@@ -11,116 +11,116 @@ import { concatenateResources } from "../../util/resources"
1111import { trieFromAllFiles } from "../../util/ctx"
1212
1313interface FolderContentOptions {
14- /**
15- * Whether to display number of folders
16- */
17- showFolderCount : boolean
18- showSubfolders : boolean
19- sort ?: SortFn
14+ /**
15+ * Whether to display number of folders
16+ */
17+ showFolderCount : boolean
18+ showSubfolders : boolean
19+ sort ?: SortFn
2020}
2121
2222const defaultOptions : FolderContentOptions = {
23- showFolderCount : true ,
24- showSubfolders : true ,
23+ showFolderCount : false ,
24+ showSubfolders : true ,
2525}
2626
2727export default ( ( opts ?: Partial < FolderContentOptions > ) => {
28- const options : FolderContentOptions = { ...defaultOptions , ...opts }
28+ const options : FolderContentOptions = { ...defaultOptions , ...opts }
2929
30- const FolderContent : QuartzComponent = ( props : QuartzComponentProps ) => {
31- const { tree, fileData, allFiles, cfg } = props
30+ const FolderContent : QuartzComponent = ( props : QuartzComponentProps ) => {
31+ const { tree, fileData, allFiles, cfg } = props
3232
33- const trie = ( props . ctx . trie ??= trieFromAllFiles ( allFiles ) )
34- const folder = trie . findNode ( fileData . slug ! . split ( "/" ) )
35- if ( ! folder ) {
36- return null
37- }
38-
39- const allPagesInFolder : QuartzPluginData [ ] =
40- folder . children
41- . map ( ( node ) => {
42- // regular file, proceed
43- if ( node . data ) {
44- return node . data
45- }
33+ const trie = ( props . ctx . trie ??= trieFromAllFiles ( allFiles ) )
34+ const folder = trie . findNode ( fileData . slug ! . split ( "/" ) )
35+ if ( ! folder ) {
36+ return null
37+ }
4638
47- if ( node . isFolder && options . showSubfolders ) {
48- // folders that dont have data need synthetic files
49- const getMostRecentDates = ( ) : QuartzPluginData [ "dates" ] => {
50- let maybeDates : QuartzPluginData [ "dates" ] | undefined = undefined
51- for ( const child of node . children ) {
52- if ( child . data ?. dates ) {
53- // compare all dates and assign to maybeDates if its more recent or its not set
54- if ( ! maybeDates ) {
55- maybeDates = { ...child . data . dates }
56- } else {
57- if ( child . data . dates . created > maybeDates . created ) {
58- maybeDates . created = child . data . dates . created
39+ const allPagesInFolder : QuartzPluginData [ ] =
40+ folder . children
41+ . map ( ( node ) => {
42+ // regular file, proceed
43+ if ( node . data ) {
44+ return node . data
5945 }
6046
61- if ( child . data . dates . modified > maybeDates . modified ) {
62- maybeDates . modified = child . data . dates . modified
63- }
47+ if ( node . isFolder && options . showSubfolders ) {
48+ // folders that dont have data need synthetic files
49+ const getMostRecentDates = ( ) : QuartzPluginData [ "dates" ] => {
50+ let maybeDates : QuartzPluginData [ "dates" ] | undefined = undefined
51+ for ( const child of node . children ) {
52+ if ( child . data ?. dates ) {
53+ // compare all dates and assign to maybeDates if its more recent or its not set
54+ if ( ! maybeDates ) {
55+ maybeDates = { ...child . data . dates }
56+ } else {
57+ if ( child . data . dates . created > maybeDates . created ) {
58+ maybeDates . created = child . data . dates . created
59+ }
6460
65- if ( child . data . dates . published > maybeDates . published ) {
66- maybeDates . published = child . data . dates . published
67- }
68- }
69- }
70- }
71- return (
72- maybeDates ?? {
73- created : new Date ( ) ,
74- modified : new Date ( ) ,
75- published : new Date ( ) ,
76- }
77- )
78- }
61+ if ( child . data . dates . modified > maybeDates . modified ) {
62+ maybeDates . modified = child . data . dates . modified
63+ }
7964
80- return {
81- slug : node . slug ,
82- dates : getMostRecentDates ( ) ,
83- frontmatter : {
84- title : node . displayName ,
85- tags : [ ] ,
86- } ,
87- }
88- }
89- } )
90- . filter ( ( page ) => page !== undefined ) ?? [ ]
91- const cssClasses : string [ ] = fileData . frontmatter ?. cssclasses ?? [ ]
92- const classes = cssClasses . join ( " " )
93- const listProps = {
94- ...props ,
95- sort : options . sort ,
96- allFiles : allPagesInFolder ,
97- }
65+ if ( child . data . dates . published > maybeDates . published ) {
66+ maybeDates . published = child . data . dates . published
67+ }
68+ }
69+ }
70+ }
71+ return (
72+ maybeDates ?? {
73+ created : new Date ( ) ,
74+ modified : new Date ( ) ,
75+ published : new Date ( ) ,
76+ }
77+ )
78+ }
79+
80+ return {
81+ slug : node . slug ,
82+ dates : getMostRecentDates ( ) ,
83+ frontmatter : {
84+ title : node . displayName ,
85+ tags : [ ] ,
86+ } ,
87+ }
88+ }
89+ } )
90+ . filter ( ( page ) => page !== undefined ) ?? [ ]
91+ const cssClasses : string [ ] = fileData . frontmatter ?. cssclasses ?? [ ]
92+ const classes = cssClasses . join ( " " )
93+ const listProps = {
94+ ...props ,
95+ sort : options . sort ,
96+ allFiles : allPagesInFolder ,
97+ }
9898
99- const content = (
100- ( tree as Root ) . children . length === 0
101- ? fileData . description
102- : htmlToJsx ( fileData . filePath ! , tree )
103- ) as ComponentChildren
99+ const content = (
100+ ( tree as Root ) . children . length === 0
101+ ? fileData . description
102+ : htmlToJsx ( fileData . filePath ! , tree )
103+ ) as ComponentChildren
104104
105- return (
106- < div class = "popover-hint" >
107- < article class = { classes } > { content } </ article >
108- < div class = "page-listing" >
109- { options . showFolderCount && (
110- < p >
111- { i18n ( cfg . locale ) . pages . folderContent . itemsUnderFolder ( {
112- count : allPagesInFolder . length ,
113- } ) }
114- </ p >
115- ) }
116- < div >
117- < PageList { ...listProps } />
118- </ div >
119- </ div >
120- </ div >
121- )
122- }
105+ return (
106+ < div class = "popover-hint" >
107+ < article class = { classes } > { content } </ article >
108+ < div class = "page-listing" >
109+ { options . showFolderCount && (
110+ < p >
111+ { i18n ( cfg . locale ) . pages . folderContent . itemsUnderFolder ( {
112+ count : allPagesInFolder . length ,
113+ } ) }
114+ </ p >
115+ ) }
116+ < div >
117+ < PageList { ...listProps } />
118+ </ div >
119+ </ div >
120+ </ div >
121+ )
122+ }
123123
124- FolderContent . css = concatenateResources ( style , PageList . css )
125- return FolderContent
124+ FolderContent . css = concatenateResources ( style , PageList . css )
125+ return FolderContent
126126} ) satisfies QuartzComponentConstructor
0 commit comments