-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pass raw frontmatter to when parsing markdown in glob loader (#1…
- Loading branch information
Showing
13 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Pass raw frontmatter to remark plugins in glob loader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/astro/test/fixtures/content-layer-remark-plugins/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# build output | ||
dist/ | ||
# generated types | ||
.astro/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
||
# logs | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
|
||
|
||
# environment variables | ||
.env | ||
.env.production | ||
|
||
# macOS-specific files | ||
.DS_Store | ||
|
||
# jetbrains setting folder | ||
.idea/ |
20 changes: 20 additions & 0 deletions
20
packages/astro/test/fixtures/content-layer-remark-plugins/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// @ts-check | ||
import { defineConfig } from 'astro/config'; | ||
import mdx from '@astrojs/mdx'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [mdx()], | ||
markdown: { | ||
remarkPlugins: [ | ||
function myRemarkPlugin() { | ||
return function transformer(tree, file) { | ||
tree.children.push({ | ||
type: 'paragraph', | ||
children: [{ type: 'text', value: file?.data?.astro?.frontmatter?.addedByTransformer ? "Transformed" : "Not transformed" }], | ||
}); | ||
}; | ||
}, | ||
], | ||
}, | ||
}); |
16 changes: 16 additions & 0 deletions
16
packages/astro/test/fixtures/content-layer-remark-plugins/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "@test/content-layer-remark-plugins", | ||
"type": "module", | ||
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
"dev": "astro dev", | ||
"build": "astro build", | ||
"preview": "astro preview", | ||
"astro": "astro" | ||
}, | ||
"dependencies": { | ||
"@astrojs/mdx": "workspace:*", | ||
"astro": "workspace:*" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/astro/test/fixtures/content-layer-remark-plugins/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions
16
packages/astro/test/fixtures/content-layer-remark-plugins/src/content.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { defineCollection, z } from 'astro:content'; | ||
import { glob } from 'astro/loaders'; | ||
|
||
const docs = defineCollection({ | ||
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/docs' }), | ||
schema: z | ||
.object({ | ||
title: z.string(), | ||
}) | ||
.transform((data) => ({ | ||
...data, | ||
someOtherField: 'Added by transform', | ||
})), | ||
}); | ||
|
||
export const collections = { docs }; |
6 changes: 6 additions & 0 deletions
6
...ages/astro/test/fixtures/content-layer-remark-plugins/src/content/docs/test1.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: Test Markdown | ||
foo: bar | ||
--- | ||
|
||
# Test Markdown |
8 changes: 8 additions & 0 deletions
8
...ges/astro/test/fixtures/content-layer-remark-plugins/src/content/docs/test2.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
title: Test MDX | ||
foo: bar | ||
--- | ||
|
||
Hello from MDX! | ||
|
||
[Markdown page](/test1) |
27 changes: 27 additions & 0 deletions
27
packages/astro/test/fixtures/content-layer-remark-plugins/src/pages/[...slug].astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
import { getCollection, render } from 'astro:content'; | ||
export async function getStaticPaths() { | ||
const docs = await getCollection('docs'); | ||
return docs.map(doc => ({ | ||
params: { slug: doc.id }, | ||
props: { doc }, | ||
})); | ||
} | ||
const { doc } = Astro.props; | ||
const { Content } = await render(doc); | ||
--- | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<h1>{doc.data.title}</h1> | ||
<Content /> | ||
</body> | ||
</html> |
12 changes: 12 additions & 0 deletions
12
packages/astro/test/fixtures/content-layer-remark-plugins/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<p><a href="/test1">Markdown page</a></p> | ||
<p><a href="/test2">MDX page</a></p> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.