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

feat: add support for required lang param #29

Closed
wants to merge 1 commit into from
Closed

feat: add support for required lang param #29

wants to merge 1 commit into from

Conversation

Epoxide
Copy link

@Epoxide Epoxide commented Jun 17, 2024

Currently only [[lang]] as an optional param is permitted. This PR makes it possible to use [lang] as a required param as well.

Example:

Routes:

/[lang]
/[lang]/about

Config:

return await sitemap.response({
  origin: 'https://www.example.com',
  page: params.page,
  lang: {
    default: 'en',
    alternates: ['sv', 'nb', 'da'],
  },
})

Output:

<url>
<loc>https://www.example.com/en</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/en"/>
<xhtml:link rel="alternate" hreflang="sv" href="https://www.example.com/sv"/>
<xhtml:link rel="alternate" hreflang="nb" href="https://www.example.com/nb"/>
<xhtml:link rel="alternate" hreflang="da" href="https://www.example.com/da"/>
</url>
<url>
<loc>https://www.example.com/sv</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/en"/>
<xhtml:link rel="alternate" hreflang="sv" href="https://www.example.com/sv"/>
<xhtml:link rel="alternate" hreflang="nb" href="https://www.example.com/nb"/>
<xhtml:link rel="alternate" hreflang="da" href="https://www.example.com/da"/>
</url>
<url>
<loc>https://www.example.com/nb</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/en"/>
<xhtml:link rel="alternate" hreflang="sv" href="https://www.example.com/sv"/>
<xhtml:link rel="alternate" hreflang="nb" href="https://www.example.com/nb"/>
<xhtml:link rel="alternate" hreflang="da" href="https://www.example.com/da"/>
</url>
<url>
<loc>https://www.example.com/da</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/en"/>
<xhtml:link rel="alternate" hreflang="sv" href="https://www.example.com/sv"/>
<xhtml:link rel="alternate" hreflang="nb" href="https://www.example.com/nb"/>
<xhtml:link rel="alternate" hreflang="da" href="https://www.example.com/da"/>
</url>
<url>
<loc>https://www.example.com/en/about</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/en/about"/>
<xhtml:link rel="alternate" hreflang="sv" href="https://www.example.com/sv/about"/>
<xhtml:link rel="alternate" hreflang="nb" href="https://www.example.com/nb/about"/>
<xhtml:link rel="alternate" hreflang="da" href="https://www.example.com/da/about"/>
</url>
<url>
<loc>https://www.example.com/sv/about</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/en/about"/>
<xhtml:link rel="alternate" hreflang="sv" href="https://www.example.com/sv/about"/>
<xhtml:link rel="alternate" hreflang="nb" href="https://www.example.com/nb/about"/>
<xhtml:link rel="alternate" hreflang="da" href="https://www.example.com/da/about"/>
</url>
<url>
<loc>https://www.example.com/nb/about</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/en/about"/>
<xhtml:link rel="alternate" hreflang="sv" href="https://www.example.com/sv/about"/>
<xhtml:link rel="alternate" hreflang="nb" href="https://www.example.com/nb/about"/>
<xhtml:link rel="alternate" hreflang="da" href="https://www.example.com/da/about"/>
</url>
<url>
<loc>https://www.example.com/da/about</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/en/about"/>
<xhtml:link rel="alternate" hreflang="sv" href="https://www.example.com/sv/about"/>
<xhtml:link rel="alternate" hreflang="nb" href="https://www.example.com/nb/about"/>
<xhtml:link rel="alternate" hreflang="da" href="https://www.example.com/da/about"/>
</url>

@jasongitmail
Copy link
Owner

Awesome. Thanks!

The related test cases should be updated too before merging. If you'd be up to push commits for that, that'd be great (and faster to merge) or I can take a look at it too.

@Epoxide
Copy link
Author

Epoxide commented Jun 17, 2024

Awesome. Thanks!

The related test cases should be updated too before merging. If you'd be up to push commits for that, that'd be great (and faster to merge) or I can take a look at it too.

I can take a look first 👍

@Epoxide
Copy link
Author

Epoxide commented Jun 18, 2024

Actually I'm not quite sure how to do the routes with both [[lang]] and [lang] at the root level without a conflict. Any ideas?

Also I skipped editing the docs in the README as I'm not sure about any other i18n library as I'm not running any third party lib. If you could take a look at that too would be great.

@jasongitmail
Copy link
Owner

jasongitmail commented Jul 2, 2024

Appreciate you opening this. Closing now that we're focusing on the PR that supports param matchers too. Feel free to jump in on that thread to collaborate on the review. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants