@@ -20,12 +20,15 @@ export type ContentDetails = {
20
20
description ?: string
21
21
}
22
22
23
+ export type FilterFn = ( [ fullSlug , ContentDetails ] : [ FullSlug , ContentDetails ] ) => boolean
24
+
23
25
interface Options {
24
26
enableSiteMap : boolean
25
27
enableRSS : boolean
26
28
rssLimit ?: number
27
29
rssFullHtml : boolean
28
30
includeEmptyFiles : boolean
31
+ filterFn ?: FilterFn
29
32
}
30
33
31
34
const defaultOptions : Options = {
@@ -48,7 +51,12 @@ function generateSiteMap(cfg: GlobalConfiguration, idx: ContentIndex): string {
48
51
return `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">${ urls } </urlset>`
49
52
}
50
53
51
- function generateRSSFeed ( cfg : GlobalConfiguration , idx : ContentIndex , limit ?: number ) : string {
54
+ function generateRSSFeed (
55
+ cfg : GlobalConfiguration ,
56
+ idx : ContentIndex ,
57
+ limit ?: number ,
58
+ filterFn : FilterFn = ( ) => true ,
59
+ ) : string {
52
60
const base = cfg . baseUrl ?? ""
53
61
54
62
const createURLEntry = ( slug : SimpleSlug , content : ContentDetails ) : string => `<item>
@@ -60,6 +68,8 @@ function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex, limit?: nu
60
68
</item>`
61
69
62
70
const items = Array . from ( idx )
71
+ // .filter(filterFn?.bind(null) ?? (() => true))
72
+ . filter ( filterFn )
63
73
. sort ( ( [ _ , f1 ] , [ __ , f2 ] ) => {
64
74
if ( f1 . date && f2 . date ) {
65
75
return f2 . date . getTime ( ) - f1 . date . getTime ( )
@@ -150,7 +160,7 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
150
160
emitted . push (
151
161
await write ( {
152
162
ctx,
153
- content : generateRSSFeed ( cfg , linkIndex , opts . rssLimit ) ,
163
+ content : generateRSSFeed ( cfg , linkIndex , opts . rssLimit , opts . filterFn ) ,
154
164
slug : "index" as FullSlug ,
155
165
ext : ".xml" ,
156
166
} ) ,
0 commit comments