Skip to content

Commit dcac3a4

Browse files
committed
simplify logic for 404 page; prepend site.path to absolute URLs
1 parent c36d7a6 commit dcac3a4

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/partials/article-404.hbs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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 id="return-link" 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 on the left.</p>
55
</div>
66
<div class="paragraph">
7-
<p>If you arrived on this page by clicking on a link on another site, please notify the owner of that site that the link is broken.
7+
<p>If you arrived on this page by clicking a link on another site, please notify the owner of that 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>
@@ -13,19 +13,23 @@ If you typed the URL of this page manually, please double check that you entered
1313
if (!returnLink) return
1414
var startPages = [
1515
{{#each site.components}}
16-
{{#if (or ./versions.[1] (ne ./versions.[0].version 'master'))}}
16+
{ name: "{{{./name}}}", title: "{{{./title}}}", url: "{{{@root.site.path}}}{{{./url}}}", prefix: "{{{@root.site.path}}}/{{{./name}}}" },
1717
{{#each ./versions}}
18-
{ name: "{{{./name}}}", title: "{{{./title}}}", version: "{{{./version}}}", url: "{{{./url}}}" },
18+
{{#unless (eq ./version 'master')}}
19+
{ name: "{{{./name}}}", title: "{{{./title}}}", version: "{{{./version}}}", url: "{{{@root.site.path}}}{{{./url}}}", prefix: "{{{@root.site.path}}}/{{{./name}}}/{{{./version}}}" },
20+
{{/unless}}
1921
{{/each}}
20-
{{/if}}
21-
{ name: "{{{./name}}}", title: "{{{./title}}}", url: "{{{./url}}}" },
2222
{{/each}}
2323
].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
24+
var prefix = it.prefix
25+
delete it.prefix
26+
if (('version' in it) && !it.url.startsWith(prefix + '/')) {
27+
var prefixSegments = prefix.split('/')
28+
var versionSegmentIdx = prefixSegments.findIndex((segment) => segment === it.version)
29+
prefixSegments.splice(versionSegmentIdx, 1, it.url.split('/')[versionSegmentIdx])
30+
prefix = prefixSegments.join('/')
2831
}
32+
accum[prefix] = it
2933
return accum
3034
}, {})
3135
var returnTo

0 commit comments

Comments
 (0)