Skip to content
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

Markdoc - remove $entry variable #7244

Merged
merged 9 commits into from May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/metal-bugs-drive.md
@@ -0,0 +1,17 @@
---
'@astrojs/markdoc': minor
'astro': patch
---

Remove the auto-generated `$entry` variable for Markdoc entries. To access frontmatter as a variable, you can pass `entry.data` as a prop where you render your content:

```astro
---
import { getEntry } from 'astro:content';

const entry = await getEntry('docs', 'why-markdoc');
const { Content } = await entry.render();
---

<Content frontmatter={entry.data} />
```
3 changes: 2 additions & 1 deletion packages/astro/src/@types/astro.ts
Expand Up @@ -1270,8 +1270,9 @@ export interface ContentEntryType {
getRenderModule?(
this: rollup.PluginContext,
params: {
contents: string;
fileUrl: URL;
viteId: string;
entry: ContentEntryModule;
}
): rollup.LoadResult | Promise<rollup.LoadResult>;
contentModuleTypes?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/content/types-generator.ts
Expand Up @@ -11,7 +11,7 @@ import { info, warn, type LogOptions } from '../core/logger/core.js';
import { isRelativePath } from '../core/path.js';
import { CONTENT_TYPES_FILE, VIRTUAL_MODULE_ID } from './consts.js';
import {
getContentEntryConfigByExtMap,
getEntryConfigByExtMap,
getContentEntryIdAndSlug,
getContentPaths,
getDataEntryExts,
Expand Down Expand Up @@ -74,7 +74,7 @@ export async function createContentTypesGenerator({
}: CreateContentGeneratorParams) {
const collectionEntryMap: CollectionEntryMap = {};
const contentPaths = getContentPaths(settings.config, fs);
const contentEntryConfigByExt = getContentEntryConfigByExtMap(settings);
const contentEntryConfigByExt = getEntryConfigByExtMap(settings.contentEntryTypes);
const contentEntryExts = [...contentEntryConfigByExt.keys()];
const dataEntryExts = getDataEntryExts(settings);

Expand Down
9 changes: 6 additions & 3 deletions packages/astro/src/content/utils.ts
Expand Up @@ -10,6 +10,7 @@ import type {
AstroConfig,
AstroSettings,
ContentEntryType,
DataEntryType,
ImageInputFormat,
} from '../@types/astro.js';
import { VALID_INPUT_FORMATS } from '../assets/consts.js';
Expand Down Expand Up @@ -172,9 +173,11 @@ export function getDataEntryExts(settings: Pick<AstroSettings, 'dataEntryTypes'>
return settings.dataEntryTypes.map((t) => t.extensions).flat();
}

export function getContentEntryConfigByExtMap(settings: Pick<AstroSettings, 'contentEntryTypes'>) {
const map: Map<string, ContentEntryType> = new Map();
for (const entryType of settings.contentEntryTypes) {
export function getEntryConfigByExtMap<TEntryType extends ContentEntryType | DataEntryType>(
entryTypes: TEntryType[]
): Map<string, TEntryType> {
const map: Map<string, TEntryType> = new Map();
for (const entryType of entryTypes) {
for (const ext of entryType.extensions) {
map.set(ext, entryType);
}
Expand Down