Skip to content

Commit 1238e68

Browse files
authored
resolves #20 add router to 404 page that offers to take visitor back to component version (PR #21)
1 parent 9a1edbc commit 1238e68

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/partials/article-404.hbs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,44 @@
11
<article class="doc">
22
<h1 class="page">{{{or page.title 'Page Not Found'}}}</h1>
33
<div class="paragraph">
4-
<p>The page you&#8217;re looking for does not exist. It may have been moved. You can{{#with site.homeUrl}} return to the <a href="{{{this}}}">start page</a>, or{{/with}} follow one of the links in the navigation to the left.</p>
4+
<p>The page you&#8217;re looking for does not exist. It may have been moved. You can{{#with site.homeUrl}} return to the <a id="return-link" href="{{{this}}}">start page</a>, or{{/with}} follow one of the links in the navigation to the left.</p>
55
</div>
66
<div class="paragraph">
77
<p>If you arrived on this page by clicking on a link, please notify the owner of the site that the link is broken.
88
If you typed the URL of this page manually, please double check that you entered the address correctly.</p>
99
</div>
1010
</article>
11+
<script>
12+
;(function (pathname, returnLink) {
13+
if (!returnLink) return
14+
var startPages = [
15+
{{#each site.components}}
16+
{{#if (or ./versions.[1] (ne ./versions.[0].version 'master'))}}
17+
{{#each ./versions}}
18+
{ name: "{{{./name}}}", title: "{{{./title}}}", version: "{{{./version}}}", url: "{{{./url}}}" },
19+
{{/each}}
20+
{{/if}}
21+
{ name: "{{{./name}}}", title: "{{{./title}}}", url: "{{{./url}}}" },
22+
{{/each}}
23+
].reduce(function (accum, it) {
24+
if ('version' in it) {
25+
accum[it.url.replace(/\/(?:index\.html?$)/, '')] = it
26+
} else {
27+
if (!('/' + it.name in accum)) accum['/' + it.name] = it
28+
}
29+
return accum
30+
}, {})
31+
var returnTo
32+
var segments = pathname.split('/').slice(0, -1)
33+
while (segments.length > 1) {
34+
if ((returnTo = startPages[segments.join('/')])) break
35+
segments.pop()
36+
}
37+
if (returnTo) {
38+
returnLink.href = returnTo.url
39+
returnLink.innerText =
40+
'start page for the ' + returnTo.title + ' ' +
41+
((returnTo.version || 'master' !== 'master') ? returnTo.version + ' ' : '') + 'documentation'
42+
}
43+
})(window.location.pathname, document.getElementById('return-link'))
44+
</script>

0 commit comments

Comments
 (0)