starlight-blog icon indicating copy to clipboard operation
starlight-blog copied to clipboard

Implement basic `reading time` functionality

Open trueberryless opened this issue 1 year ago • 6 comments

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 if showReadingTime is deactivated)

  • additional libs file (readingTime.ts)

  • change the MarkdownContent.astro and Metadata.astro files and create PageTitle.astro file

  • If readingTime is too large it shows in hours and minutes

  • write tests for libs/readingTime.ts

Screenshots

image image

manual override: image

trueberryless avatar Nov 10 '24 18:11 trueberryless

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

vercel[bot] avatar Nov 10 '24 18:11 vercel[bot]

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.

vercel[bot] avatar Nov 10 '24 18:11 vercel[bot]

Okay, I'm sorry for the many commits (Vercel build minutes) HiDeoo, but I think I got the most features covered from #74

trueberryless avatar Nov 10 '24 18:11 trueberryless

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 min or 1 h but when there are multiple numbers, like here: 1h 9min I 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:

    image

  • ~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 /basics or just some random test in utils so I leave it up to you...~ I have written tests for the libs/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

trueberryless avatar Nov 10 '24 18:11 trueberryless

⚠️ 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

changeset-bot[bot] avatar Dec 23 '24 11:12 changeset-bot[bot]

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...

trueberryless avatar Dec 23 '24 11:12 trueberryless

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).

HiDeoo avatar May 28 '25 07:05 HiDeoo