From bcde2abcb20ad02a0c3f1430b9d620ee60e6cb63 Mon Sep 17 00:00:00 2001
From: dralagen <dralagen@dralagen.fr>
Date: Wed, 19 Mar 2025 04:47:35 +0000
Subject: [PATCH] fix(transformer): find last modified date form commit on submodule (#1831)
---
quartz/components/pages/FolderContent.tsx | 118 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 96 insertions(+), 22 deletions(-)
diff --git a/quartz/components/pages/FolderContent.tsx b/quartz/components/pages/FolderContent.tsx
index d3f28dd..9621f4f 100644
--- a/quartz/components/pages/FolderContent.tsx
+++ b/quartz/components/pages/FolderContent.tsx
@@ -1,55 +1,129 @@
-import { QuartzComponentConstructor, QuartzComponentProps } from "../types"
-import path from "path"
+import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"
import style from "../styles/listPage.scss"
-import { PageList } from "../PageList"
-import { stripSlashes, simplifySlug } from "../../util/path"
+import { PageList, SortFn } from "../PageList"
import { Root } from "hast"
import { htmlToJsx } from "../../util/jsx"
import { i18n } from "../../i18n"
-
+import { QuartzPluginData } from "../../plugins/vfile"
+import { ComponentChildren } from "preact"
+import { concatenateResources } from "../../util/resources"
+import { FileTrieNode } from "../../util/fileTrie"
interface FolderContentOptions {
/**
* Whether to display number of folders
*/
showFolderCount: boolean
+ showSubfolders: boolean
+ sort?: SortFn
}
const defaultOptions: FolderContentOptions = {
showFolderCount: true,
+ showSubfolders: true,
}
export default ((opts?: Partial<FolderContentOptions>) => {
const options: FolderContentOptions = { ...defaultOptions, ...opts }
+ let trie: FileTrieNode<
+ QuartzPluginData & {
+ slug: string
+ title: string
+ filePath: string
+ }
+ >
- function FolderContent(props: QuartzComponentProps) {
+ 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
- })
+
+ if (!trie) {
+ trie = new FileTrieNode([])
+ allFiles.forEach((file) => {
+ if (file.frontmatter) {
+ trie.add({
+ ...file,
+ slug: file.slug!,
+ title: file.frontmatter.title,
+ filePath: file.filePath!,
+ })
+ }
+ })
+ }
+
+ const folder = trie.findNode(fileData.slug!.split("/"))
+ if (!folder) {
+ return null
+ }
+
+ const allPagesInFolder: QuartzPluginData[] =
+ folder.children
+ .map((node) => {
+ // regular file, proceed
+ if (node.data) {
+ return node.data
+ }
+
+ if (node.isFolder && options.showSubfolders) {
+ // folders that dont have data need synthetic files
+ const getMostRecentDates = (): QuartzPluginData["dates"] => {
+ let maybeDates: QuartzPluginData["dates"] | undefined = undefined
+ for (const child of node.children) {
+ if (child.data?.dates) {
+ // compare all dates and assign to maybeDates if its more recent or its not set
+ if (!maybeDates) {
+ maybeDates = { ...child.data.dates }
+ } else {
+ if (child.data.dates.created > maybeDates.created) {
+ maybeDates.created = child.data.dates.created
+ }
+
+ if (child.data.dates.modified > maybeDates.modified) {
+ maybeDates.modified = child.data.dates.modified
+ }
+
+ if (child.data.dates.published > maybeDates.published) {
+ maybeDates.published = child.data.dates.published
+ }
+ }
+ }
+ }
+ return (
+ maybeDates ?? {
+ created: new Date(),
+ modified: new Date(),
+ published: new Date(),
+ }
+ )
+ }
+
+ return {
+ slug: node.slug,
+ dates: getMostRecentDates(),
+ frontmatter: {
+ title: node.displayName,
+ tags: [],
+ },
+ }
+ }
+ })
+ .filter((page) => page !== undefined) ?? []
const cssClasses: string[] = fileData.frontmatter?.cssclasses ?? []
- const classes = ["popover-hint", ...cssClasses].join(" ")
+ const classes = cssClasses.join(" ")
const listProps = {
...props,
+ sort: options.sort,
allFiles: allPagesInFolder,
}
- const content =
+ const content = (
(tree as Root).children.length === 0
? fileData.description
: htmlToJsx(fileData.filePath!, tree)
+ ) as ComponentChildren
return (
- <div class={classes}>
- <article>
- <p>{content}</p>
- </article>
+ <div class="popover-hint">
+ <article class={classes}>{content}</article>
<div class="page-listing">
{options.showFolderCount && (
<p>
@@ -66,6 +140,6 @@
)
}
- FolderContent.css = style + PageList.css
+ FolderContent.css = concatenateResources(style, PageList.css)
return FolderContent
}) satisfies QuartzComponentConstructor
--
Gitblit v1.10.0