starlight-blog
starlight-blog copied to clipboard
Auto excerpt - instead of frontmatter
Is your feature request related to a problem?
I'm always a little frustrated having to write things twice, the blog post, and then the excerpt. It seems like a lot of duplicated work.
Describe the solution you'd like
On other blogging platforms (docusaurus, et. al.) you define a place in the article using some kind of separator, and the excerpt/preview truncates at the spot you define. This means you don't have to have an excerpt / summary / preview frontmatter option, you just add the truncation point wherever you'd like.
Describe alternatives you've considered
Having ChatGPT write me a summary because I'm tired of writing... haha.
Additional Context
Here's from the docusaurus blog documentation
---
title: Welcome Docusaurus
description: This is my first post on Docusaurus.
slug: welcome-docusaurus-v2
authors:
- name: Joel Marcey
title: Co-creator of Docusaurus 1
url: https://github.com/JoelMarcey
image_url: https://github.com/JoelMarcey.png
socials:
x: joelmarcey
github: JoelMarcey
- name: Sébastien Lorber
title: Docusaurus maintainer
url: https://sebastienlorber.com
image_url: https://github.com/slorber.png
socials:
x: sebastienlorber
github: slorber
tags: [hello, docusaurus-v2]
image: https://i.imgur.com/mErPwqL.png
hide_table_of_contents: false
---
Welcome to this blog. This blog is created with [**Docusaurus 2**](https://docusaurus.io/).
<!-- truncate -->
This is my first post on Docusaurus 2.
A whole bunch of exploration to follow.
Thanks for the feedback.
Interesting idea, not something I'm familiar with so I have a few extra questions:
- You want an excerpt identical to the beginning of your content but not the entire post itself (which is the default if no
excerptis provided)? - When using such feature, the blog post list truncate at the separator if I'm correct. But when visiting the blog post itself, does this view include the content before the excerpt separator too? Or is it truncated too?
Not something I have done before, but could be worth exploring the feasibility of adding a feature like this.
Thanks for getting back to me so quickly!
- You want an excerpt identical to the beginning of your content but not the entire post itself (which is the default if no
excerptis provided)?
- Exactly. Basically whatever precedes the truncate element. This means the "all posts" page basically just has the beginning of each article.
- Do you feel this is a mutually exclusive goal to the excerpt front-matter? I suppose the benefit of the current way allows the author to write some kind of summary, instead of just a copy/paste of a portion of the article. I suppose the answer to this question depends on how people are using it.
- When using such feature, the blog post list truncate at the separator if I'm correct. But when visiting the blog post itself, does this view include the content before the excerpt separator too? Or is it truncated too?
- Yes! So when visiting the blog post itself, the truncate command is ignored and the entire post is rendered. The truncate element just defines where the "preview" on the all posts timeline stops rendering.
Not something I have done before, but could be worth exploring the feasibility of adding a feature like this.
- I'm happy to contribute however I can, if you feel like this is something you'd like to move forward with it.
Thanks for the follow-up, super helpful.
Do you feel this is a mutually exclusive goal to the excerpt front-matter?
This is of course a super early thought, but my current thinking may be to use the following behavior:
- If
excerptis specified in the frontmatter, use that as the excerpt. - If not and
whatever_excerpt_separatoris used in the content, use that to split the content and use the first part as the excerpt. - If neither is specified, use the entire content as the excerpt like it is now.
The default current behavior would not change and user could opt-in to use or not the whatever_excerpt_separator in the content.
I'd like to think a bit more about it obviously, maybe research what other blog engines do, play a bit with it to see how it could work across all content types supported by Starlight, etc. but so far, I don't see any obvious blockers to this idea.
Just released version 0.22.0 which adds support for excerpt delimiters.
I've also published a new guide to recap all possible ways to have excerpts in your blog posts, including the new delimiters feature.
Basically, in Markdown files, you can now use the following syntax to define an excerpt:
Markdown content **included** in the blog post excerpt.
<!-- excerpt -->
Markdown content **not included** in the blog post excerpt.
And in MDX files, you can use:
MDX content **included** in the blog post excerpt.
{/* excerpt */}
MDX content **not included** in the blog post excerpt.