mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-24 15:05:42 -05:00
refactor: incorporate suggestions
This commit is contained in:
parent
8b0dd136e4
commit
a8c0ffe721
@ -51,9 +51,6 @@ function generateSiteMap(cfg: GlobalConfiguration, idx: ContentIndex): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex, limit?: number): string {
|
function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex, limit?: number): string {
|
||||||
if (idx == undefined) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
const base = cfg.baseUrl ?? ""
|
const base = cfg.baseUrl ?? ""
|
||||||
|
|
||||||
const createURLEntry = (slug: SimpleSlug, content: ContentDetails): string => `<item>
|
const createURLEntry = (slug: SimpleSlug, content: ContentDetails): string => `<item>
|
||||||
@ -121,13 +118,9 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
|
|||||||
async emit(ctx, content, _resources) {
|
async emit(ctx, content, _resources) {
|
||||||
const cfg = ctx.cfg.configuration
|
const cfg = ctx.cfg.configuration
|
||||||
const emitted: FilePath[] = []
|
const emitted: FilePath[] = []
|
||||||
const feedIndices: Map<String, ContentIndex> = new Map()
|
const feedIndices: Map<string, ContentIndex> = new Map()
|
||||||
|
|
||||||
// bfahrenfort: ts can't see the expansion of opts above that guarantees a non-null feedDirectories
|
for (const feed of opts?.feedDirectories!) {
|
||||||
const directories =
|
|
||||||
opts?.feedDirectories == null ? defaultOptions.feedDirectories : opts.feedDirectories
|
|
||||||
|
|
||||||
for (const feed of directories) {
|
|
||||||
const linkIndex: ContentIndex = new Map()
|
const linkIndex: ContentIndex = new Map()
|
||||||
for (const [tree, file] of content) {
|
for (const [tree, file] of content) {
|
||||||
const slug = file.data.slug!
|
const slug = file.data.slug!
|
||||||
@ -153,13 +146,14 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
|
|||||||
feedIndices.set(feed, linkIndex)
|
feedIndices.set(feed, linkIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const siteFeed = feedIndices.get("index")!
|
||||||
if (opts?.enableSiteMap) {
|
if (opts?.enableSiteMap) {
|
||||||
emitted.push(
|
emitted.push(
|
||||||
await write({
|
await write({
|
||||||
ctx,
|
ctx,
|
||||||
// bfahrenfort: "index" is guaranteed non-null
|
// bfahrenfort: "index" is guaranteed non-null
|
||||||
// see directories instantiation and feedIndices.set iterating over directories
|
// see directories instantiation and feedIndices.set iterating over directories
|
||||||
content: generateSiteMap(cfg, feedIndices.get("index")!),
|
content: generateSiteMap(cfg, siteFeed),
|
||||||
slug: "sitemap" as FullSlug,
|
slug: "sitemap" as FullSlug,
|
||||||
ext: ".xml",
|
ext: ".xml",
|
||||||
}),
|
}),
|
||||||
@ -167,16 +161,19 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (opts?.enableRSS) {
|
if (opts?.enableRSS) {
|
||||||
directories.map(async (feed) => {
|
var feedPromises: Promise<FilePath>[] = []
|
||||||
const emittedFeed = await write({
|
opts.feedDirectories!.map((feed) => {
|
||||||
ctx,
|
feedPromises.push(
|
||||||
// bfahrenfort: we just generated a feedIndices entry for every directories entry, guaranteed non-null
|
write({
|
||||||
content: generateRSSFeed(cfg, feedIndices.get(feed)!, opts?.rssLimit),
|
ctx,
|
||||||
slug: feed as FullSlug,
|
// bfahrenfort: we just generated a feedIndices entry for every directories entry, guaranteed non-null
|
||||||
ext: ".xml",
|
content: generateRSSFeed(cfg, feedIndices.get(feed)!, opts?.rssLimit),
|
||||||
})
|
slug: feed as FullSlug,
|
||||||
emitted.push(emittedFeed)
|
ext: ".xml",
|
||||||
|
}),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
emitted.push(...(await Promise.all(feedPromises)))
|
||||||
}
|
}
|
||||||
|
|
||||||
const fp = joinSegments("static", "contentIndex") as FullSlug
|
const fp = joinSegments("static", "contentIndex") as FullSlug
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user