Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

1574242600/astro-rehype-excerpt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Astro-rehype-excerpt

Astro rehype transformer plugin for extracting an excerpt. similar to WordPress's excerpt functionality.

Not recommended. Remark and rehype plugins access the raw Markdown or MDX document frontmatter. This means that remarkPluginFrontmatter frontmatter is handled separately from your type-safe schema, and will not reflect any changes or defaults applied through Astro. Use at your own risk!
from https://docs.astro.build/en/guides/content-collections/#modifying-frontmatter-with-remark

Install

npm install https://github.com/1574242600/astro-rehype-excerpt

Use

// astro.config.mjs
import { rehypeExcerpt } from 'astro-rehype-excerpt'

export default defineConfig({
    markdown: {
        rehypePlugins: [rehypeExcerpt]
    }
})

Plugin options

interface options {
    // Specifies the excerpt comment identifier to look for.
    // Default: excerpt, more, preview, or teaser
    identifier?: string 
}

Astro.glob or import

---
import * as myPost from 'post.md'
---

<div set:html={myPost.frontmatter.excerpt.html} />

Collection

---
import { getEntry } from 'astro:content'
const blogPost = await getEntry('blog', 'post-1')
const { remarkPluginFrontmatter } = await blogPost.render()
---

<div set:html={remarkPluginFrontmatter.excerpt.html} />

example

# Title
Paragraph 1.
Paragraph 2.
<!--excerpt-->
Paragraph 3.
Paragraph 4.

html

<h1>Title</h1>
<p>Paragraph 1.</p>
<p>Paragraph 2.</p>

text

Title Paragraph 1. Paragraph 2.

Thanks.

manovotny/remark-excerpt
...

LICENSE

MIT

About

Astro rehype transformer plugin for extracting an excerpt. similar to WordPress's excerpt functionality.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published