Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create readingTime frontmatter #75

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/content/docs/blog/funda-pro.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Funda pro
date: 2020-02-02
excerpt: Aliquam erat volutpat. Sed non iaculis sem. Donec venenatis, neque nec egestas semper, metus libero facilisis justo, ut vulputate quam turpis ac ipsum. Cras ex lectus, accumsan vel lorem maximus, varius ornare sapien. Donec feugiat laoreet arcu, rhoncus blandit nisl varius non. Suspendisse congue lobortis lectus quis mattis. Suspendisse et.
authors: hideoo
readingTime: 2
---

## Temptata sata tamen
Expand Down
1 change: 1 addition & 0 deletions docs/src/content/docs/blog/mihi-terrae-somnia.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: Mihi terrae somnia
date: 2020-11-11
excerpt: Quisque imperdiet at lorem a fermentum. Aliquam ut porta lorem. Morbi faucibus mauris enim, a venenatis ligula hendrerit nec. Quisque elementum est ut urna vulputate ornare. Praesent eget sapien ut libero euismod ornare. Pellentesque ultricies dolor id semper porttitor. Sed vehicula nulla lectus, ut finibus dui lobortis sit amet. Nunc nec vehicula ligula. Phasellus a lacus lorem. Phasellus non ex ultrices, consectetur metus eget, lacinia magna. Cras porta lacus ligula.
readingTime: 4
---

## Quodque manus
Expand Down
1 change: 1 addition & 0 deletions docs/src/content/docs/blog/sequantur-quaeritis-tandem.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ excerpt: Donec eget **vestibulum** leo. Curabitur vel pretium nulla, in bibendum
tags:
- Starlight
- Demo
readingTime: 3
---

## Et recingunt etiam
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tags:
- WIP
authors:
- hideoo
readingTime: 4
---

## Rudibusque positos tegitur qua pugnat Lucifer habitatis
Expand Down
1 change: 1 addition & 0 deletions docs/src/content/docs/blog/vario-nunc-polo.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ authors:
cover:
alt: A cover
image: ../../../assets/cover.png
readingTime: 4
---

### Canes plura palmas eodem huc scelerate spectat
Expand Down
16 changes: 16 additions & 0 deletions docs/src/content/docs/guides/frontmatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,19 @@ type CoverConfig =
light: string
}
```

### `readingTime`

**Type:** `number`

Give the reader an idea on how long it will take them to read the whole blog post. This frontmatter is a number which represents the **minutes** for reading the post.

```md
---
readingTime: 3
---
```

:::note
The `readingTime` is measured in minutes!
:::
7 changes: 7 additions & 0 deletions packages/starlight-blog/components/Metadata.astro
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ const hasAuthors = authors.length > 0

<div class="metadata not-content">
<div class="dates">
{
entry.data.readingTime && (
<span class="reading-time">
{entry.data.readingTime} min read <span style="margin-inline: 0.25rem;">•</span>
</span>
)
}
<time datetime={entry.data.date.toISOString()}>
{date}
</time>
Expand Down
1 change: 1 addition & 0 deletions packages/starlight-blog/libs/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ interface StarlightBlogEntryMetadata {
authors: StarlightBlogAuthor[]
date: string
lastUpdated: string | undefined
readingTime: number
}

interface StarlightBlogStaticProps {
Expand Down
5 changes: 5 additions & 0 deletions packages/starlight-blog/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export const blogEntrySchema = ({ image }: SchemaContext) =>
}),
])
.optional(),

/**
* The reading time of the blog post in minutes.
*/
readingTime: z.number().optional(),
})

export function blogSchema(context: SchemaContext) {
Expand Down
Loading