mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-17 12:01:33 +02:00
test: add plugins
This commit is contained in:
parent
4341dab741
commit
9e9cdcb206
8 changed files with 257 additions and 4 deletions
26
src/plugins/remark-excerpt.ts
Normal file
26
src/plugins/remark-excerpt.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import type { Root } from 'mdast'
|
||||
import { toString } from 'mdast-util-to-string'
|
||||
|
||||
interface AstroData {
|
||||
data: {
|
||||
astro: {
|
||||
frontmatter: {
|
||||
excerpt: string
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function remarkExcerpt() {
|
||||
return (tree: Root, file: AstroData) => {
|
||||
let excerpt = ''
|
||||
for (const node of tree.children) {
|
||||
if (node.type !== 'paragraph') {
|
||||
continue
|
||||
}
|
||||
excerpt = toString(node)
|
||||
break
|
||||
}
|
||||
file.data.astro.frontmatter.excerpt = excerpt
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue