Re-write to cleanup all styles and such (#158)

* Rewrite and re-style the wiki

* Fix links

* Fix mobile width being wrong

* Make the anticheat warning pretty

* Fix root pages

* Fix code blocks and cleanup some other bits

* Fix search

* Fix android and iOS sidebar links
This commit is contained in:
rtm516 authored and GitHub committed 2023-06-04 19:29:37 +01:00
1 parent 17e1be5177
commit 09025ac3cb
93 files changed
+595 -3676

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
(function () {
const toc = document.querySelector('#page-nav')
// Select each header
const sections = document.querySelectorAll('main h1')
sections.forEach((section, id) => {
// Create the header link
toc.innerHTML += '<div id="link_' + section.id + '" class="md-nav__item"><a class="md-nav__link" href="#' + section.id + '" title="' + section.textContent + '">' + section.textContent + '</a></div>'
// Create the sub links container
const children = document.createElement('nav')
children.className = 'md-nav'
children.innerHTML = '<ul class="md-nav__list"></ul>'
// Select all the sub headers and add them to the sub links container
let contenders = section.nextElementSibling
while (contenders && contenders.tagName !== 'H1') {
if (contenders.tagName === 'H2' || contenders.tagName === 'H3') {
const content = '<li class="md-nav__item"><a class="md-nav__link" href="#' + contenders.id + '" title="' + contenders.textContent + '">' + contenders.textContent + '</a></li>'
children.firstElementChild.innerHTML += content
}
contenders = contenders.nextElementSibling
}
document.querySelector('#link_' + section.id).appendChild(children)
})
})()
+102
View File
@@ -0,0 +1,102 @@
(function () {
function getQueryVariable (variable) {
const query = window.location.search.substring(1)
const vars = query.split('&')
for (let i = 0; i < vars.length; i++) {
const pair = vars[i].split('=')
if (pair[0] === variable) {
return decodeURIComponent(pair[1].replace(/\+/g, '%20')).trim()
}
}
}
function getPreview (query, content, previewLength) {
previewLength = previewLength || (content.length * 2)
const parts = query.split(' ')
let match = content.toLowerCase().indexOf(query.toLowerCase())
let matchLength = query.length
let preview
// Find a relevant location in content
for (let i = 0; i < parts.length; i++) {
if (match >= 0) {
break
}
match = content.toLowerCase().indexOf(parts[i].toLowerCase())
matchLength = parts[i].length
}
// Create preview
if (match >= 0) {
const start = match - (previewLength / 2)
const end = start > 0 ? match + matchLength + (previewLength / 2) : previewLength
preview = content.substring(start, end).trim()
if (start > 0) {
preview = '...' + preview
}
if (end < content.length) {
preview = preview + '...'
}
// Highlight query parts
preview = preview.replace(new RegExp('(' + parts.join('|') + ')', 'gi'), '<strong>$1</strong>')
} else {
// Use start of content if no match found
preview = content.substring(0, previewLength).trim() + (content.length > previewLength ? '...' : '')
}
return preview
}
function displaySearchResults (results, query) {
const searchResultsEl = document.getElementById('search-results')
const searchProcessEl = document.getElementById('search-process')
if (results.length) {
let resultsHTML = ''
results.forEach(function (result) {
const item = window.data[result.ref]
if (item.title) {
const contentPreview = getPreview(query, item.content, 170)
const titlePreview = getPreview(query, item.title)
resultsHTML += "<li><h4><a href='" + item.url.trim() + "'>" + titlePreview + '</a></h4><p><small>' + contentPreview + '</small></p></li>'
}
})
searchResultsEl.innerHTML = resultsHTML
searchProcessEl.innerText = 'Showing'
} else {
searchResultsEl.style.display = 'none'
searchProcessEl.innerText = 'No'
}
}
window.index = lunr(function () {
this.field('id')
this.field('title', { boost: 10 })
this.field('url')
this.field('content')
})
const query = decodeURIComponent((getQueryVariable('q') || '').replace(/\+/g, '%20'))
const searchQueryContainerEl = document.getElementById('search-query-container')
const searchQueryEl = document.getElementById('search-query')
searchQueryEl.innerText = query
if (query !== '') {
searchQueryContainerEl.style.display = 'inline'
}
for (const key in window.data) {
window.index.add(window.data[key])
}
displaySearchResults(window.index.search(query), query) // Hand the results off to be displayed
})()