From 5a39719898fe486994750ec24fa430f332fa67eb Mon Sep 17 00:00:00 2001
From: Aaron Pham <contact@aarnphm.xyz>
Date: Thu, 06 Mar 2025 01:33:16 +0000
Subject: [PATCH] fix(graph): set container as renderGroup to avoid redrawing multiple times (#1736)

---
 quartz/plugins/emitters/aliases.ts |   43 ++++++++++++++++++++++++-------------------
 1 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/quartz/plugins/emitters/aliases.ts b/quartz/plugins/emitters/aliases.ts
index 84ace74..b5bfff0 100644
--- a/quartz/plugins/emitters/aliases.ts
+++ b/quartz/plugins/emitters/aliases.ts
@@ -1,32 +1,37 @@
-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[]> {
+  async getDependencyGraph(ctx, content, _resources) {
+    const graph = new DepGraph<FilePath>()
+
+    const { argv } = ctx
+    for (const [_tree, file] of content) {
+      for (const slug of getAliasSlugs(file.data.frontmatter?.aliases ?? [], argv, file)) {
+        graph.addEdge(file.data.filePath!, joinSegments(argv.output, slug + ".html") as FilePath)
+      }
+    }
+
+    return graph
+  },
+  async emit(ctx, content, _resources): Promise<FilePath[]> {
+    const { argv } = ctx
     const fps: FilePath[] = []
 
     for (const [_tree, file] of content) {
-      const ogSlug = canonicalizeServer(file.data.slug!)
-      const dir = path.relative(contentFolder, file.dirname ?? contentFolder)
+      const ogSlug = simplifySlug(file.data.slug!)
 
-      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 alias of aliases) {
-        const slug = path.posix.join(dir, alias) as ServerSlug
-
-        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!)
+        const fp = await write({
+          ctx,
           content: `
             <!DOCTYPE html>
             <html lang="en-us">
@@ -47,5 +52,5 @@
       }
     }
     return fps
-  }
+  },
 })

--
Gitblit v1.10.0