From 3ac6b42e16dca5a44ed3fec2c0314f1dbbc2322b Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Sun, 16 Jul 2023 06:02:12 +0000
Subject: [PATCH] finish path refactoring, add sourcemap + better trace support

---
 quartz/plugins/emitters/aliases.ts |   18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/quartz/plugins/emitters/aliases.ts b/quartz/plugins/emitters/aliases.ts
index c9a019b..84ace74 100644
--- a/quartz/plugins/emitters/aliases.ts
+++ b/quartz/plugins/emitters/aliases.ts
@@ -1,4 +1,4 @@
-import { relativeToRoot } from "../../path"
+import { CanonicalSlug, FilePath, ServerSlug, canonicalizeServer, resolveRelative } from "../../path"
 import { QuartzEmitterPlugin } from "../types"
 import path from 'path'
 
@@ -7,14 +7,14 @@
   getQuartzComponents() {
     return []
   },
-  async emit(contentFolder, _cfg, content, _resources, emit): Promise<string[]> {
-    const fps: string[] = []
+  async emit(contentFolder, _cfg, content, _resources, emit): Promise<FilePath[]> {
+    const fps: FilePath[] = []
 
     for (const [_tree, file] of content) {
-      const ogSlug = file.data.slug!
+      const ogSlug = canonicalizeServer(file.data.slug!)
       const dir = path.relative(contentFolder, file.dirname ?? contentFolder)
 
-      let aliases: string[] = []
+      let aliases: CanonicalSlug[] = []
       if (file.data.frontmatter?.aliases) {
         aliases = file.data.frontmatter?.aliases
       } else if (file.data.frontmatter?.alias) {
@@ -22,12 +22,10 @@
       }
 
       for (const alias of aliases) {
-        const slug = alias.startsWith("/")
-          ? alias
-          : path.posix.join(dir, alias)
+        const slug = path.posix.join(dir, alias) as ServerSlug
 
-        const fp = slug + ".html"
-        const redirUrl = relativeToRoot(slug, ogSlug)
+        const fp = slug + ".html" as FilePath
+        const redirUrl = resolveRelative(canonicalizeServer(slug), ogSlug)
         await emit({
           content: `
             <!DOCTYPE html>

--
Gitblit v1.10.0