summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/fresh-gifts-buy.md5
-rw-r--r--packages/astro/src/content/loaders/glob.ts2
-rw-r--r--packages/astro/test/astro-markdown-plugins.test.js18
-rw-r--r--packages/astro/test/fixtures/content-layer-remark-plugins/.gitignore24
-rw-r--r--packages/astro/test/fixtures/content-layer-remark-plugins/astro.config.mjs20
-rw-r--r--packages/astro/test/fixtures/content-layer-remark-plugins/package.json16
-rw-r--r--packages/astro/test/fixtures/content-layer-remark-plugins/public/favicon.svg9
-rw-r--r--packages/astro/test/fixtures/content-layer-remark-plugins/src/content.config.ts16
-rw-r--r--packages/astro/test/fixtures/content-layer-remark-plugins/src/content/docs/test1.md6
-rw-r--r--packages/astro/test/fixtures/content-layer-remark-plugins/src/content/docs/test2.mdx8
-rw-r--r--packages/astro/test/fixtures/content-layer-remark-plugins/src/pages/[...slug].astro27
-rw-r--r--packages/astro/test/fixtures/content-layer-remark-plugins/src/pages/index.astro12
-rw-r--r--pnpm-lock.yaml9
13 files changed, 171 insertions, 1 deletions
diff --git a/.changeset/fresh-gifts-buy.md b/.changeset/fresh-gifts-buy.md
new file mode 100644
index 000000000..3f8633584
--- /dev/null
+++ b/.changeset/fresh-gifts-buy.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Pass raw frontmatter to remark plugins in glob loader
diff --git a/packages/astro/src/content/loaders/glob.ts b/packages/astro/src/content/loaders/glob.ts
index 1e080c57a..f96ab22b7 100644
--- a/packages/astro/src/content/loaders/glob.ts
+++ b/packages/astro/src/content/loaders/glob.ts
@@ -171,7 +171,7 @@ export function glob(globOptions: GlobOptions): Loader {
try {
rendered = await render?.({
id,
- data: parsedData,
+ data,
body,
filePath,
digest,
diff --git a/packages/astro/test/astro-markdown-plugins.test.js b/packages/astro/test/astro-markdown-plugins.test.js
index 09cb76d2d..ec7e70172 100644
--- a/packages/astro/test/astro-markdown-plugins.test.js
+++ b/packages/astro/test/astro-markdown-plugins.test.js
@@ -120,6 +120,24 @@ describe('Astro Markdown plugins', () => {
testRemark(html);
testRehype(html, '#smartypants-test');
});
+
+ describe("content layer plugins", () => {
+ let fixture
+ before(async () => {
+ fixture = await loadFixture({
+ root: './fixtures/content-layer-remark-plugins/',
+ });
+ await fixture.build();
+ });
+
+ it('passes untransformed frontmatter to remark plugins', async () => {
+ const html = await fixture.readFile('/test1/index.html');
+ const $ = cheerio.load(html);
+ assert.equal($('p').text(), 'Not transformed');
+ });
+
+ });
+
});
function testRehype(html, headingId) {
diff --git a/packages/astro/test/fixtures/content-layer-remark-plugins/.gitignore b/packages/astro/test/fixtures/content-layer-remark-plugins/.gitignore
new file mode 100644
index 000000000..16d54bb13
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer-remark-plugins/.gitignore
@@ -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/
diff --git a/packages/astro/test/fixtures/content-layer-remark-plugins/astro.config.mjs b/packages/astro/test/fixtures/content-layer-remark-plugins/astro.config.mjs
new file mode 100644
index 000000000..950fdd73b
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer-remark-plugins/astro.config.mjs
@@ -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" }],
+ });
+ };
+ },
+ ],
+ },
+});
diff --git a/packages/astro/test/fixtures/content-layer-remark-plugins/package.json b/packages/astro/test/fixtures/content-layer-remark-plugins/package.json
new file mode 100644
index 000000000..d00fb93e9
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer-remark-plugins/package.json
@@ -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:*"
+ }
+}
diff --git a/packages/astro/test/fixtures/content-layer-remark-plugins/public/favicon.svg b/packages/astro/test/fixtures/content-layer-remark-plugins/public/favicon.svg
new file mode 100644
index 000000000..f157bd1c5
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer-remark-plugins/public/favicon.svg
@@ -0,0 +1,9 @@
+<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 128 128">
+ <path d="M50.4 78.5a75.1 75.1 0 0 0-28.5 6.9l24.2-65.7c.7-2 1.9-3.2 3.4-3.2h29c1.5 0 2.7 1.2 3.4 3.2l24.2 65.7s-11.6-7-28.5-7L67 45.5c-.4-1.7-1.6-2.8-2.9-2.8-1.3 0-2.5 1.1-2.9 2.7L50.4 78.5Zm-1.1 28.2Zm-4.2-20.2c-2 6.6-.6 15.8 4.2 20.2a17.5 17.5 0 0 1 .2-.7 5.5 5.5 0 0 1 5.7-4.5c2.8.1 4.3 1.5 4.7 4.7.2 1.1.2 2.3.2 3.5v.4c0 2.7.7 5.2 2.2 7.4a13 13 0 0 0 5.7 4.9v-.3l-.2-.3c-1.8-5.6-.5-9.5 4.4-12.8l1.5-1a73 73 0 0 0 3.2-2.2 16 16 0 0 0 6.8-11.4c.3-2 .1-4-.6-6l-.8.6-1.6 1a37 37 0 0 1-22.4 2.7c-5-.7-9.7-2-13.2-6.2Z" />
+ <style>
+ path { fill: #000; }
+ @media (prefers-color-scheme: dark) {
+ path { fill: #FFF; }
+ }
+ </style>
+</svg>
diff --git a/packages/astro/test/fixtures/content-layer-remark-plugins/src/content.config.ts b/packages/astro/test/fixtures/content-layer-remark-plugins/src/content.config.ts
new file mode 100644
index 000000000..8fc303804
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer-remark-plugins/src/content.config.ts
@@ -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 };
diff --git a/packages/astro/test/fixtures/content-layer-remark-plugins/src/content/docs/test1.md b/packages/astro/test/fixtures/content-layer-remark-plugins/src/content/docs/test1.md
new file mode 100644
index 000000000..a5e9bc608
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer-remark-plugins/src/content/docs/test1.md
@@ -0,0 +1,6 @@
+---
+title: Test Markdown
+foo: bar
+---
+
+# Test Markdown
diff --git a/packages/astro/test/fixtures/content-layer-remark-plugins/src/content/docs/test2.mdx b/packages/astro/test/fixtures/content-layer-remark-plugins/src/content/docs/test2.mdx
new file mode 100644
index 000000000..3b937b559
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer-remark-plugins/src/content/docs/test2.mdx
@@ -0,0 +1,8 @@
+---
+title: Test MDX
+foo: bar
+---
+
+Hello from MDX!
+
+[Markdown page](/test1)
diff --git a/packages/astro/test/fixtures/content-layer-remark-plugins/src/pages/[...slug].astro b/packages/astro/test/fixtures/content-layer-remark-plugins/src/pages/[...slug].astro
new file mode 100644
index 000000000..757765a4c
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer-remark-plugins/src/pages/[...slug].astro
@@ -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>
diff --git a/packages/astro/test/fixtures/content-layer-remark-plugins/src/pages/index.astro b/packages/astro/test/fixtures/content-layer-remark-plugins/src/pages/index.astro
new file mode 100644
index 000000000..34ce5d610
--- /dev/null
+++ b/packages/astro/test/fixtures/content-layer-remark-plugins/src/pages/index.astro
@@ -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> \ No newline at end of file
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 4d1eb4f95..c50866380 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2655,6 +2655,15 @@ importers:
specifier: ^10.25.0
version: 10.25.1
+ packages/astro/test/fixtures/content-layer-remark-plugins:
+ dependencies:
+ '@astrojs/mdx':
+ specifier: workspace:*
+ version: link:../../../../integrations/mdx
+ astro:
+ specifier: workspace:*
+ version: link:../../..
+
packages/astro/test/fixtures/content-layer-rendering:
dependencies:
'@astrojs/mdx':