-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Adds logic to look for links in frontmatter #944
base: v4
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,11 @@ import { | |
TransformOptions, | ||
stripSlashes, | ||
simplifySlug, | ||
slugifyFilePath, | ||
splitAnchor, | ||
transformLink, | ||
joinSegments, | ||
FilePath, | ||
} from "../../util/path" | ||
import path from "path" | ||
import { visit } from "unist-util-visit" | ||
|
@@ -23,6 +25,7 @@ interface Options { | |
openLinksInNewTab: boolean | ||
lazyLoad: boolean | ||
externalLinkIcon: boolean | ||
includeFrontmatterLinks: boolean | ||
} | ||
|
||
const defaultOptions: Options = { | ||
|
@@ -31,6 +34,7 @@ const defaultOptions: Options = { | |
openLinksInNewTab: false, | ||
lazyLoad: false, | ||
externalLinkIcon: true, | ||
includeFrontmatterLinks: true, | ||
} | ||
|
||
export const CrawlLinks: QuartzTransformerPlugin<Partial<Options> | undefined> = (userOpts) => { | ||
|
@@ -49,6 +53,18 @@ export const CrawlLinks: QuartzTransformerPlugin<Partial<Options> | undefined> = | |
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") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah you might need to take a look at how we handle links in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we do this in ofm instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I tried to but I didn't manage to get a grasp of how it works. This is still too high level typescript for me 🤣 |
||
const dest = fmValue.match(/\[\[(.*)\]\]/)?.[1] as FilePath ?? null | ||
if (dest) { | ||
outgoing.add(simplifySlug(slugifyFilePath(dest))) | ||
} | ||
} | ||
} | ||
} | ||
|
||
visit(tree, "element", (node, _index, _parent) => { | ||
// rewrite all links | ||
if ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.