mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-21 03:44:05 -06:00
Fix type errors and prettier
This commit is contained in:
parent
43cfbaae22
commit
689b54a945
@ -169,7 +169,7 @@ document.addEventListener("render", (e) => {
|
||||
// runs when content is rendered or re-rendered
|
||||
// e.detail.htmlElement contains the DOM element that was updated
|
||||
const container = e.detail.htmlElement
|
||||
|
||||
|
||||
// attach event listeners to elements within this container
|
||||
const toggleSwitch = container.querySelector("#switch") as HTMLInputElement
|
||||
if (toggleSwitch) {
|
||||
|
||||
@ -15,16 +15,17 @@ document.addEventListener("nav", (e: CustomEventMap["nav"]) => {
|
||||
// Access the current page URL
|
||||
const currentUrl = e.detail.url
|
||||
console.log(`User navigated to: ${currentUrl}`)
|
||||
|
||||
|
||||
// Good for:
|
||||
// - Analytics tracking
|
||||
// - URL-dependent state updates
|
||||
// - URL-dependent state updates
|
||||
// - Setting up page-level event handlers
|
||||
// - Theme/mode initialization
|
||||
})
|
||||
```
|
||||
|
||||
**When it fires:**
|
||||
|
||||
- On initial page load
|
||||
- On client-side navigation (if SPA routing is enabled)
|
||||
- Does NOT fire on content re-renders
|
||||
@ -37,11 +38,11 @@ The `render` event is fired when content needs to be processed or updated. This
|
||||
document.addEventListener("render", (e: CustomEventMap["render"]) => {
|
||||
// Access the container that was updated
|
||||
const container = e.detail.htmlElement
|
||||
|
||||
|
||||
// Process elements within this container
|
||||
const codeBlocks = container.querySelectorAll("pre code")
|
||||
codeBlocks.forEach(addSyntaxHighlighting)
|
||||
|
||||
|
||||
// Good for:
|
||||
// - Setting up event listeners on new content
|
||||
// - Processing dynamic content (syntax highlighting, math rendering, etc.)
|
||||
@ -50,6 +51,7 @@ document.addEventListener("render", (e: CustomEventMap["render"]) => {
|
||||
```
|
||||
|
||||
**When it fires:**
|
||||
|
||||
- On initial page load (with `document.body` as the container)
|
||||
- When popover content is loaded
|
||||
- When search results are displayed
|
||||
@ -106,10 +108,12 @@ Always clean up event handlers to prevent memory leaks:
|
||||
```ts
|
||||
addRenderListener((container) => {
|
||||
const buttons = container.querySelectorAll(".my-button")
|
||||
|
||||
const handleClick = (e) => { /* ... */ }
|
||||
|
||||
buttons.forEach(button => {
|
||||
|
||||
const handleClick = (e) => {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
buttons.forEach((button) => {
|
||||
button.addEventListener("click", handleClick)
|
||||
// Clean up when navigating away
|
||||
window.addCleanup(() => {
|
||||
@ -168,4 +172,4 @@ addRenderListener((container) => {
|
||||
})
|
||||
```
|
||||
|
||||
This provides cleaner separation of concerns and better performance.
|
||||
This provides cleaner separation of concerns and better performance.
|
||||
|
||||
@ -291,12 +291,6 @@ document.addEventListener("prenav", async () => {
|
||||
|
||||
document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
const currentSlug = e.detail.url
|
||||
const rerender = e.detail.rerender
|
||||
|
||||
// If this is secondary nav call, do not populate explorer again
|
||||
if (rerender) {
|
||||
return
|
||||
}
|
||||
|
||||
await setupExplorer(currentSlug)
|
||||
|
||||
|
||||
@ -577,9 +577,6 @@ function cleanupGlobalGraphs() {
|
||||
document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
const slug = e.detail.url
|
||||
|
||||
// if we are rerendering, we can ignore this event
|
||||
if (e.detail.rerender) return
|
||||
|
||||
addToVisited(simplifySlug(slug))
|
||||
|
||||
async function renderLocalGraph() {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { computePosition, flip, inline, shift } from "@floating-ui/dom"
|
||||
import { FullSlug, normalizeRelativeURLs } from "../../util/path"
|
||||
import { normalizeRelativeURLs } from "../../util/path"
|
||||
import { fetchCanonical, dispatchRenderEvent, addRenderListener } from "./util"
|
||||
|
||||
const p = new DOMParser()
|
||||
|
||||
@ -38,7 +38,7 @@ const getOpts = ({ target }: Event): { url: URL; scroll?: boolean } | undefined
|
||||
function notifyNav(url: FullSlug) {
|
||||
const event: CustomEventMap["nav"] = new CustomEvent("nav", { detail: { url } })
|
||||
document.dispatchEvent(event)
|
||||
|
||||
|
||||
// Also trigger render event for the whole document body
|
||||
dispatchRenderEvent(document.body)
|
||||
}
|
||||
|
||||
@ -137,7 +137,8 @@
|
||||
}
|
||||
|
||||
// Hide the decrypt form when encrypted content appears in popover and search
|
||||
.search-space, .popover {
|
||||
.search-space,
|
||||
.popover {
|
||||
.encrypted-content .encryption-notice .decrypt-form {
|
||||
display: none;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user