Skip to content

Commit bd0dd9d

Browse files
committed
Revert "feat: support .md overrides for content collections"
This reverts commit c06f83e.
1 parent 5b9a1f3 commit bd0dd9d

File tree

15 files changed

+40
-94
lines changed

15 files changed

+40
-94
lines changed

examples/with-markdoc/src/content/docs/intro.md renamed to examples/with-markdoc/src/content/docs/intro.mdoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: Welcome to Markdoc 👋
33
---
44

5-
This simple starter showcases Markdoc's features with Content Collections. All Markdoc features are supported, including this nifty built-in `{% table %}` tag:
5+
This simple starter showcases Markdoc with Content Collections. All Markdoc features are supported, including this nifty built-in `{% table %}` tag:
66

77
{% table %}
88
* Feature
99
* Supported
1010
---
11-
* `.mdoc` + `.md` in Content Collections
11+
* `.mdoc` in Content Collections
1212
* ✅
1313
---
1414
* Markdoc transform configuration

packages/astro/src/@types/astro.ts

-1
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,6 @@ export interface AstroConfig extends z.output<typeof AstroConfigSchema> {
978978
}
979979

980980
export interface ContentEntryType {
981-
name: string;
982981
extensions: string[];
983982
getEntryInfo(params: { fileUrl: URL; contents: string }): Promise<{
984983
data: Record<string, unknown>;

packages/astro/src/content/consts.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ export const STYLES_PLACEHOLDER = '@@ASTRO-STYLES@@';
66
export const SCRIPTS_PLACEHOLDER = '@@ASTRO-SCRIPTS@@';
77

88
export const CONTENT_TYPES_FILE = 'types.d.ts';
9-
export const MARKDOWN_CONTENT_ENTRY_TYPE_NAME = 'astro:markdown';

packages/astro/src/content/index.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
export { attachContentServerListeners } from './server-listeners.js';
22
export { createContentTypesGenerator } from './types-generator.js';
3-
export {
4-
contentObservable,
5-
getContentPaths,
6-
getDotAstroTypeReference,
7-
hasMdContentEntryTypeOverride,
8-
} from './utils.js';
9-
export { getMarkdownContentEntryType } from './markdown.js';
3+
export { contentObservable, getContentPaths, getDotAstroTypeReference } from './utils.js';
104
export { astroContentAssetPropagationPlugin } from './vite-plugin-content-assets.js';
115
export { astroContentImportPlugin } from './vite-plugin-content-imports.js';
126
export { astroContentVirtualModPlugin } from './vite-plugin-content-virtual-mod.js';

packages/astro/src/content/markdown.ts

-29
This file was deleted.

packages/astro/src/content/template/markdown-types.d.ts

-9
This file was deleted.

packages/astro/src/content/template/types.d.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
declare module 'astro:content' {
2+
interface Render {
3+
'.md': Promise<{
4+
Content: import('astro').MarkdownInstance<{}>['Content'];
5+
headings: import('astro').MarkdownHeading[];
6+
remarkPluginFrontmatter: Record<string, any>;
7+
}>;
8+
}
9+
}
10+
111
declare module 'astro:content' {
212
export { z } from 'astro/zod';
313
export type CollectionEntry<C extends keyof typeof entryMap> =

packages/astro/src/content/utils.ts

+1-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ErrorPayload as ViteErrorPayload, normalizePath, ViteDevServer } from '
77
import { z } from 'zod';
88
import { AstroConfig, AstroSettings } from '../@types/astro.js';
99
import { AstroError, AstroErrorData } from '../core/errors/index.js';
10-
import { CONTENT_TYPES_FILE, MARKDOWN_CONTENT_ENTRY_TYPE_NAME } from './consts.js';
10+
import { CONTENT_TYPES_FILE } from './consts.js';
1111

1212
export const collectionConfigParser = z.object({
1313
schema: z.any().optional(),
@@ -312,7 +312,6 @@ export function contentObservable(initialCtx: ContentCtx): ContentObservable {
312312
}
313313

314314
export type ContentPaths = {
315-
templateDir: URL;
316315
contentDir: URL;
317316
cacheDir: URL;
318317
typesTemplate: URL;
@@ -330,7 +329,6 @@ export function getContentPaths(
330329
const configStats = search(fs, srcDir);
331330
const templateDir = new URL('../../src/content/template/', import.meta.url);
332331
return {
333-
templateDir,
334332
cacheDir: new URL('.astro/', root),
335333
contentDir: new URL('./content/', srcDir),
336334
typesTemplate: new URL('types.d.ts', templateDir),
@@ -349,11 +347,3 @@ function search(fs: typeof fsMod, srcDir: URL) {
349347
}
350348
return { exists: false, url: paths[0] };
351349
}
352-
353-
export function hasMdContentEntryTypeOverride(settings: Pick<AstroSettings, 'contentEntryTypes'>) {
354-
return settings.contentEntryTypes.some(
355-
(contentEntryType) =>
356-
contentEntryType.name !== MARKDOWN_CONTENT_ENTRY_TYPE_NAME &&
357-
contentEntryType.extensions.includes('.md')
358-
);
359-
}

packages/astro/src/core/config/settings.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { fileURLToPath, pathToFileURL } from 'url';
55
import jsxRenderer from '../../jsx/renderer.js';
66
import { createDefaultDevConfig } from './config.js';
77
import { loadTSConfig } from './tsconfig.js';
8+
import { markdownContentEntryType } from '../../vite-plugin-markdown/content-entry-type.js';
89

910
export function createBaseSettings(config: AstroConfig): AstroSettings {
1011
return {
@@ -15,7 +16,7 @@ export function createBaseSettings(config: AstroConfig): AstroSettings {
1516
adapter: undefined,
1617
injectedRoutes: [],
1718
pageExtensions: ['.astro', '.html', ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS],
18-
contentEntryTypes: [],
19+
contentEntryTypes: [markdownContentEntryType],
1920
renderers: [jsxRenderer],
2021
scripts: [],
2122
watchFiles: [],

packages/astro/src/integrations/index.ts

-8
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ import {
1212
HookParameters,
1313
RouteData,
1414
} from '../@types/astro.js';
15-
import { hasMdContentEntryTypeOverride } from '../content/utils.js';
1615
import type { SerializedSSRManifest } from '../core/app/types';
1716
import type { PageBuildData } from '../core/build/types';
1817
import { mergeConfig } from '../core/config/config.js';
1918
import { info, LogOptions } from '../core/logger/core.js';
20-
import { getMarkdownContentEntryType } from '../content/index.js';
2119

2220
async function withTakingALongTimeMsg<T>({
2321
name,
@@ -128,12 +126,6 @@ export async function runHookConfigSetup({
128126
}
129127

130128
updatedSettings.config = updatedConfig;
131-
if (!hasMdContentEntryTypeOverride(updatedSettings)) {
132-
updatedSettings.contentEntryTypes.push(
133-
await getMarkdownContentEntryType(updatedSettings.config, fs)
134-
);
135-
}
136-
137129
return updatedSettings;
138130
}
139131

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { fileURLToPath } from 'node:url';
2+
import { ContentEntryType } from '../@types/astro.js';
3+
import { parseFrontmatter } from '../content/utils.js';
4+
5+
export const markdownContentEntryType: ContentEntryType = {
6+
extensions: ['.md'],
7+
async getEntryInfo({ fileUrl, contents }: { fileUrl: URL; contents: string }) {
8+
const parsed = parseFrontmatter(contents, fileURLToPath(fileUrl));
9+
return {
10+
data: parsed.data,
11+
body: parsed.content,
12+
slug: parsed.data.slug,
13+
rawData: parsed.matter,
14+
};
15+
},
16+
};

packages/astro/src/vite-plugin-markdown/index.ts

-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type { Plugin } from 'vite';
1010
import { normalizePath } from 'vite';
1111
import type { AstroSettings } from '../@types/astro';
1212
import { getContentPaths } from '../content/index.js';
13-
import { hasMdContentEntryTypeOverride } from '../content/index.js';
1413
import { AstroError, AstroErrorData, MarkdownError } from '../core/errors/index.js';
1514
import type { LogOptions } from '../core/logger/core.js';
1615
import { warn } from '../core/logger/core.js';
@@ -67,15 +66,6 @@ export default function markdown({ settings, logging }: AstroPluginOptions): Plu
6766
async load(id) {
6867
if (isMarkdownFile(id)) {
6968
const { fileId, fileUrl } = getFileInfo(id, settings.config);
70-
if (
71-
// Integrations can override the Markdown parser for content collections.
72-
// If an override is present, skip this file.
73-
fileId.startsWith(getContentPaths(settings.config).contentDir.pathname) &&
74-
hasMdContentEntryTypeOverride(settings)
75-
) {
76-
return;
77-
}
78-
7969
const rawFile = await fs.promises.readFile(fileId, 'utf-8');
8070
const raw = safeMatter(rawFile, id);
8171
const renderResult = await renderMarkdown(raw.content, {

packages/integrations/markdoc/src/index.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ import { parseFrontmatter } from './utils.js';
66
import { fileURLToPath } from 'node:url';
77
import fs from 'node:fs';
88

9-
const DEFAULT_MARKDOC_EXTS = ['.mdoc', '.md'];
10-
119
export default function markdoc(): AstroIntegration {
1210
return {
1311
name: '@astrojs/markdoc',
1412
hooks: {
1513
'astro:config:setup': async ({ updateConfig, config, addContentEntryType, command }: any) => {
1614
const contentEntryType = {
17-
name: 'astro:markdoc',
18-
extensions: DEFAULT_MARKDOC_EXTS,
15+
extensions: ['.mdoc'],
1916
async getEntryInfo({ fileUrl, contents }: { fileUrl: URL; contents: string }) {
2017
const parsed = parseFrontmatter(contents, fileURLToPath(fileUrl));
2118
return {
@@ -37,7 +34,7 @@ export default function markdoc(): AstroIntegration {
3734
{
3835
name: '@astrojs/markdoc',
3936
async transform(code, id) {
40-
if (!DEFAULT_MARKDOC_EXTS.some((ext) => id.endsWith(ext))) return;
37+
if (!id.endsWith('.mdoc')) return;
4138
return `import { jsx as h } from 'astro/jsx-runtime';\nimport { Markdoc } from '@astrojs/markdoc';\nimport { Renderer } from '@astrojs/markdoc/components';\nexport const body = ${JSON.stringify(
4239
code
4340
)};\nexport function getParsed() { return Markdoc.parse(body); }\nexport function getTransformed(inlineConfig) { return Markdoc.transform(getParsed(), inlineConfig) }\nexport async function Content ({ config, components }) { return h(Renderer, { content: getTransformed(config), components }); }\nContent[Symbol.for('astro.needsHeadRendering')] = true;`;

packages/integrations/markdoc/template/content-module-types.d.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@ declare module 'astro:content' {
99
}): Record<string, any>;
1010
};
1111

12-
type RenderResult = Promise<{
13-
Content(props: {
14-
config?: import('@astrojs/markdoc').MarkdocConfig;
15-
components?: Record<string, ComponentRenderer>;
16-
}): import('astro').MarkdownInstance<{}>['Content'];
17-
}>;
18-
1912
interface Render {
20-
'.md': RenderResult;
21-
'.mdoc': RenderResult;
13+
'.mdoc': Promise<{
14+
Content(props: {
15+
config?: import('@astrojs/markdoc').MarkdocConfig;
16+
components?: Record<string, ComponentRenderer>;
17+
}): import('astro').MarkdownInstance<{}>['Content'];
18+
}>;
2219
}
2320
}

packages/integrations/mdx/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
3535
command,
3636
}: any) => {
3737
const contentEntryType = {
38-
name: 'astro:mdx',
3938
extensions: ['.mdx'],
4039
async getEntryInfo({ fileUrl, contents }: { fileUrl: URL; contents: string }) {
4140
const parsed = parseFrontmatter(contents, fileURLToPath(fileUrl));

0 commit comments

Comments
 (0)