mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-07-07 12:51:00 +02:00
properly splice changes array
This commit is contained in:
parent
7681a86815
commit
5ccb9ddc70
@ -137,17 +137,17 @@ async function startWatching(
|
|||||||
.on("add", (fp) => {
|
.on("add", (fp) => {
|
||||||
if (buildData.ignored(fp)) return
|
if (buildData.ignored(fp)) return
|
||||||
changes.push({ path: fp as FilePath, type: "add" })
|
changes.push({ path: fp as FilePath, type: "add" })
|
||||||
rebuild(changes, clientRefresh, buildData)
|
void rebuild(changes, clientRefresh, buildData)
|
||||||
})
|
})
|
||||||
.on("change", (fp) => {
|
.on("change", (fp) => {
|
||||||
if (buildData.ignored(fp)) return
|
if (buildData.ignored(fp)) return
|
||||||
changes.push({ path: fp as FilePath, type: "change" })
|
changes.push({ path: fp as FilePath, type: "change" })
|
||||||
rebuild(changes, clientRefresh, buildData)
|
void rebuild(changes, clientRefresh, buildData)
|
||||||
})
|
})
|
||||||
.on("unlink", (fp) => {
|
.on("unlink", (fp) => {
|
||||||
if (buildData.ignored(fp)) return
|
if (buildData.ignored(fp)) return
|
||||||
changes.push({ path: fp as FilePath, type: "delete" })
|
changes.push({ path: fp as FilePath, type: "delete" })
|
||||||
rebuild(changes, clientRefresh, buildData)
|
void rebuild(changes, clientRefresh, buildData)
|
||||||
})
|
})
|
||||||
|
|
||||||
return async () => {
|
return async () => {
|
||||||
@ -162,6 +162,7 @@ async function rebuild(changes: ChangeEvent[], clientRefresh: () => void, buildD
|
|||||||
const buildId = randomIdNonSecure()
|
const buildId = randomIdNonSecure()
|
||||||
ctx.buildId = buildId
|
ctx.buildId = buildId
|
||||||
buildData.lastBuildMs = new Date().getTime()
|
buildData.lastBuildMs = new Date().getTime()
|
||||||
|
const numChangesInBuild = changes.length
|
||||||
const release = await mut.acquire()
|
const release = await mut.acquire()
|
||||||
|
|
||||||
// if there's another build after us, release and let them do it
|
// if there's another build after us, release and let them do it
|
||||||
@ -180,17 +181,20 @@ async function rebuild(changes: ChangeEvent[], clientRefresh: () => void, buildD
|
|||||||
}
|
}
|
||||||
|
|
||||||
const staticResources = getStaticResourcesFromPlugins(ctx)
|
const staticResources = getStaticResourcesFromPlugins(ctx)
|
||||||
|
const pathsToParse: FilePath[] = []
|
||||||
for (const [fp, type] of Object.entries(changesSinceLastBuild)) {
|
for (const [fp, type] of Object.entries(changesSinceLastBuild)) {
|
||||||
if (type === "delete" || path.extname(fp) !== ".md") continue
|
if (type === "delete" || path.extname(fp) !== ".md") continue
|
||||||
const fullPath = joinSegments(argv.directory, toPosixPath(fp)) as FilePath
|
const fullPath = joinSegments(argv.directory, toPosixPath(fp)) as FilePath
|
||||||
const parsed = await parseMarkdown(ctx, [fullPath])
|
pathsToParse.push(fullPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsed = await parseMarkdown(ctx, pathsToParse)
|
||||||
for (const content of parsed) {
|
for (const content of parsed) {
|
||||||
contentMap.set(content[1].data.relativePath!, {
|
contentMap.set(content[1].data.relativePath!, {
|
||||||
type: "markdown",
|
type: "markdown",
|
||||||
content,
|
content,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// update state using changesSinceLastBuild
|
// update state using changesSinceLastBuild
|
||||||
// we do this weird play of add => compute change events => remove
|
// we do this weird play of add => compute change events => remove
|
||||||
@ -265,7 +269,7 @@ async function rebuild(changes: ChangeEvent[], clientRefresh: () => void, buildD
|
|||||||
|
|
||||||
console.log(`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince("rebuild")}`)
|
console.log(`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince("rebuild")}`)
|
||||||
console.log(chalk.green(`Done rebuilding in ${perf.timeSince()}`))
|
console.log(chalk.green(`Done rebuilding in ${perf.timeSince()}`))
|
||||||
changes.length = 0
|
changes.splice(0, numChangesInBuild)
|
||||||
clientRefresh()
|
clientRefresh()
|
||||||
release()
|
release()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user