refactor: move rendering to util

This commit is contained in:
bholmesdev 2023-02-16 14:14:49 -05:00
parent fd432e6752
commit c1ca780e20
6 changed files with 79 additions and 27 deletions

View file

@ -1,15 +1,17 @@
{
"name": "md",
"name": "@performance/md",
"version": "1.0.0",
"description": "",
"main": "index.js",
"private": true,
"scripts": {
"build": "astro build --perf"
},
"keywords": [],
"author": "",
"license": "ISC",
"license": "unlicensed",
"dependencies": {
"@performance/utils": "^0.0.0",
"astro": "^2.0.12"
}
}

View file

@ -1,29 +1,8 @@
---
import { getCollection } from "astro:content";
import { getCollection } from 'astro:content';
import { RenderContent } from '@performance/utils';
const posts = await getCollection('posts');
const posts = await getCollection('generated');
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Md render test</title>
</head>
<body>
{
posts.map(async (entry) => {
const { Content } = await entry.render();
return (
<div>
<h1>{entry.data.title}</h1>
<p>{entry.data.description}</p>
<Content />
</div>
);
})
}
</body>
</html>
<RenderContent {posts} />

View file

@ -0,0 +1,31 @@
---
type Props = {
posts: any[];
}
const { posts } = Astro.props;
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Md render test</title>
</head>
<body>
{
posts.map(async (entry) => {
const { Content } = await entry.render();
return (
<div>
<h1>{entry.data.title}</h1>
<p>{entry.data.description}</p>
<Content />
</div>
);
})
}
</body>
</html>

View file

@ -0,0 +1,2 @@
// @ts-ignore
export { default as RenderContent } from './RenderContent.astro';

View file

@ -0,0 +1,17 @@
{
"name": "@performance/utils",
"version": "0.0.0",
"description": "",
"main": "index.js",
"type": "module",
"private": true,
"keywords": [],
"author": "",
"license": "unlicensed",
"devDependencies": {
"astro": "^2.0.12"
},
"exports": {
".": "./index.ts"
}
}

View file

@ -1106,10 +1106,31 @@ importers:
astro: link:../../..
vue: 3.2.47
packages/astro/performance:
specifiers: {}
packages/astro/performance/fixtures/md:
specifiers:
'@performance/utils': ^0.0.0
astro: ^2.0.12
dependencies:
'@performance/utils': link:../utils
astro: link:../../..
packages/astro/performance/fixtures/mdx:
specifiers:
'@astrojs/mdx': ^0.16.2
'@performance/utils': ^0.0.0
astro: ^2.0.12
dependencies:
'@astrojs/mdx': link:../../../../integrations/mdx
'@performance/utils': link:../utils
astro: link:../../..
packages/astro/performance/fixtures/utils:
specifiers:
astro: ^2.0.12
devDependencies:
astro: link:../../..
packages/astro/test/benchmark/simple: