summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/generate_html.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/generate_html.rs b/src/generate_html.rs
index b19d8b7..cb2f1f3 100644
--- a/src/generate_html.rs
+++ b/src/generate_html.rs
@@ -27,6 +27,21 @@ const DEFAULT_TEMPLATE: &str = "\
</body>
</html>";
+const SLUG_FUNCTION: &str = "\
+function to_slug(string) {
+ let slug = '';
+ let prev = ' ';
+ for (let c of string.toLowerCase()) {
+ if (c==' ') c = '-';
+ if (/[a-z0-9]/.test(c)) slug += c;
+ if ('_~.+/#'.includes(c)) slug += c;
+ if (c=='-' && prev != '-') slug += '-';
+ prev = c;
+ }
+ return slug;
+}
+";
+
pub fn generate_html(page: &Page, website: &Website) -> String {
let root = page.root();
@@ -93,8 +108,14 @@ pub fn generate_html_redirect(path: &str, website: &Website) -> String {
<!DOCTYPE html>
<html>
<head>
+ <script>
+ {SLUG_FUNCTION}
+ window.location.replace('{path}' + to_slug(window.location.hash));
+ </script>
<title>Redirecting...</title>
- <meta http-equiv='refresh' content='0; url={path}'>
+ <noscript>
+ <meta http-equiv='refresh' content='0; url={path}'>
+ </noscript>
{head}
</head>
</html>")