on master help sign in
Lowercase categories and prettier URLs

Fixes #291 and #292

commit6df12f9b4fc2e5d999a84bf02bdc549e3b9f7e9d authorジョシュ <joshavanier@users.noreply.github.com> dateFri 16 Aug 2019, 17:01 (7 years ago) parent89bad78
1 file changed+8−3
scripts/wiki.js+8−3
scripts/wiki.js+8−3
@@ -9,6 +9,8 @@ const Wiki = sites => {
99 const authors = new Set()
1010 const terms = new Set()
1111
12+ const encodeUrl = text => text.replace(/ /g, '+').trim().toLowerCase()
13+
1214 const cleanEntry = entry => {
1315 const temp = document.createElement('div')
1416 temp.textContent = entry
@@ -63,7 +65,7 @@ const Wiki = sites => {
6365 const formatSideBarCat = (key, entries) => (currentHtml, cat) => {
6466 const catLength = Object.keys(entries[cat]).length
6567 const newHtml = `<li class='${selected(key, cat)}'}'>
66− <a href='#${cat}' data-msgs='${catLength}'>${cat.toLowerCase()}</a>
68+ <a href='#${encodeUrl(cat)}' data-msgs='${catLength}'>${cat.toLowerCase()}</a>
6769 </li>`
6870 return `${currentHtml}${newHtml}`
6971 }
@@ -118,6 +120,7 @@ const Wiki = sites => {
118120 }
119121
120122 const refresh = key => {
123+ console.log(key)
121124 if (key) {
122125 if (entries[key] === undefined) return
123126 const items = Object.keys(entries[key]).sort().reduce(formatEntries(entries[key]), '')
@@ -162,11 +165,13 @@ const Wiki = sites => {
162165 }
163166}
164167
168+const decodeUrl = text => text.replace(/\+/g, ' ').trim().toUpperCase()
169+
165170const stripHash = hash => {
166171 const decoded = decodeURIComponent(hash)
167− return decoded.charAt(0) === '#' ? decoded.substring(1) : decoded
172+ return decoded.charAt(0) === '#' ? decodeUrl(decoded.substring(1)) : decoded
168173}
169174
170175window.addEventListener('hashchange', () => {
171− wiki.refresh(stripHash(window.location.hash).toUpperCase())
176+ wiki.refresh(stripHash(window.location.hash))
172177})