mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-24 15:05:42 -05:00
Early return if index.md is not present
This commit is contained in:
parent
a8c0ffe721
commit
9fe604ba18
@ -8,6 +8,7 @@ import { toHtml } from "hast-util-to-html"
|
|||||||
import { write } from "./helpers"
|
import { write } from "./helpers"
|
||||||
import { i18n } from "../../i18n"
|
import { i18n } from "../../i18n"
|
||||||
import DepGraph from "../../depgraph"
|
import DepGraph from "../../depgraph"
|
||||||
|
import chalk from "chalk"
|
||||||
|
|
||||||
export type ContentIndex = Map<FullSlug, ContentDetails>
|
export type ContentIndex = Map<FullSlug, ContentDetails>
|
||||||
export type ContentDetails = {
|
export type ContentDetails = {
|
||||||
@ -23,6 +24,7 @@ export type ContentDetails = {
|
|||||||
interface Options {
|
interface Options {
|
||||||
enableSiteMap: boolean
|
enableSiteMap: boolean
|
||||||
enableRSS: boolean
|
enableRSS: boolean
|
||||||
|
bypassIndexCheck: boolean
|
||||||
rssLimit?: number
|
rssLimit?: number
|
||||||
rssFullHtml: boolean
|
rssFullHtml: boolean
|
||||||
includeEmptyFiles: boolean
|
includeEmptyFiles: boolean
|
||||||
@ -30,6 +32,7 @@ interface Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const defaultOptions: Options = {
|
const defaultOptions: Options = {
|
||||||
|
bypassIndexCheck: false,
|
||||||
enableSiteMap: true,
|
enableSiteMap: true,
|
||||||
enableRSS: true,
|
enableRSS: true,
|
||||||
rssLimit: 10,
|
rssLimit: 10,
|
||||||
@ -116,8 +119,18 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
|
|||||||
return graph
|
return graph
|
||||||
},
|
},
|
||||||
async emit(ctx, content, _resources) {
|
async emit(ctx, content, _resources) {
|
||||||
|
// If we're missing an index file, don't bother with sitemap/RSS gen
|
||||||
|
if (!(opts?.bypassIndexCheck || "index" in content.filter(c => c[1].data.slug!))) {
|
||||||
|
console.warn(chalk.yellow(`Warning: contentIndex:
|
||||||
|
content/ folder is missing an index.md. RSS feeds and sitemap will not be generated.
|
||||||
|
If you still wish to generate these files, add:
|
||||||
|
bypassIndexCheck: true,
|
||||||
|
to your configuration for Plugin.ContentIndex({...}) in quartz.config.ts`))
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
const cfg = ctx.cfg.configuration
|
const cfg = ctx.cfg.configuration
|
||||||
const emitted: FilePath[] = []
|
const emitted: Promise<FilePath>[] = []
|
||||||
const feedIndices: Map<string, ContentIndex> = new Map()
|
const feedIndices: Map<string, ContentIndex> = new Map()
|
||||||
|
|
||||||
for (const feed of opts?.feedDirectories!) {
|
for (const feed of opts?.feedDirectories!) {
|
||||||
@ -149,7 +162,7 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
|
|||||||
const siteFeed = feedIndices.get("index")!
|
const siteFeed = feedIndices.get("index")!
|
||||||
if (opts?.enableSiteMap) {
|
if (opts?.enableSiteMap) {
|
||||||
emitted.push(
|
emitted.push(
|
||||||
await write({
|
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
|
||||||
@ -161,24 +174,20 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (opts?.enableRSS) {
|
if (opts?.enableRSS) {
|
||||||
var feedPromises: Promise<FilePath>[] = []
|
|
||||||
opts.feedDirectories!.map((feed) => {
|
opts.feedDirectories!.map((feed) => {
|
||||||
feedPromises.push(
|
emitted.push(write({
|
||||||
write({
|
|
||||||
ctx,
|
ctx,
|
||||||
// bfahrenfort: we just generated a feedIndices entry for every directories entry, guaranteed non-null
|
// bfahrenfort: we just generated a feedIndices entry for every directories entry, guaranteed non-null
|
||||||
content: generateRSSFeed(cfg, feedIndices.get(feed)!, opts?.rssLimit),
|
content: generateRSSFeed(cfg, feedIndices.get(feed)!, opts?.rssLimit),
|
||||||
slug: feed as FullSlug,
|
slug: feed as FullSlug,
|
||||||
ext: ".xml",
|
ext: ".xml",
|
||||||
}),
|
}))
|
||||||
)
|
|
||||||
})
|
})
|
||||||
emitted.push(...(await Promise.all(feedPromises)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fp = joinSegments("static", "contentIndex") as FullSlug
|
const fp = joinSegments("static", "contentIndex") as FullSlug
|
||||||
const simplifiedIndex = Object.fromEntries(
|
const simplifiedIndex = Object.fromEntries(
|
||||||
Array.from(feedIndices.get("index") ?? []).map(([slug, content]) => {
|
Array.from(feedIndices.get("index")!).map(([slug, content]) => {
|
||||||
// remove description and from content index as nothing downstream
|
// remove description and from content index as nothing downstream
|
||||||
// actually uses it. we only keep it in the index as we need it
|
// actually uses it. we only keep it in the index as we need it
|
||||||
// for the RSS feed
|
// for the RSS feed
|
||||||
@ -189,7 +198,7 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
emitted.push(
|
emitted.push(
|
||||||
await write({
|
write({
|
||||||
ctx,
|
ctx,
|
||||||
content: JSON.stringify(simplifiedIndex),
|
content: JSON.stringify(simplifiedIndex),
|
||||||
slug: fp,
|
slug: fp,
|
||||||
@ -197,7 +206,7 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
return emitted
|
return await Promise.all(emitted)
|
||||||
},
|
},
|
||||||
getQuartzComponents: () => [],
|
getQuartzComponents: () => [],
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user