rebase(contentIndex): refactor to align with new emit interface

This commit is contained in:
bfahrenfort 2025-03-17 13:09:00 -05:00
parent 7b90d4feb1
commit 7e852aa427

View File

@ -8,20 +8,18 @@ import {
SimpleSlug, SimpleSlug,
joinSegments, joinSegments,
simplifySlug, simplifySlug,
slugifyFilePath,
} from "../../util/path" } from "../../util/path"
import { QuartzEmitterPlugin } from "../types" import { QuartzEmitterPlugin } from "../types"
import { toHtml } from "hast-util-to-html" import { toHtml } from "hast-util-to-html"
import { write } from "./helpers" import { write } from "./helpers"
import { i18n } from "../../i18n" import { i18n } from "../../i18n"
import { BuildCtx } from "../../util/ctx" import { BuildCtx } from "../../util/ctx"
import DepGraph from "../../depgraph"
import chalk from "chalk" import chalk from "chalk"
import { ProcessedContent } from "../vfile" import { ProcessedContent } from "../vfile"
type ContentIndex = Tree<TreeNode> type ContentIndex = Tree<TreeNode>
export type ContentDetails = { export type ContentDetails = {
slug: FullSlug slug?: FullSlug
filePath: FilePath filePath: FilePath
title: string title: string
links: SimpleSlug[] links: SimpleSlug[]
@ -30,7 +28,6 @@ export type ContentDetails = {
richContent?: string richContent?: string
date?: Date date?: Date
description?: string description?: string
slug?: FullSlug
noRSS?: boolean noRSS?: boolean
} }
@ -125,27 +122,7 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
opts = { ...defaultOptions, ...opts } opts = { ...defaultOptions, ...opts }
return { return {
name: "ContentIndex", name: "ContentIndex",
async getDependencyGraph(ctx, content, _resources) { async *emit(ctx, content) {
const graph = new DepGraph<FilePath>()
for (const [_tree, file] of content) {
const sourcePath = file.data.filePath!
graph.addEdge(
sourcePath,
joinSegments(ctx.argv.output, "static/contentIndex.json") as FilePath,
)
if (opts?.enableSiteMap) {
graph.addEdge(sourcePath, joinSegments(ctx.argv.output, "sitemap.xml") as FilePath)
}
if (opts?.enableRSS) {
graph.addEdge(sourcePath, joinSegments(ctx.argv.output, "index.xml") as FilePath)
}
}
return graph
},
async emit(ctx, content, _resources) {
// If we're missing an index file, don't bother with sitemap/RSS gen // If we're missing an index file, don't bother with sitemap/RSS gen
if ( if (
!( !(
@ -174,6 +151,8 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
// folded into the FeedGenerator postorder accept // folded into the FeedGenerator postorder accept
const detailsOf = ([tree, file]: ProcessedContent): ContentDetails => { const detailsOf = ([tree, file]: ProcessedContent): ContentDetails => {
return { return {
slug: file.data.slug!,
filePath: file.data.relativePath!,
title: file.data.frontmatter?.title!, title: file.data.frontmatter?.title!,
links: file.data.links ?? [], links: file.data.links ?? [],
tags: file.data.frontmatter?.tags ?? [], tags: file.data.frontmatter?.tags ?? [],
@ -183,7 +162,6 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
: undefined, : undefined,
date: getDate(ctx.cfg.configuration, file.data) ?? new Date(), date: getDate(ctx.cfg.configuration, file.data) ?? new Date(),
description: file.data.description ?? "", description: file.data.description ?? "",
slug: slugifyFilePath(file.data.relativePath!, true),
noRSS: file.data.frontmatter?.noRSS ?? false, noRSS: file.data.frontmatter?.noRSS ?? false,
} }
} }
@ -288,7 +266,8 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
}), }),
) )
return await Promise.all(emitted) // Promise<FilePath>[] -> Promise<FilePath[]>
return Promise.all(emitted)
}, },
externalResources: (ctx) => { externalResources: (ctx) => {
if (opts?.enableRSS) { if (opts?.enableRSS) {