Skip to content

Commit 5cdcb0d

Browse files
authored
Use swup for page navigation (elixir-lang#1986)
1 parent 61a8d1d commit 5cdcb0d

23 files changed

+247
-102
lines changed

assets/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
sourceType: 'module'
1212
},
1313
rules: {
14+
'no-new': 0,
1415
'no-path-concat': 0,
1516
'no-throw-literal': 0,
1617
'no-useless-escape': 0,

assets/js/entry/html.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import { initialize as initSettings } from '../settings'
2121
import { initialize as initStyling } from '../styling'
2222
import { initialize as initPreview} from '../preview'
2323

24+
import Swup from 'swup'
25+
import SwupA11yPlugin from '@swup/a11y-plugin'
26+
2427
onDocumentReady(() => {
2528
const params = new URLSearchParams(window.location.search)
2629
const isPreview = params.has('preview')
@@ -37,6 +40,26 @@ onDocumentReady(() => {
3740
if (isPreview) {
3841
initPreview()
3942
} else {
43+
if (window.location.protocol !== 'file:') {
44+
new Swup({
45+
animationSelector: false,
46+
containers: ['#main'],
47+
ignoreVisit: (url) => {
48+
const path = url.split('#')[0]
49+
return path === window.location.pathname ||
50+
path === window.location.pathname + '.html'
51+
},
52+
hooks: {
53+
'page:view': () => {
54+
initSidebarContent()
55+
initSearchPage()
56+
}
57+
},
58+
linkSelector: 'a[href]:not([href^="/"]):not([href^="http"])',
59+
plugins: [new SwupA11yPlugin()]
60+
})
61+
}
62+
4063
initVersions()
4164
initSidebarDrawer()
4265
initSidebarContent()

assets/js/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function escapeHtmlEntities (text) {
4343
* @returns {String}
4444
*/
4545
export function getCurrentPageSidebarType () {
46-
return document.body.dataset.type
46+
return document.getElementById('main').dataset.type
4747
}
4848

4949
/**

assets/js/search-page.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import { qs, escapeHtmlEntities, isBlank, getQueryParamByName, getProjectNameAnd
55
import { setSearchInputValue } from './search-bar'
66

77
const EXCERPT_RADIUS = 80
8-
98
const SEARCH_CONTAINER_SELECTOR = '#search'
109

10+
lunr.tokenizer.separator = /\s+/
11+
lunr.QueryLexer.termSeparator = /\s+/
12+
lunr.Pipeline.registerFunction(docTokenFunction, 'docTokenSplitter')
13+
lunr.Pipeline.registerFunction(docTrimmerFunction, 'docTrimmer')
14+
1115
/**
1216
* Performs a full-text search within the documentation
1317
* for the query in URL params and renders the result.
@@ -49,12 +53,6 @@ function renderResults ({ value, results, errorMessage }) {
4953
}
5054

5155
async function getIndex () {
52-
// lunr by default splits on - but we don't want that.
53-
lunr.tokenizer.separator = /\s+/
54-
lunr.QueryLexer.termSeparator = /\s+/
55-
lunr.Pipeline.registerFunction(docTokenFunction, 'docTokenSplitter')
56-
lunr.Pipeline.registerFunction(docTrimmerFunction, 'docTrimmer')
57-
5856
const cachedIndex = await loadIndex()
5957
if (cachedIndex) { return cachedIndex }
6058

assets/package-lock.json

Lines changed: 134 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"type": "git",
2020
"url": "git+https://github.com/elixir-lang/ex_doc.git"
2121
},
22-
"author": "Plataformatec",
22+
"author": "The Elixir Team",
2323
"license": "Apache-2.0",
2424
"bugs": {
2525
"url": "https://github.com/elixir-lang/ex_doc/issues"
@@ -29,6 +29,7 @@
2929
"devDependencies": {
3030
"@fontsource/inconsolata": "^4.5.9",
3131
"@fontsource/lato": "^4.5.10",
32+
"@swup/a11y-plugin": "^5.0.0",
3233
"esbuild": "^0.16.16",
3334
"eslint": "^8.31.0",
3435
"eslint-config-standard": "^17.0.0",
@@ -46,6 +47,7 @@
4647
"lodash.throttle": "^4.1.1",
4748
"lunr": "^2.3.8",
4849
"mocha": "^10.2.0",
49-
"normalize.css": "^8.0.1"
50+
"normalize.css": "^8.0.1",
51+
"swup": "^4.8.1"
5052
}
5153
}

formatters/html/dist/html-FUIEFJA2.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

formatters/html/dist/html-ZOXW4WH5.js

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ex_doc/formatter/epub/templates.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ defmodule ExDoc.Formatter.EPUB.Templates do
9494
:defp,
9595
:head_template,
9696
Path.expand("templates/head_template.eex", __DIR__),
97-
[:config, :page],
97+
[:config, :title],
9898
trim: true
9999
)
100100

lib/ex_doc/formatter/epub/templates/extra_template.eex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= head_template(config, %{title: title}) %>
1+
<%= head_template(config, title) %>
22
<h1 id="content">
33
<%=h title_content %>
44
</h1>

0 commit comments

Comments
 (0)