on master help sign in
Lowercase categories and prettier URLs
6df12f9ジョシュ
scripts/wiki.js+8−3
@@ -9,6 +9,8 @@ const Wiki = sites => {
9 const authors = new Set()
9 const authors = new Set()
10 const terms = new Set()
10 const terms = new Set()
11
11
12+ const encodeUrl = text => text.replace(/ /g, '+').trim().toLowerCase()
13+
12 const cleanEntry = entry => {
14 const cleanEntry = entry => {
13 const temp = document.createElement('div')
15 const temp = document.createElement('div')
14 temp.textContent = entry
16 temp.textContent = entry
@@ -63,7 +65,7 @@ const Wiki = sites => {
63 const formatSideBarCat = (key, entries) => (currentHtml, cat) => {
65 const formatSideBarCat = (key, entries) => (currentHtml, cat) => {
64 const catLength = Object.keys(entries[cat]).length
66 const catLength = Object.keys(entries[cat]).length
65 const newHtml = `<li class='${selected(key, cat)}'}'>
67 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>
67 </li>`
69 </li>`
68 return `${currentHtml}${newHtml}`
70 return `${currentHtml}${newHtml}`
69 }
71 }
@@ -118,6 +120,7 @@ const Wiki = sites => {
118 }
120 }
119
121
120 const refresh = key => {
122 const refresh = key => {
123+ console.log(key)
121 if (key) {
124 if (key) {
122 if (entries[key] === undefined) return
125 if (entries[key] === undefined) return
123 const items = Object.keys(entries[key]).sort().reduce(formatEntries(entries[key]), '')
126 const items = Object.keys(entries[key]).sort().reduce(formatEntries(entries[key]), '')
@@ -162,11 +165,13 @@ const Wiki = sites => {
162 }
165 }
163}
166}
164
167
168+const decodeUrl = text => text.replace(/\+/g, ' ').trim().toUpperCase()
169+
165const stripHash = hash => {
170const stripHash = hash => {
166 const decoded = decodeURIComponent(hash)
171 const decoded = decodeURIComponent(hash)
167− return decoded.charAt(0) === '#' ? decoded.substring(1) : decoded
172+ return decoded.charAt(0) === '#' ? decodeUrl(decoded.substring(1)) : decoded
168}
173}
169
174
170window.addEventListener('hashchange', () => {
175window.addEventListener('hashchange', () => {
171− wiki.refresh(stripHash(window.location.hash).toUpperCase())
176+ wiki.refresh(stripHash(window.location.hash))
172})
177})