Add guides (#224)

* Add guides

* Add versioning to guides

* Guides: special variables and nested expressions

* Add guides page to vite build

* Add search and hash hooks, guide tags and headings

* Improve guides list and filtering

* Add 1.19 download link
This commit is contained in:
Misode
2022-05-06 06:37:27 +02:00
committed by GitHub
parent c788277450
commit 6f27465c78
29 changed files with 1769 additions and 386 deletions

27
src/app/hooks/useHash.ts Normal file
View File

@@ -0,0 +1,27 @@
import { useCallback, useEffect, useState } from 'preact/hooks'
import { changeUrl } from '../Utils'
export function useHash(): [string, (hash: string) => unknown] {
const [hash, setHash] = useState(window.location.hash)
const onChange = useCallback(() => {
setHash(window.location.hash)
}, [])
useEffect(() => {
window.addEventListener('hashchange', onChange)
window.addEventListener('replacestate', onChange)
return () => {
window.removeEventListener('hashchange', onChange)
window.removeEventListener('replacestate', onChange)
}
}, [])
const changeHash = useCallback((newHash: string) => {
if (newHash !== hash) {
changeUrl({ hash: newHash })
}
}, [hash])
return [hash, changeHash]
}