diff --git a/quartz.config.ts b/quartz.config.ts index 3774c2f17..fa29ab547 100644 --- a/quartz.config.ts +++ b/quartz.config.ts @@ -68,7 +68,14 @@ const config: QuartzConfig = { Plugin.GitHubFlavoredMarkdown(), Plugin.TableOfContents(), Plugin.CrawlLinks({ markdownLinkResolution: "shortest" }), - Plugin.Description(), + Plugin.Redirects({ + redirects: { + "/testredirect": "https://google.com", + // "/another-page": "https://another-example.com" + // Add more redirects as needed + } + }) + ], Plugin.Description(), ], filters: [Plugin.RemoveDrafts()], emitters: [ diff --git a/quartz/plugins/redirects.ts b/quartz/plugins/redirects.ts new file mode 100644 index 000000000..69ed3d465 --- /dev/null +++ b/quartz/plugins/redirects.ts @@ -0,0 +1,50 @@ +// quartz/plugins/redirects.ts +import { QuartzTransformerPlugin } from "../types" + +export interface Options { + redirects: Record +} + +export const Redirects: QuartzTransformerPlugin = (opts) => { + return { + name: "Redirects", + async transform(ctx) { + const pages = [] + + // Create redirect pages for each entry in the redirects map + for (const [fromPath, toUrl] of Object.entries(opts.redirects)) { + // Create a simple HTML page with meta refresh and JS redirect + const content = ` + + + + + Redirecting... + + +

Redirecting to ${toUrl}...

+ + +` + + // Create a FilePath for this redirect page + const redirectPath = fromPath.startsWith("/") ? fromPath.slice(1) : fromPath + + // Add to the context + ctx.pages.push({ + slug: redirectPath, + // Creating a basic file representation + file: { + path: redirectPath, + name: "index", + ext: "html", + content: Buffer.from(content) + }, + contentType: "text/html" + }) + } + + return ctx + } + } +}