From 9c8fec06d2b58e4e3bbe280ddc665a99fcc4878c Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Sun, 09 Mar 2025 22:33:15 +0000
Subject: [PATCH] feat: support non-singleton search

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

diff --git a/quartz/plugins/emitters/aliases.ts b/quartz/plugins/emitters/aliases.ts
index 84ace74..9d12a99 100644
--- a/quartz/plugins/emitters/aliases.ts
+++ b/quartz/plugins/emitters/aliases.ts
@@ -1,32 +1,33 @@
-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 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(contentFolder, _cfg, content, _resources, emit): Promise<FilePath[]> {
+  async emit(ctx, content, _resources): Promise<FilePath[]> {
     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 +48,5 @@
       }
     }
     return fps
-  }
+  },
 })

--
Gitblit v1.10.0