| | |
| | | import { toHtml } from "hast-util-to-html" |
| | | import { write } from "./helpers" |
| | | import { i18n } from "../../i18n" |
| | | import DepGraph from "../../depgraph" |
| | | |
| | | export type ContentIndex = Map<FullSlug, ContentDetails> |
| | | export type ContentDetails = { |
| | |
| | | enableRSS: boolean |
| | | rssLimit?: number |
| | | rssFullHtml: boolean |
| | | rssSlug: string |
| | | includeEmptyFiles: boolean |
| | | } |
| | | |
| | |
| | | enableRSS: true, |
| | | rssLimit: 10, |
| | | rssFullHtml: false, |
| | | rssSlug: "index", |
| | | includeEmptyFiles: true, |
| | | } |
| | | |
| | |
| | | opts = { ...defaultOptions, ...opts } |
| | | return { |
| | | name: "ContentIndex", |
| | | async getDependencyGraph(ctx, content, _resources) { |
| | | 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) { |
| | | const cfg = ctx.cfg.configuration |
| | | const emitted: FilePath[] = [] |
| | |
| | | await write({ |
| | | ctx, |
| | | content: generateRSSFeed(cfg, linkIndex, opts.rssLimit), |
| | | slug: "index" as FullSlug, |
| | | slug: (opts?.rssSlug ?? "index") as FullSlug, |
| | | ext: ".xml", |
| | | }), |
| | | ) |