From b01eb1a453adaebcdac3886113120f81833c7d3b Mon Sep 17 00:00:00 2001 From: lifehackerhansol Date: Wed, 20 Nov 2024 14:05:11 -0800 Subject: [PATCH] index: add hack to restore docsify behaviour This attempts to restore the old behaviour of docsify.js, where it uses hash parameters to navigate the site. Since this isn't the case in VitePress, all the old links to the guide broke, so check it on load. This works on a best-effort basis; if the corresponding page exists (such as `#/aroma/getting-started` -> `/aroma/getting-started`), it should navigate properly, but if the corresponding page doesn't exist, it will 404. --- docs/index.md | 4 ++++ docs/public/assets/js/docsify-wrapper.js | 27 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 docs/public/assets/js/docsify-wrapper.js diff --git a/docs/index.md b/docs/index.md index a26389481b1..91aa262198c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -6,6 +6,10 @@ hero: tagline: "A guide collaboration between Nintendo Homebrew's Helpers and Staff, from stock to Aroma custom firmware." image: src: "/assets/img/home-page-feature.jpg" + +head: [ + ['script', {src: '/assets/js/docsify-wrapper.js'}] +] --- ::: tip diff --git a/docs/public/assets/js/docsify-wrapper.js b/docs/public/assets/js/docsify-wrapper.js new file mode 100644 index 00000000000..8d2f4e24891 --- /dev/null +++ b/docs/public/assets/js/docsify-wrapper.js @@ -0,0 +1,27 @@ +/* + Copyright (C) 2024 Nintendo Homebrew + + SPDX-License-Identifier: MIT +*/ + +const map = new WeakMap() + +function checkDocsify(callback) { + if (map.has(callback)) + return; + map.set(callback, true); + if (document.readyState === 'complete') + callback(); + else + window.addEventListener('load', callback, false); +} + +checkDocsify(() => { + if(!window.location.hash) + return; + + if(window.location.hash[1] == '/') { + path = window.location.hash.substring(1); + window.location.href = path; + } +})