diff options
| author | Ayaz Hafiz <ayaz.hafiz.1@gmail.com> | 2020-07-15 17:50:43 -0700 |
|---|---|---|
| committer | Caleb Cartwright <calebcartwright@users.noreply.github.com> | 2021-08-17 21:55:26 -0500 |
| commit | bf47fc17a3bbcf93f665ec2b19fbe794ead555af (patch) | |
| tree | 5e7ae193c4bcfb1c39486c4611d49b7deb6da611 | |
| parent | 3195d6c2b7fd2f958d823eb32bce0fb350bf6ec5 (diff) | |
| download | rust-bf47fc17a3bbcf93f665ec2b19fbe794ead555af.tar.gz rust-bf47fc17a3bbcf93f665ec2b19fbe794ead555af.zip | |
Ensure that doc url hash IDs are scrolled to on page load
I broke this a few weeks ago so I'll fix it Demo: https://5f0fa445faca4aff5f580029--naughty-borg-09b903.netlify.app/?version=master&search=#brace_style
| -rw-r--r-- | docs/index.html | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/docs/index.html b/docs/index.html index 40fafd44428..1f299b91820 100644 --- a/docs/index.html +++ b/docs/index.html @@ -108,7 +108,8 @@ shouldStable: false, version: versionNumber, oldVersion: undefined, - versionOptions: ['master'] + versionOptions: ['master'], + scrolledOnce: false, }, asyncComputed: { async outputHtml() { @@ -156,11 +157,11 @@ renderer.heading = function(text, level) { const id = htmlToId(text); return `<h${level}> - <a href="#${id}" name="${id}" class="header-link">${text}</a> + <a id="${id}" href="#${id}" name="${id}" class="header-link">${text}</a> </h${level}>`; }; - return marked.parser(ast, { + const html = marked.parser(ast, { highlight(code, lang) { return hljs.highlight(lang ? lang : 'rust', code).value; }, @@ -168,6 +169,8 @@ headerPrefix: '', renderer, }); + document.dispatchEvent(new Event('htmlbuilt')); + return html; } }, created: async function() { @@ -178,12 +181,15 @@ .filter(tag => tag.startsWith('v')); this.versionOptions = this.versionOptions.concat(tagOptions); }, - mounted() { + updated: function() { if (UrlHash === '') return; - const target = document.querySelector(`#${UrlHash}`); - if (target != null) { - target.scrollIntoView(true); - } + this.$nextTick(() => { + const target = document.querySelector(`#${UrlHash}`); + if (target != null && !this.scrolledOnce) { + target.scrollIntoView(true); + this.scrolledOnce = true; + } + }); } }); const extractDepthOnes = (ast) => { |
