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

Added slug utility function #14

Closed

Conversation

guilty-p01nt3r
Copy link

I needed getUrlWithoutLocale and getLocale but for slugs instead of URL

@jlarmstrongiv
Copy link
Owner

jlarmstrongiv commented Jul 24, 2023

Sure, I thought the use-case would be with the built-in Astro url objects. But, supporting regular url paths would be good too. Rather than make three new functions, I think we can add support to the three existing functions:

  • getLocale
  • getUrlWithoutLocale
  • getLocaleUrlPrefix

After all, we’re just pulling the url.pathname string from the url anyway.

However, I would like to have strong type safety with these functions and strings. If I pass in a constant of /en/about to getLocale, I should get the type en back, not the type string.

It should support the regular URL object, as well as paths like:

  • /es/about
  • es/about
  • /about
  • about
  • ../about
  • /enigma (starts with a locale like /en)
  • enigma

When you’ve updated your PR, I’ll be glad to review and merge it 😄

@jlarmstrongiv
Copy link
Owner

Added in 0.3.5

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