mirror of
https://codeberg.org/HPCesia/AstralHalo.git
synced 2025-04-08 17:34:27 +08:00
feat: auto generate post description
This commit is contained in:
parent
438b4f5d8a
commit
2cc5107c7f
@ -1,6 +1,7 @@
|
||||
// @ts-check
|
||||
import { CDN } from './src/constants/cdn.mjs';
|
||||
import { rehypeWrapTables } from './src/plugins/rehype-wrap-tables.mjs';
|
||||
import { remarkExcerpt } from './src/plugins/remark-excerpt';
|
||||
import { remarkReadingTime } from './src/plugins/remark-reading-time.mjs';
|
||||
import { rehypeHeadingIds } from '@astrojs/markdown-remark';
|
||||
import sitemap from '@astrojs/sitemap';
|
||||
@ -36,6 +37,7 @@ export default defineConfig({
|
||||
remarkPlugins: [
|
||||
remarkMath,
|
||||
remarkReadingTime,
|
||||
remarkExcerpt,
|
||||
// @ts-expect-error - types are not up to date
|
||||
[
|
||||
remarkGithubBlockQuote,
|
||||
|
@ -19,9 +19,11 @@ export async function getStaticPaths() {
|
||||
|
||||
const { article } = Astro.props;
|
||||
const { Content, headings, remarkPluginFrontmatter } = await render(article);
|
||||
|
||||
const description = article.data.description || remarkPluginFrontmatter.excerpt;
|
||||
---
|
||||
|
||||
<GridLayout title={article.data.title} description={article.data.description}>
|
||||
<GridLayout title={article.data.title} description={description}>
|
||||
<Fragment slot="header-content">
|
||||
<PostInfo
|
||||
title={article.data.title}
|
||||
|
16
src/plugins/remark-excerpt.js
Normal file
16
src/plugins/remark-excerpt.js
Normal file
@ -0,0 +1,16 @@
|
||||
import { toString } from 'mdast-util-to-string'
|
||||
|
||||
/* Use the post's first paragraph as the excerpt */
|
||||
export function remarkExcerpt() {
|
||||
return (tree, { data }) => {
|
||||
let excerpt = ''
|
||||
for (let node of tree.children) {
|
||||
if (node.type !== 'paragraph') {
|
||||
continue
|
||||
}
|
||||
excerpt = toString(node)
|
||||
break
|
||||
}
|
||||
data.astro.frontmatter.excerpt = excerpt
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user