upgrade to astro v7
This commit is contained in:
+6
-3
@@ -1,7 +1,8 @@
|
|||||||
import { defineConfig } from "astro/config";
|
import { defineConfig } from "astro/config";
|
||||||
import mdx from '@astrojs/mdx';
|
import mdx from '@astrojs/mdx';
|
||||||
import vue from '@astrojs/vue';
|
import vue from '@astrojs/vue';
|
||||||
import { remarkDescription } from './src/plugins.ts';
|
import { satteri } from '@astrojs/markdown-satteri';
|
||||||
|
import { description } from './src/plugins.ts';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
integrations: [
|
integrations: [
|
||||||
@@ -10,12 +11,14 @@ export default defineConfig({
|
|||||||
],
|
],
|
||||||
prefetch: true,
|
prefetch: true,
|
||||||
markdown: {
|
markdown: {
|
||||||
remarkPlugins: [remarkDescription],
|
processor: satteri({
|
||||||
|
mdastPlugins: [description],
|
||||||
|
}),
|
||||||
shikiConfig: {
|
shikiConfig: {
|
||||||
themes: {
|
themes: {
|
||||||
light: 'dracula',
|
light: 'dracula',
|
||||||
dark: 'dark-plus',
|
dark: 'dark-plus',
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
+6
-6
@@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@astrojs/check": "^0.9.6",
|
"@astrojs/check": "0.9.10",
|
||||||
"@astrojs/mdx": "^4.3.13",
|
"@astrojs/mdx": "7.0.7",
|
||||||
"@astrojs/rss": "^4.0.15",
|
"@astrojs/rss": "4.0.19",
|
||||||
"@astrojs/sitemap": "^3.7.0",
|
"@astrojs/sitemap": "3.7.3",
|
||||||
"@astrojs/vue": "^5.1.4",
|
"@astrojs/vue": "7.0.2",
|
||||||
"@fontsource-variable/baskervville": "^5.2.3",
|
"@fontsource-variable/baskervville": "^5.2.3",
|
||||||
"@fontsource-variable/baskervville-sc": "^5.2.3",
|
"@fontsource-variable/baskervville-sc": "^5.2.3",
|
||||||
"@fontsource-variable/figtree": "^5.2.10",
|
"@fontsource-variable/figtree": "^5.2.10",
|
||||||
"@fontsource-variable/fira-code": "^5.2.7",
|
"@fontsource-variable/fira-code": "^5.2.7",
|
||||||
"astro": "^5.18.0",
|
"astro": "7.2.4",
|
||||||
"sharp": "^0.34.5"
|
"sharp": "^0.34.5"
|
||||||
},
|
},
|
||||||
"name": "astro",
|
"name": "astro",
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const posts = await Promise.all(entries.map(async entry => {
|
|||||||
<ul>
|
<ul>
|
||||||
{posts.map( (p, idx) =>
|
{posts.map( (p, idx) =>
|
||||||
<li>
|
<li>
|
||||||
{idx > 0 && <hr></hr>}
|
{idx > 0 && <hr />}
|
||||||
<h2>
|
<h2>
|
||||||
<a href={`/${p.id}`} data-astro-prefetch>
|
<a href={`/${p.id}`} data-astro-prefetch>
|
||||||
{p.data.title}
|
{p.data.title}
|
||||||
|
|||||||
+16
-32
@@ -1,33 +1,17 @@
|
|||||||
import type { Root, Paragraph, PhrasingContent } from 'mdast';
|
import { defineMdastPlugin } from 'satteri';
|
||||||
import type { VFile } from 'vfile';
|
|
||||||
import { visit } from 'unist-util-visit';
|
|
||||||
import { toString } from 'mdast-util-to-string';
|
|
||||||
|
|
||||||
|
export const description = defineMdastPlugin({
|
||||||
export function remarkDescription() {
|
name: 'description',
|
||||||
return (tree: Root, vfile: VFile) => {
|
paragraph(node, ctx) {
|
||||||
let description: string | null = null;
|
if (ctx.data.astro !== undefined) {
|
||||||
|
const astro = ctx.data.astro as { frontmatter: Record<string, unknown> };
|
||||||
visit(tree, 'paragraph', (node: Paragraph) => {
|
if (astro.frontmatter.description === undefined) {
|
||||||
if (description !== null) return;
|
const filteredText = node.children
|
||||||
description = summarize(node);
|
.filter(c => c.type !== 'mdxJsxTextElement')
|
||||||
});
|
.map(c => ctx.textContent(c))
|
||||||
|
.join('');
|
||||||
// Astro exposes this as `remarkPluginFrontmatter` from render()
|
astro.frontmatter.description = filteredText;
|
||||||
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 });
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user