upgrade to astro v7

This commit is contained in:
2026-08-22 07:59:49 -04:00
parent 8799733474
commit 0ded527b40
5 changed files with 511 additions and 358 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ const posts = await Promise.all(entries.map(async entry => {
<ul>
{posts.map( (p, idx) =>
<li>
{idx > 0 && <hr></hr>}
{idx > 0 && <hr />}
<h2>
<a href={`/${p.id}`} data-astro-prefetch>
{p.data.title}
+16 -32
View File
@@ -1,33 +1,17 @@
import type { Root, Paragraph, PhrasingContent } from 'mdast';
import type { VFile } from 'vfile';
import { visit } from 'unist-util-visit';
import { toString } from 'mdast-util-to-string';
import { defineMdastPlugin } from 'satteri';
export function remarkDescription() {
return (tree: Root, vfile: VFile) => {
let description: string | null = null;
visit(tree, 'paragraph', (node: Paragraph) => {
if (description !== null) return;
description = summarize(node);
});
// Astro exposes this as `remarkPluginFrontmatter` from render()
const astro = (vfile.data.astro ??= { frontmatter: {} }) as { frontmatter: Record<string, unknown> };
astro.frontmatter.description = description;
};
}
/**
* Convert a paragraph node to a plain-text string, stripping any
* MDX JSX elements (e.g. <Sidenote>) so their content doesn't
* leak into the summary.
*/
function summarize(par: Paragraph): string {
const filtered = par.children.filter(
(child: PhrasingContent) => !(child.type as string).startsWith('mdxJsx')
);
return toString({ type: 'paragraph', children: filtered });
}
export const description = defineMdastPlugin({
name: 'description',
paragraph(node, ctx) {
if (ctx.data.astro !== undefined) {
const astro = ctx.data.astro as { frontmatter: Record<string, unknown> };
if (astro.frontmatter.description === undefined) {
const filteredText = node.children
.filter(c => c.type !== 'mdxJsxTextElement')
.map(c => ctx.textContent(c))
.join('');
astro.frontmatter.description = filteredText;
}
}
},
})