Skip to content

Commit

Permalink
Markdoc - remove $entry variable (#7244)
Browse files Browse the repository at this point in the history
* refactor: remove entry prop from `getRenderModule()`

* refactor: remove `$entry` from markdoc

* test: update entry-prop -> variables test

* refactor: unify `getEntryConfigByExt`

* chore: clean up shared content / data get logic

* docs: update `$entry` recommendation

* chore: rename entry-prop -> variables

* chore: changeset

* chore: missed a spot
  • Loading branch information
bholmesdev committed May 30, 2023
1 parent c7897f2 commit bef3a75
Show file tree
Hide file tree
Showing 16 changed files with 217 additions and 257 deletions.
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

0 comments on commit bef3a75

Please sign in to comment.