-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new 'redirect' layout that can be used to as a target of an Apache HTTPD rewrite rule in order to perform redirects based on a page or anchor. Redirect pages can be written in asciidoc in the following form: :page-layout: redirect * xref:<new-location>[<previous-page><#previous-anchor>] ... Closes gh-221
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
:page-layout: redirect | ||
|
||
* xref:index.adoc[oldpage] | ||
* xref:baz/index.adoc[#old] | ||
* xref:samples/index.adoc[oldpage#old] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
;(function () { | ||
'use strict' | ||
|
||
window.addEventListener('load', onChange) | ||
window.addEventListener('hashchange', onChange) | ||
|
||
function onChange () { | ||
const params = new URLSearchParams(window.location.search) | ||
const page = params.get('page') || '' | ||
const fragment = window.location.hash | ||
const pageAndFragment = page + ((fragment.length === 1) ? '' : fragment) | ||
let foundForFragment | ||
let foundForPageAndFragment | ||
const candidates = document.querySelector('body ul') | ||
if (candidates) { | ||
for (const candidate of candidates.children) { | ||
const anchorElement = candidate.querySelector('a') | ||
if (anchorElement.text === pageAndFragment) foundForPageAndFragment = anchorElement.href | ||
if (anchorElement.text === fragment) foundForFragment = anchorElement.href | ||
} | ||
} | ||
window.location.replace(foundForPageAndFragment || foundForFragment || 'index.html') | ||
} | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<head> | ||
<style> | ||
body { display: none; } | ||
</style> | ||
</head> | ||
{{{page.contents}}} | ||
<script id="redirect" async src="{{{uiRootPath}}}/js/vendor/redirect.js"></script> |