Jacky Zhao
2023-08-17 2f6747b1666316e579c6e7238092ac6a65d00925
quartz/plugins/emitters/contentIndex.ts
@@ -1,5 +1,11 @@
import { GlobalConfiguration } from "../../cfg"
import { CanonicalSlug, ClientSlug, FilePath, ServerSlug, canonicalizeServer } from "../../path"
import {
  CanonicalSlug,
  ClientSlug,
  FilePath,
  ServerSlug,
  canonicalizeServer,
} from "../../util/path"
import { QuartzEmitterPlugin } from "../types"
import path from "path"
@@ -68,7 +74,8 @@
  opts = { ...defaultOptions, ...opts }
  return {
    name: "ContentIndex",
    async emit(_contentDir, cfg, content, _resources, emit) {
    async emit(ctx, content, _resources, emit) {
      const cfg = ctx.cfg.configuration
      const emitted: FilePath[] = []
      const linkIndex: ContentIndex = new Map()
      for (const [_tree, file] of content) {
@@ -87,21 +94,23 @@
      }
      if (opts?.enableSiteMap) {
        await emit({
          content: generateSiteMap(cfg, linkIndex),
          slug: "sitemap" as ServerSlug,
          ext: ".xml",
        })
        emitted.push("sitemap.xml" as FilePath)
        emitted.push(
          await emit({
            content: generateSiteMap(cfg, linkIndex),
            slug: "sitemap" as ServerSlug,
            ext: ".xml",
          }),
        )
      }
      if (opts?.enableRSS) {
        await emit({
          content: generateRSSFeed(cfg, linkIndex),
          slug: "index" as ServerSlug,
          ext: ".xml",
        })
        emitted.push("index.xml" as FilePath)
        emitted.push(
          await emit({
            content: generateRSSFeed(cfg, linkIndex),
            slug: "index" as ServerSlug,
            ext: ".xml",
          }),
        )
      }
      const fp = path.join("static", "contentIndex") as ServerSlug
@@ -116,12 +125,13 @@
        }),
      )
      await emit({
        content: JSON.stringify(simplifiedIndex),
        slug: fp,
        ext: ".json",
      })
      emitted.push(`${fp}.json` as FilePath)
      emitted.push(
        await emit({
          content: JSON.stringify(simplifiedIndex),
          slug: fp,
          ext: ".json",
        }),
      )
      return emitted
    },