mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-05-18 06:24:22 +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) => {
|
||||
if (buildData.ignored(fp)) return
|
||||
changes.push({ path: fp as FilePath, type: "add" })
|
||||
rebuild(changes, clientRefresh, buildData)
|
||||
void rebuild(changes, clientRefresh, buildData)
|
||||
})
|
||||
.on("change", (fp) => {
|
||||
if (buildData.ignored(fp)) return
|
||||
changes.push({ path: fp as FilePath, type: "change" })
|
||||
rebuild(changes, clientRefresh, buildData)
|
||||
void rebuild(changes, clientRefresh, buildData)
|
||||
})
|
||||
.on("unlink", (fp) => {
|
||||
if (buildData.ignored(fp)) return
|
||||
changes.push({ path: fp as FilePath, type: "delete" })
|
||||
rebuild(changes, clientRefresh, buildData)
|
||||
void rebuild(changes, clientRefresh, buildData)
|
||||
})
|
||||
|
||||
return async () => {
|
||||
@ -162,6 +162,7 @@ async function rebuild(changes: ChangeEvent[], clientRefresh: () => void, buildD
|
||||
const buildId = randomIdNonSecure()
|
||||
ctx.buildId = buildId
|
||||
buildData.lastBuildMs = new Date().getTime()
|
||||
const numChangesInBuild = changes.length
|
||||
const release = await mut.acquire()
|
||||
|
||||
// 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 pathsToParse: FilePath[] = []
|
||||
for (const [fp, type] of Object.entries(changesSinceLastBuild)) {
|
||||
if (type === "delete" || path.extname(fp) !== ".md") continue
|
||||
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) {
|
||||
contentMap.set(content[1].data.relativePath!, {
|
||||
type: "markdown",
|
||||
content,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// update state using changesSinceLastBuild
|
||||
// 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(chalk.green(`Done rebuilding in ${perf.timeSince()}`))
|
||||
changes.length = 0
|
||||
changes.splice(0, numChangesInBuild)
|
||||
clientRefresh()
|
||||
release()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user