1
0
mirror of https://github.com/one-among-us/data.git synced 2024-11-23 03:27:38 +08:00

[O] Optimize footnote

This commit is contained in:
Azalea 2024-02-28 18:56:09 -05:00
parent 496363eaa0
commit 94dccc0bd1

View File

@ -137,47 +137,18 @@ function buildPeoplePages() {
} }
function handleFootnote(md: string) { function handleFootnote(md: string) {
const data = md.split('') if (!md.includes('[^')) return md
let result = ''
let footnote = false
let ol = false
for (let i = 0; i < data.length; i += 1) { // Replace footnote references with HTML superscript tags
if ((data[i] == '[') && (i != data.length - 1)) { md = md.replace(/\[\^(\d+)\](?::\s*(.*))?/g, (match, id, text) => text ?
if (data[i + 1] == '^') { // Footnote definition
footnote = true; `<li id="footnote-${id}">${text}<a href="#footnote-ref-${id}">↩</a></li>` :
i += 1 // Footnote reference
let id = '' `<sup><a href="#footnote-${id}" id="footnote-ref-${id}">${id}</a></sup>`
while (data[++i] != ']') id += data[i] )
if (data[i + 1] == ':') {
if (!ol) {
ol = !ol;
result += '<ol>\n'
}
//<li id="fn1">message <a href="#fnref1">↩</a></li>
result += `<li id=\"fn${id}\">`
let message = ''
while (data[i] != '\n') {
if (i < data.length - 1) ++i
else break
message += data[i]
}
result += message
result += `<a href=\"#fnref${id}\">↩</a></li>`
}
else {
//<sup><a href="#fn1" id="fnref1">1</a></sup>
result += `<sup><a href=\"#fn${id}\" id=\"fnref${id}\">${id}</a></sup>`
}
}
else result += data[i]
}
else result += data[i]
}
if (footnote) result += '\n</ol>\n' // Wrap the footnote definitions in an ordered list
return md.replace(/(<li id="footnote.*<\/li>)/gs, '<ol>\n$1\n</ol>')
return result
} }
// Copy `people/${dirname}/photos` to `dist/people/${dirname}/`. // Copy `people/${dirname}/photos` to `dist/people/${dirname}/`.