From 8fd75ffbfda30edd5a134a1fbf9b81ac3cebb2ff Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Mon, 24 Jul 2023 00:42:00 +0000
Subject: [PATCH] support attachments folder
---
quartz/plugins/emitters/aliases.ts | 26 +++++++++++++++-----------
1 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/quartz/plugins/emitters/aliases.ts b/quartz/plugins/emitters/aliases.ts
index 85681f1..7d2c08a 100644
--- a/quartz/plugins/emitters/aliases.ts
+++ b/quartz/plugins/emitters/aliases.ts
@@ -1,18 +1,24 @@
-import { CanonicalSlug, FilePath, ServerSlug, relativeToRoot } from "../../path"
+import {
+ CanonicalSlug,
+ FilePath,
+ ServerSlug,
+ canonicalizeServer,
+ resolveRelative,
+} from "../../path"
import { QuartzEmitterPlugin } from "../types"
-import path from 'path'
+import path from "path"
export const AliasRedirects: QuartzEmitterPlugin = () => ({
name: "AliasRedirects",
getQuartzComponents() {
return []
},
- async emit(contentFolder, _cfg, content, _resources, emit): Promise<FilePath[]> {
+ async emit({ argv }, content, _resources, emit): Promise<FilePath[]> {
const fps: FilePath[] = []
for (const [_tree, file] of content) {
- const ogSlug = file.data.slug!
- const dir = path.relative(contentFolder, file.dirname ?? contentFolder)
+ const ogSlug = canonicalizeServer(file.data.slug!)
+ const dir = path.relative(argv.directory, file.dirname ?? argv.directory)
let aliases: CanonicalSlug[] = []
if (file.data.frontmatter?.aliases) {
@@ -22,12 +28,10 @@
}
for (const alias of aliases) {
- const slug = (alias.startsWith("/")
- ? alias
- : path.posix.join(dir, alias)) as ServerSlug
+ const slug = path.posix.join(dir, alias) as ServerSlug
- const fp = slug + ".html" as FilePath
- const redirUrl = relativeToRoot(slug, ogSlug)
+ const fp = (slug + ".html") as FilePath
+ const redirUrl = resolveRelative(canonicalizeServer(slug), ogSlug)
await emit({
content: `
<!DOCTYPE html>
@@ -49,5 +53,5 @@
}
}
return fps
- }
+ },
})
--
Gitblit v1.10.0