Compare commits

...

1 commit

Author SHA1 Message Date
bholmesdev
72b98a5868 wip: attempt ssr transform cache? failed 2023-06-21 14:06:30 -04:00
10 changed files with 38 additions and 49 deletions

View file

@ -1,14 +1,10 @@
import { defineMarkdocConfig } from '@astrojs/markdoc/config';
import Aside from './src/components/Aside.astro';
import Ben from './src/components/Ben.astro';
export default defineMarkdocConfig({
tags: {
aside: {
render: Aside,
attributes: {
type: { type: String },
title: { type: String },
},
ben: {
render: Ben,
},
},
});

View file

@ -0,0 +1,6 @@
---
import { getEntry } from 'astro:content';
const author = await getEntry('docs', 'ben');
---
<h2>{author?.data.name}</h2>

View file

@ -0,0 +1,3 @@
{
"name": "Ben"
}

View file

@ -0,0 +1,3 @@
{
"name": "Ben"
}

View file

@ -0,0 +1,3 @@
---
name: Ben 👋
---

View file

@ -2,38 +2,4 @@
title: Welcome to Markdoc 👋
---
This simple starter showcases Markdoc with Content Collections. All Markdoc features are supported, including this nifty built-in `{% table %}` tag:
{% table %}
* Feature
* Supported
---
* `.mdoc` in Content Collections
* ✅
---
* Markdoc transform configuration
* ✅
---
* Astro components
* ✅
{% /table %}
{% aside title="Code Challenge" type="tip" %}
Reveal the secret message below by adding `revealSecret` to your list of Markdoc variables.
_Hint: Try passing as a prop to the `<Content />` component in the `src/pages/index.astro` file._
{% if $revealSecret %}
Maybe the real secret was the Rick Rolls we shared along the way.
![Rick Astley dancing](https://media.tenor.com/x8v1oNUOmg4AAAAM/rickroll-roll.gif)
{% /if %}
{% /aside %}
Check out [the `@astrojs/markdoc` integration][astro-markdoc] for complete documentation and usage examples.
[astro-markdoc]: https://docs.astro.build/en/guides/integrations-guide/markdoc/
{% ben /%}

View file

@ -1,8 +1,8 @@
---
import { getEntryBySlug } from 'astro:content';
import { getEntry } from 'astro:content';
import Layout from '../layouts/Layout.astro';
const intro = await getEntryBySlug('docs', 'intro');
const intro = await getEntry('docs', 'intro');
const { Content } = await intro.render();
---

View file

@ -41,13 +41,17 @@ function createGlobLookup(glob) {
const filePath = lookupMap[collection]?.entries[lookupId];
if (!filePath) return undefined;
return glob[collection][filePath];
const res = glob[collection][filePath];
console.log('res', res);
return res;
};
}
const renderEntryGlob = import.meta.glob('@@RENDER_ENTRY_GLOB_PATH@@', {
query: { astroRenderContent: true },
});
const renderEntryGlob = {
'/src/content/docs/intro.mdoc': () => import('/src/content/docs/intro.mdoc'),
'/src/content/docs/ben.mdoc': () => import('/src/content/docs/ben.mdoc'),
};
console.log('glob', renderEntryGlob);
const collectionToRenderEntryMap = createCollectionToGlobResultMap({
globResult: renderEntryGlob,
contentDir,

View file

@ -268,6 +268,7 @@ async function render({
if (typeof renderEntryImport !== 'function') throw UnexpectedRenderError;
const baseMod = await renderEntryImport();
console.log('baseMod', baseMod);
if (baseMod == null || typeof baseMod !== 'object') throw UnexpectedRenderError;
const { default: defaultMod } = baseMod;

View file

@ -14,6 +14,8 @@ const fileExtensionsToSSR = new Set(['.astro', '.mdoc', ...SUPPORTED_MARKDOWN_FI
const STRIP_QUERY_PARAMS_REGEX = /\?.*$/;
const ASTRO_PROPAGATED_ASSET_REGEX = /\?astroPropagatedAssets/;
const mwho = new Set<string>();
/** recursively crawl the module graph to get all style files imported by parent id */
export async function* crawlGraph(
loader: ModuleLoader,
@ -70,9 +72,14 @@ export async function* crawlGraph(
if (
isFileTypeNeedingSSR &&
// Should not SSR a module with ?astroPropagatedAssets
!isPropagationStoppingPoint
!isPropagationStoppingPoint &&
!mwho.has(importedModule.id)
) {
const mod = loader.getModuleById(importedModule.id);
if (importedModule.id.includes('.mdoc')) {
console.log('mdoc', importedModule.id);
mwho.add(importedModule.id);
}
if (!mod?.ssrModule) {
try {
await loader.import(importedModule.id);