mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-24 15:05:42 -05:00
Merge 162cf61135 into 6264f5685c
This commit is contained in:
commit
36c063dcf7
@ -6,9 +6,11 @@ import {
|
|||||||
TransformOptions,
|
TransformOptions,
|
||||||
stripSlashes,
|
stripSlashes,
|
||||||
simplifySlug,
|
simplifySlug,
|
||||||
|
slugifyFilePath,
|
||||||
splitAnchor,
|
splitAnchor,
|
||||||
transformLink,
|
transformLink,
|
||||||
joinSegments,
|
joinSegments,
|
||||||
|
FilePath,
|
||||||
} from "../../util/path"
|
} from "../../util/path"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { visit } from "unist-util-visit"
|
import { visit } from "unist-util-visit"
|
||||||
@ -23,6 +25,7 @@ interface Options {
|
|||||||
openLinksInNewTab: boolean
|
openLinksInNewTab: boolean
|
||||||
lazyLoad: boolean
|
lazyLoad: boolean
|
||||||
externalLinkIcon: boolean
|
externalLinkIcon: boolean
|
||||||
|
includeFrontmatterLinks: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultOptions: Options = {
|
const defaultOptions: Options = {
|
||||||
@ -31,6 +34,7 @@ const defaultOptions: Options = {
|
|||||||
openLinksInNewTab: false,
|
openLinksInNewTab: false,
|
||||||
lazyLoad: false,
|
lazyLoad: false,
|
||||||
externalLinkIcon: true,
|
externalLinkIcon: true,
|
||||||
|
includeFrontmatterLinks: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CrawlLinks: QuartzTransformerPlugin<Partial<Options> | undefined> = (userOpts) => {
|
export const CrawlLinks: QuartzTransformerPlugin<Partial<Options> | undefined> = (userOpts) => {
|
||||||
@ -49,6 +53,18 @@ export const CrawlLinks: QuartzTransformerPlugin<Partial<Options> | undefined> =
|
|||||||
allSlugs: ctx.allSlugs,
|
allSlugs: ctx.allSlugs,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add frontmatter links to outgoing links
|
||||||
|
if (opts.includeFrontmatterLinks && file.data.frontmatter) {
|
||||||
|
for (const [fmKey, fmValue] of Object.entries(file.data.frontmatter)) {
|
||||||
|
if (fmValue && typeof fmValue === "string") {
|
||||||
|
const dest = fmValue.match(/\[\[(.*)\]\]/)?.[1] as FilePath ?? null
|
||||||
|
if (dest) {
|
||||||
|
outgoing.add(simplifySlug(slugifyFilePath(dest)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
visit(tree, "element", (node, _index, _parent) => {
|
visit(tree, "element", (node, _index, _parent) => {
|
||||||
// rewrite all links
|
// rewrite all links
|
||||||
if (
|
if (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user