From da1b6b37fe2ee09359b532f0d2669975b4476c95 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Fri, 14 Mar 2025 17:05:26 +0000
Subject: [PATCH] fix(explorer): fix incorrect recursive case for folder rendering
---
quartz/plugins/emitters/aliases.ts | 44 ++++++++++++++++++++------------------------
1 files changed, 20 insertions(+), 24 deletions(-)
diff --git a/quartz/plugins/emitters/aliases.ts b/quartz/plugins/emitters/aliases.ts
index 84ace74..a16093b 100644
--- a/quartz/plugins/emitters/aliases.ts
+++ b/quartz/plugins/emitters/aliases.ts
@@ -1,32 +1,31 @@
-import { CanonicalSlug, FilePath, ServerSlug, canonicalizeServer, resolveRelative } from "../../path"
+import { FilePath, joinSegments, resolveRelative, simplifySlug } from "../../util/path"
import { QuartzEmitterPlugin } from "../types"
-import path from 'path'
+import { write } from "./helpers"
+import DepGraph from "../../depgraph"
+import { getAliasSlugs } from "../transformers/frontmatter"
export const AliasRedirects: QuartzEmitterPlugin = () => ({
name: "AliasRedirects",
- getQuartzComponents() {
- return []
- },
- async emit(contentFolder, _cfg, content, _resources, emit): Promise<FilePath[]> {
- const fps: FilePath[] = []
+ async getDependencyGraph(ctx, content, _resources) {
+ const graph = new DepGraph<FilePath>()
+ const { argv } = ctx
for (const [_tree, file] of content) {
- const ogSlug = canonicalizeServer(file.data.slug!)
- const dir = path.relative(contentFolder, file.dirname ?? contentFolder)
-
- let aliases: CanonicalSlug[] = []
- if (file.data.frontmatter?.aliases) {
- aliases = file.data.frontmatter?.aliases
- } else if (file.data.frontmatter?.alias) {
- aliases = [file.data.frontmatter?.alias]
+ for (const slug of getAliasSlugs(file.data.frontmatter?.aliases ?? [], argv, file)) {
+ graph.addEdge(file.data.filePath!, joinSegments(argv.output, slug + ".html") as FilePath)
}
+ }
- for (const alias of aliases) {
- const slug = path.posix.join(dir, alias) as ServerSlug
+ return graph
+ },
+ async *emit(ctx, content, _resources) {
+ for (const [_tree, file] of content) {
+ const ogSlug = simplifySlug(file.data.slug!)
- const fp = slug + ".html" as FilePath
- const redirUrl = resolveRelative(canonicalizeServer(slug), ogSlug)
- await emit({
+ for (const slug of file.data.aliases ?? []) {
+ const redirUrl = resolveRelative(slug, file.data.slug!)
+ yield write({
+ ctx,
content: `
<!DOCTYPE html>
<html lang="en-us">
@@ -42,10 +41,7 @@
slug,
ext: ".html",
})
-
- fps.push(fp)
}
}
- return fps
- }
+ },
})
--
Gitblit v1.10.0