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

Fix last updated dates for pages displaying fallback content #1044

Merged
merged 4 commits into from
Nov 7, 2023

Conversation

HiDeoo
Copy link
Member

@HiDeoo HiDeoo commented Nov 6, 2023

What kind of changes does this PR include?

  • Changes to Starlight code

Description

This pull request fixes the last updates dates for pages displaying fallback content by taking into account isFallback when generating the file path used with getFileCommitDate().

Preview:

  • A docs production fallback page with no last update date: link
  • The same page after this PR: link

Copy link

changeset-bot bot commented Nov 6, 2023

🦋 Changeset detected

Latest commit: 444b438

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Nov 6, 2023

Deploy Preview for astro-starlight ready!

Name Link
🔨 Latest commit 444b438
🔍 Latest deploy log https://app.netlify.com/sites/astro-starlight/deploys/654a0c96af733b0008142345
😎 Deploy Preview https://deploy-preview-1044--astro-starlight.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 92 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added the 🌟 core Changes to Starlight’s main package label Nov 6, 2023
Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for quickly picking this up @HiDeoo — and especially for adding some testing here. Will help us know if my suggestion actually works or not :-D

Comment on lines 71 to 72
const currentId = isFallback ? localizedId(id, config.defaultLocale.locale) : id;
const currentFilePath = fileURLToPath(new URL('src/content/docs/' + currentId, project.root));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think we can simplify it to this!

Suggested change
const currentId = isFallback ? localizedId(id, config.defaultLocale.locale) : id;
const currentFilePath = fileURLToPath(new URL('src/content/docs/' + currentId, project.root));
const currentFilePath = fileURLToPath(new URL('src/content/docs/' + entry.id, project.root));

PageProps includes a root-level id localized for the current page, but entry also includes the original id for the content being used.

@@ -66,9 +66,10 @@ function getToC({ entry, locale, headings }: PageProps) {
};
}

function getLastUpdated({ entry, id }: PageProps): Date | undefined {
function getLastUpdated({ entry, id, isFallback }: PageProps): Date | undefined {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then this is also simpler!

Suggested change
function getLastUpdated({ entry, id, isFallback }: PageProps): Date | undefined {
function getLastUpdated({ entry }: PageProps): Date | undefined {

@HiDeoo
Copy link
Member Author

HiDeoo commented Nov 7, 2023

Brilliant idea, did not think of that at all and it works perfectly. Thanks a lot!

I also slightly improved the test as I was taking a route and "faking" it to be a fallback one instead of just using a fallback route ^^ Not sure what I was thinking there.

Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @HiDeoo — looks great! Should be safe to merge whenever you like 🌟

@HiDeoo HiDeoo merged commit a5a9754 into withastro:main Nov 7, 2023
9 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 core Changes to Starlight’s main package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Last Updated fallback not working
2 participants