From ea92ed4f45e6e863a432447a977c33c6319423bc Mon Sep 17 00:00:00 2001
From: Cao Mingjun <me@caomingjun.com>
Date: Wed, 10 Jul 2024 00:42:33 +0000
Subject: [PATCH] feat: Allow custom sorting of FolderPage and TagPage (#1250)
---
quartz/plugins/emitters/folderPage.tsx | 28 ++++++++++++++++++++--------
1 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/quartz/plugins/emitters/folderPage.tsx b/quartz/plugins/emitters/folderPage.tsx
index 690fa56..bd17e57 100644
--- a/quartz/plugins/emitters/folderPage.tsx
+++ b/quartz/plugins/emitters/folderPage.tsx
@@ -3,7 +3,7 @@
import HeaderConstructor from "../../components/Header"
import BodyConstructor from "../../components/Body"
import { pageResources, renderPage } from "../../components/renderPage"
-import { ProcessedContent, defaultProcessedContent } from "../vfile"
+import { ProcessedContent, QuartzPluginData, defaultProcessedContent } from "../vfile"
import { FullPageLayout } from "../../cfg"
import path from "path"
import {
@@ -21,11 +21,13 @@
import { i18n } from "../../i18n"
import DepGraph from "../../depgraph"
-export const FolderPage: QuartzEmitterPlugin<Partial<FullPageLayout>> = (userOpts) => {
+export const FolderPage: QuartzEmitterPlugin<
+ Partial<FullPageLayout> & { sort?: (f1: QuartzPluginData, f2: QuartzPluginData) => number }
+> = (userOpts) => {
const opts: FullPageLayout = {
...sharedPageComponents,
...defaultListPageLayout,
- pageBody: FolderContent(),
+ pageBody: FolderContent({ sort: userOpts?.sort }),
...userOpts,
}
@@ -38,12 +40,21 @@
getQuartzComponents() {
return [Head, Header, Body, ...header, ...beforeBody, pageBody, ...left, ...right, Footer]
},
- async getDependencyGraph(_ctx, _content, _resources) {
+ async getDependencyGraph(_ctx, content, _resources) {
// Example graph:
- // nested/file.md --> nested/file.html
- // \-------> nested/index.html
- // TODO implement
- return new DepGraph<FilePath>()
+ // nested/file.md --> nested/index.html
+ // nested/file2.md ------^
+ const graph = new DepGraph<FilePath>()
+
+ content.map(([_tree, vfile]) => {
+ const slug = vfile.data.slug
+ const folderName = path.dirname(slug ?? "") as SimpleSlug
+ if (slug && folderName !== "." && folderName !== "tags") {
+ graph.addEdge(vfile.data.filePath!, joinSegments(folderName, "index.html") as FilePath)
+ }
+ })
+
+ return graph
},
async emit(ctx, content, resources): Promise<FilePath[]> {
const fps: FilePath[] = []
@@ -86,6 +97,7 @@
const externalResources = pageResources(pathToRoot(slug), resources)
const [tree, file] = folderDescriptions[folder]
const componentData: QuartzComponentProps = {
+ ctx,
fileData: file.data,
externalResources,
cfg,
--
Gitblit v1.10.0