-
-
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
[markdown] Harder, better, faster, stronger vite-plugin-markdown
#4137
Conversation
🦋 Changeset detectedLatest commit: 95e4d8c The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
b57d625
to
5e24cb5
Compare
const title = content.title; | ||
const headings = content.astro.headings; |
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.
content.astro.headings
now throws! You'll get a nice error recommending Astro.props.headings
instead 👍
@@ -29,7 +29,7 @@ export function* getTopLevelPages( | |||
): Generator<string, void, unknown> { | |||
for (const info of walkParentInfos(id, ctx)) { | |||
const importers = (info?.importers || []).concat(info?.dynamicImporters || []); | |||
if (importers.length <= 2 && importers[0] === resolvedPagesVirtualModuleId) { |
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.
This assumed a pages
entry would never be imported, which breaks glob
imports for MD files in /pages
. The ?mdImport
flag hid this bug before!
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.
I fixed this a different way in #4156
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.
Oh, glad to hear it! Should I revert and let your PR go first @matthewp ?
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.
Update: Rebased with your fix 🙏
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.
Yep, sorry I forgot to reply here.
// Why not the "transform" hook instead of "load" + readFile? | ||
// A: Vite transforms all "import.meta.env" references to their values before | ||
// passing to the transform hook. This lets us get the truly raw value | ||
// to escape "import.meta.env" ourselves. |
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.
why do we want to escape import.meta.env
ourselves instead of letting Vite do it?
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.
Because Vite does not escape them! It'll replace all import.meta.env
usages with their values before giving you the code
, since Vite assumes all modules are JS modules. A manual file read is the only way around it
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.
Ohhhh right, we want them escaped. Makes sense! This is probably more accurate from a Rollup/Vite perspective as well, since I think load()
was designed to load the file from disk and turn it into JS, while transform()
is just for transforming the file without changing its file type.
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.
LGTM overall, but left one comment on how to improve the output to reduce potentially-expensive JSON.stringify
calls.
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.
LGTM assuming all other feedback gets addressed! Great work on this, Ben!
This reverts commit 3e5fa49.
498f6f4
to
37b805b
Compare
Changes
vite-plugin-markdown
to 1 compilation step?content
and?mdImport
flags 🥳renderMarkdown
in all cases, including globs - unblocks remark / rehype plugins appending to frontmatterlegacy.astroFlavoredMarkdown
vite-plugin-markdown
(now renamedvite-plugin-markdown-legacy
) based on legacy flagheadings
andfrontmatter
to layout props, for consistency with MDX ([MDX] Addheadings
andfrontmatter
to layout props #4134)Testing
astro-markdown
suite tolegacy-astro-flavored-markdown
for clarityastro-markdown
suite (formerlyastro-markdown-md-mode
): layouts, headings,import.meta.env
, raw and compiled contentDocs
N/A