| | |
| | | console.log(`Cleaned output directory \`${output}\` in ${perf.timeSince("clean")}`) |
| | | |
| | | perf.addEvent("glob") |
| | | const fps = await glob("**/*.md", argv.directory, cfg.configuration.ignorePatterns) |
| | | const allFiles = await glob("**/*.*", argv.directory, cfg.configuration.ignorePatterns) |
| | | const fps = allFiles.filter((fp) => fp.endsWith(".md")) |
| | | console.log( |
| | | `Found ${fps.length} input files from \`${argv.directory}\` in ${perf.timeSince("glob")}`, |
| | | ) |
| | | |
| | | const filePaths = fps.map((fp) => joinSegments(argv.directory, fp) as FilePath) |
| | | ctx.allSlugs = fps.map((fp) => slugifyFilePath(fp as FilePath)) |
| | | ctx.allSlugs = allFiles.map((fp) => slugifyFilePath(fp as FilePath)) |
| | | |
| | | const parsedFiles = await parseMarkdown(ctx, filePaths) |
| | | const filteredContent = filterContent(ctx, parsedFiles) |
| | |
| | | let timeoutId: ReturnType<typeof setTimeout> | null = null |
| | | let toRebuild: Set<FilePath> = new Set() |
| | | let toRemove: Set<FilePath> = new Set() |
| | | let trackedAssets: Set<FilePath> = new Set() |
| | | async function rebuild(fp: string, action: "add" | "change" | "delete") { |
| | | // don't do anything for gitignored files |
| | | if (ignored(fp)) { |
| | | return |
| | | } |
| | | |
| | | // dont bother rebuilding for non-content files, just track and refresh |
| | | if (path.extname(fp) !== ".md") { |
| | | // dont bother rebuilding for non-content files, just refresh |
| | | fp = toPosixPath(fp) |
| | | const filePath = joinSegments(argv.directory, fp) as FilePath |
| | | if (action === "add" || action === "change") { |
| | | trackedAssets.add(filePath) |
| | | } else if (action === "delete") { |
| | | trackedAssets.add(filePath) |
| | | } |
| | | clientRefresh() |
| | | return |
| | | } |
| | | |
| | | fp = toPosixPath(fp) |
| | | if (!ignored(fp)) { |
| | | const filePath = joinSegments(argv.directory, fp) as FilePath |
| | | if (action === "add" || action === "change") { |
| | | toRebuild.add(filePath) |
| | |
| | | try { |
| | | const filesToRebuild = [...toRebuild].filter((fp) => !toRemove.has(fp)) |
| | | |
| | | ctx.allSlugs = [...new Set([...contentMap.keys(), ...toRebuild])] |
| | | ctx.allSlugs = [...new Set([...contentMap.keys(), ...toRebuild, ...trackedAssets])] |
| | | .filter((fp) => !toRemove.has(fp)) |
| | | .map((fp) => slugifyFilePath(path.posix.relative(argv.directory, fp) as FilePath)) |
| | | |
| | |
| | | toRemove.clear() |
| | | }, 250) |
| | | } |
| | | } |
| | | |
| | | const watcher = chokidar.watch(".", { |
| | | persistent: true, |