From bf8e24501c51bc6361e2396f88f5d1ddd446ff23 Mon Sep 17 00:00:00 2001 From: Lisandra-dev Date: Sat, 20 Apr 2024 21:35:12 +0000 Subject: [PATCH] fix page content doesnt work --- quartz/components/pages/FolderContent.tsx | 124 +++++++++++----------- 1 file changed, 61 insertions(+), 63 deletions(-) diff --git a/quartz/components/pages/FolderContent.tsx b/quartz/components/pages/FolderContent.tsx index d31a96705b5dd..ffd8255a61fa9 100644 --- a/quartz/components/pages/FolderContent.tsx +++ b/quartz/components/pages/FolderContent.tsx @@ -1,74 +1,72 @@ -import { Root } from "hast"; -import path from "path"; +import { Root } from "hast" +import path from "path" -import { i18n } from "../../i18n"; -import { htmlToJsx } from "../../util/jsx"; -import { classNames } from "../../util/lang"; -import { simplifySlug,stripSlashes } from "../../util/path"; -import { PageList } from "../PageList"; -import style from "../styles/listPage.scss"; -import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"; +import { i18n } from "../../i18n" +import { htmlToJsx } from "../../util/jsx" +import { classNames } from "../../util/lang" +import { simplifySlug, stripSlashes } from "../../util/path" +import { PageList } from "../PageList" +import style from "../styles/listPage.scss" +import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types" interface FolderContentOptions { - /** - * Whether to display number of folders - */ - showFolderCount: boolean + /** + * Whether to display number of folders + */ + showFolderCount: boolean } const defaultOptions: FolderContentOptions = { - showFolderCount: true, -}; + showFolderCount: true, +} export default ((opts?: Partial) => { - const options: FolderContentOptions = { ...defaultOptions, ...opts }; + const options: FolderContentOptions = { ...defaultOptions, ...opts } - const FolderContent: QuartzComponent = (props: QuartzComponentProps) => { - const { tree, fileData, allFiles, cfg } = props; - const folderSlug = stripSlashes(simplifySlug(fileData.slug!)); - const allPagesInFolder = allFiles.filter((file) => { - const fileSlug = stripSlashes(simplifySlug(file.slug!)); - const prefixed = fileSlug.startsWith(folderSlug) && fileSlug !== folderSlug; - const folderParts = folderSlug.split(path.posix.sep); - const fileParts = fileSlug.split(path.posix.sep); - const isDirectChild = fileParts.length === folderParts.length + 1; - return prefixed && isDirectChild; - }); - const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? []; - const listProps = { - ...props, - allFiles: allPagesInFolder, - }; + const FolderContent: QuartzComponent = (props: QuartzComponentProps) => { + const { tree, fileData, allFiles, cfg } = props + const folderSlug = stripSlashes(simplifySlug(fileData.slug!)) + const allPagesInFolder = allFiles.filter((file) => { + const fileSlug = stripSlashes(simplifySlug(file.slug!)) + const prefixed = fileSlug.startsWith(folderSlug) && fileSlug !== folderSlug + const folderParts = folderSlug.split(path.posix.sep) + const fileParts = fileSlug.split(path.posix.sep) + const isDirectChild = fileParts.length === folderParts.length + 1 + return prefixed && isDirectChild + }) + const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? [] + const listProps = { + ...props, + allFiles: allPagesInFolder, + } - const content = - (tree as Root).children.length === 0 - ? undefined - : htmlToJsx(fileData.filePath!, tree); - const descFontmatter = fileData.frontmatter?.description; - const descContent = descFontmatter ? descFontmatter : content; - return ( -
-
-

{descContent}

-
- {(!content || content?.props?.children?.length === 0) && ( -
- {options.showFolderCount && ( -

- {i18n(cfg.locale).pages.folderContent.itemsUnderFolder({ - count: allPagesInFolder.length, - })} -

- )} -
- -
-
- )} -
- ); - }; + const content = + (tree as Root).children.length === 0 ? undefined : htmlToJsx(fileData.filePath!, tree) + const descFontmatter = fileData.frontmatter?.description + const descContent = content ? content : descFontmatter + return ( +
+
+

{descContent}

+
+ {(!content || content?.props?.children?.length === 0) && ( +
+ {options.showFolderCount && ( +

+ {i18n(cfg.locale).pages.folderContent.itemsUnderFolder({ + count: allPagesInFolder.length, + })} +

+ )} +
+ +
+
+ )} +
+ ) + } - FolderContent.css = style + PageList.css; - return FolderContent; -}) satisfies QuartzComponentConstructor; + FolderContent.css = style + PageList.css + return FolderContent +}) satisfies QuartzComponentConstructor