mirror of
https://github.com/aljazceru/pear-docs.git
synced 2025-12-17 14:34:19 +01:00
docs home
This commit is contained in:
@@ -34,7 +34,6 @@ customElements.define('docs-viewer', class extends HTMLElement {
|
||||
blockquote::before { content: "ℹ"; float: left; font-size: 1.625rem; margin-left: 1rem; margin-right: 0.625rem; }
|
||||
img { display: block; max-width: 63em; margin: 0 auto; margin-block-start: 1.625rem; margin-block-end: 1.625rem; box-shadow: rgb(123 115 168 / 15%) 0px 13px 24px 0px; }
|
||||
</style>
|
||||
<header></header>
|
||||
<div id="panel" class="${lightMode ? 'light' : ''}"><slot></slot></div>
|
||||
</div>
|
||||
`
|
||||
@@ -43,7 +42,6 @@ customElements.define('docs-viewer', class extends HTMLElement {
|
||||
this.root.appendChild(this.template.content.cloneNode(true))
|
||||
|
||||
this.panel = this.root.querySelector('#panel')
|
||||
this.header = this.root.querySelector('header')
|
||||
|
||||
this.page = 'readme.md'
|
||||
|
||||
@@ -60,21 +58,27 @@ customElements.define('docs-viewer', class extends HTMLElement {
|
||||
const url = new URL(href, location.href)
|
||||
if (url.origin !== origin) return window.open(href)
|
||||
evt.preventDefault()
|
||||
document.documentElement.scrollTo(0, 0)
|
||||
this.page = evt.target.pathname
|
||||
history.pushState(null, null, evt.target.pathname + location.hash)
|
||||
this.#load().catch((err) => this.#error(err))
|
||||
this.load(evt.target.pathname)
|
||||
})
|
||||
|
||||
|
||||
window.addEventListener('popstate', (evt) => {
|
||||
if (location.hash === '#documentation') {
|
||||
if (location.hash.startsWith('#documentation')) {
|
||||
const home = location.hash.endsWith('-home')
|
||||
if (home) {
|
||||
this.page = '/readme.md'
|
||||
history.replaceState(null, null, this.page + location.hash)
|
||||
location.href = '/pulse.html#documentation'
|
||||
return
|
||||
}
|
||||
|
||||
if (location.pathname.endsWith('.md') === false) {
|
||||
history.replaceState(null, null, this.page + location.hash)
|
||||
} else {
|
||||
evt.preventDefault()
|
||||
this.page = location.pathname
|
||||
this.#load().catch((err) => this.#error(err))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
evt.preventDefault()
|
||||
this.page = location.pathname
|
||||
this.#load().catch((err) => this.#error(err))
|
||||
|
||||
}
|
||||
})
|
||||
@@ -86,6 +90,13 @@ customElements.define('docs-viewer', class extends HTMLElement {
|
||||
try { this.panel.querySelector('slot').innerHTML = err.stack } catch (e) { console.error(err, e) }
|
||||
}
|
||||
|
||||
load (page) {
|
||||
document.documentElement.scrollTo(0, 0)
|
||||
this.page = page
|
||||
history.pushState(null, null, page + location.hash)
|
||||
return this.#load().catch((err) => this.#error(err))
|
||||
}
|
||||
|
||||
async #load () {
|
||||
this.panel.querySelector('slot').innerHTML = marked.parse(await (await fetch(this.page)).text(), {headerIds: false, mangle: false})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user