starlight-blog
starlight-blog copied to clipboard
Implement basic `reading time` functionality
Describe the pull request
Add reading time after discussion #74 was left open for 3 months.
How
-
new Starlight component override:
PageTitle.astro -
add property to
config.ts(showReadingTime: generall set if readingTime should be calculated) and schema (readingTime: manually override calculated readingTime or show specific readingTime ifshowReadingTimeis deactivated) -
additional libs file (
readingTime.ts) -
change the
MarkdownContent.astroandMetadata.astrofiles and createPageTitle.astrofile -
If readingTime is too large it shows in hours and minutes
-
write tests for
libs/readingTime.ts
Screenshots
manual override:
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| starlight-blog-docs | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Dec 23, 2024 11:12am |
Deployment failed with the following error:
The provided GitHub repository does not contain the requested branch or commit reference. Please ensure the repository is not empty.
Okay, I'm sorry for the many commits (Vercel build minutes) HiDeoo, but I think I got the most features covered from #74
Some thinks to note down before merging:
-
there is currently the inconsistency that the reading time has a space between the number and string:
2 minor1 hbut when there are multiple numbers, like here:1h 9minI chose not to include the space because it looks weird for me, but this is something we need to discuss. I just saw that @julien-deramond just has the spaces in every case: -
~there are currently NO TESTS written by me because 1. I'm not that familiar with writing test currently (Im working on it) and 2. I dont know how you, HiDeoo, want to handle the test scenarios. I looked into the test folder and wasn't sure if I should create a new file under
/basicsor just some random test inutilsso I leave it up to you...~ I have written tests for thelibs/readingTime.ts -
the documentation is expandable (basics are covered but nothing too advanced)
-
when Starlight merges https://github.com/withastro/starlight/pull/2390 we'll probably have to revised all overridden components and see which we can avoid to override
⚠️ No Changeset found
Latest commit: 440d7a9f81bdfb1e8bb0aa7397a94e027a029be2
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
It's probably better to wait with this feature until the route data is moved to Astro.locals in Starlight. After the refactoring of the plugin, it's easier to implement this feature...
Thanks for kicking off the feature.
As discussed, I'm closing this PR in favor of #155 which once finished would provide a similar feature with a more robust implementation as this one was not considering markup or internationalization (splitting around does not work for languages with different word boundaries).