diff --git a/quartz/components/FolderList.tsx b/quartz/components/FolderList.tsx deleted file mode 100644 index 7a81e2600..000000000 --- a/quartz/components/FolderList.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import path from "path" -import { resolveRelative, SimpleSlug } from "../util/path" -import { QuartzComponent, QuartzComponentProps } from "./types" - -type Props = { - limit?: number -} & QuartzComponentProps - -export const FolderList: QuartzComponent = ({ cfg, fileData, allFolders, limit }: Props) => { - let list: SimpleSlug[] = allFolders.sort(_alphabetical) - if (limit) { - list = list.slice(0, limit) - } - - return ( - - ) -} - -function _alphabetical(f1: SimpleSlug, f2: SimpleSlug): number { - const f1Title = _getTitle(f1) - const f2Title = _getTitle(f2) - return f1Title.localeCompare(f2Title) -} - -function _getTitle(folderSlug: SimpleSlug): string { - return folderSlug.split(path.posix.sep).at(-1)! -} diff --git a/quartz/components/pages/FolderContent.tsx b/quartz/components/pages/FolderContent.tsx index 90f981f1e..af5c437df 100644 --- a/quartz/components/pages/FolderContent.tsx +++ b/quartz/components/pages/FolderContent.tsx @@ -3,8 +3,7 @@ import path from "path" import style from "../styles/listPage.scss" import { PageList, SortFn } from "../PageList" -import { FolderList } from "../FolderList" -import { stripSlashes, simplifySlug, SimpleSlug, joinSegments } from "../../util/path" +import { stripSlashes, simplifySlug, SimpleSlug, joinSegments, FullSlug } from "../../util/path" import { Root } from "hast" import { htmlToJsx } from "../../util/jsx" import { i18n } from "../../i18n" @@ -32,7 +31,7 @@ export default ((opts?: Partial) => { const folderSlug = stripSlashes(simplifySlug(fileData.slug!)) const allPagesInFolder: QuartzPluginData[] = [] - const allSubfolders: Set = new Set() + const allSubfolders: Set = new Set() allFiles.forEach((file) => { const fileSlug = stripSlashes(simplifySlug(file.slug!)) @@ -48,22 +47,21 @@ export default ((opts?: Partial) => { if (isDirectChild) { allPagesInFolder.push(file) } else { - const folderSlug = joinSegments(...fileParts.slice(0, folderParts.length + 1)) - allSubfolders.add(folderSlug as SimpleSlug) + const folderSlug = joinSegments(...fileParts.slice(0, folderParts.length + 1)) as FullSlug + if (!allSubfolders.has(folderSlug)) { + allPagesInFolder.push(_createFolderData(folderSlug)) + } + allSubfolders.add(folderSlug) } }) const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? [] const classes = ["popover-hint", ...cssClasses].join(" ") - const pageListProps = { + const listProps = { ...props, sort: options.sort, allFiles: allPagesInFolder, } - const folderListProps = { - ...props, - allFolders: Array.from(allSubfolders.values()), - } const content = (tree as Root).children.length === 0 @@ -82,15 +80,7 @@ export default ((opts?: Partial) => {

)}
- -
- -
- {options.showSubfolders && ( -

{allSubfolders.size === 1 ? "1 subfolder." : `${allSubfolders.size} subfolders.`}

- )} -
- +
@@ -100,3 +90,12 @@ export default ((opts?: Partial) => { FolderContent.css = style + PageList.css return FolderContent }) satisfies QuartzComponentConstructor + +function _createFolderData(folderSlug: FullSlug): QuartzPluginData { + return { + slug: folderSlug, + frontmatter: { + title: folderSlug.split(path.posix.sep).at(-1)!, + }, + } +}