Added hash to the URL bar on Glossary page when sidebar links are clicked

This commit is contained in:
ポール ウェッブ 2018-08-21 17:37:39 -05:00
parent 6197f32e3c
commit a92480742a
3 changed files with 26 additions and 21 deletions

View file

@ -1,9 +1,11 @@
{
"name": "lbry.tech",
"description": "Documentation for the LBRY protocol and associated projects",
"author": "LBRY Team",
"version": "0.0.0",
"private": true,
"babel": {
"presets": [
"env",
"stage-2"
]
},
"dependencies": {
"@octokit/rest": "^15.10.0",
"app-root-path": "^2.1.0",
@ -38,12 +40,14 @@
"nanohtml": "^1.2.4",
"prismjs": "^1.15.0",
"redis": "^2.8.0",
"request": "^2.88.0",
"request-promise-native": "^1.0.5",
"slack-node": "^0.1.8",
"socket.io": "^2.1.1",
"stringify-object": "^3.2.2",
"turbocolor": "^2.6.1"
},
"description": "Documentation for the LBRY protocol and associated projects",
"devDependencies": {
"babel-preset-env": "^1.7.0",
"babel-preset-stage-2": "^6.24.1",
@ -55,23 +59,11 @@
"standardx": "^2.1.0",
"updates": "^4.1.2"
},
"peerDependencies": {
"request": "^2.88.0"
},
"babel": {
"presets": [
"env",
"stage-2"
]
},
"engines": {
"node": "10.2.x"
},
"standardx": {
"ignore": [
"public"
]
},
"name": "lbry.tech",
"private": true,
"scripts": {
"lint": "standardx --verbose | snazzy",
"start": "NODE_ENV=production node server",
@ -81,5 +73,11 @@
"watch": "run-p watch:*",
"watch:sass": "sass --watch sass:public/css --style compressed",
"watch:server": "NODE_ENV=development nodemon index.js --ignore 'public/'"
}
},
"standardx": {
"ignore": [
"public"
]
},
"version": "0.0.0"
}

View file

@ -7,3 +7,8 @@ document.getElementsByTagName("body")[0].classList.add("glossary");
$("[data-action='toggle glossary sidebar']").on("click", () => { // Toggle sidebar
$("body").toggleClass("sidebar-closed");
});
$(".component--glossary-toc li a").on("click", event => { // Add hash to URL bar
const hash = event.currentTarget.href.split("#")[1];
history.replaceState({}, "", `#${hash}`);
});

View file

@ -12,10 +12,12 @@ const numberRegex = /^[0-9]/g;
// E X P O R T
module.exports = exports = (state, emit, markdown) => {
const tocElements = markdown.match(headerRegex);
const collectionOfTocElements = [];
const tocElements = markdown.match(headerRegex);
for (const item of tocElements) collectionOfTocElements.push(`<li><a href="${slugify(item)}" title="">${item.replace(/### /g, "")}</a></li>`);
for (const item of tocElements) collectionOfTocElements.push(`
<li><a href="${slugify(item)}" title="Go to '${item.replace(/### /g, "")}'">${item.replace(/### /g, "")}</a></li>
`);
return `
<ul class="component--glossary-toc">