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: Added x-default hreflang tag for HeadHrefLangs component #159

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

Y-developer
Copy link

Describe your changes

I noticed that the HeadHrefLangs component in the astro-i18next package does not include the hreflang='x-default' tag. I added the hreflang='x-default' tag to the HeadHrefLangs component.

As a result of adding the hreflang='x-default' tag, I ran an audit using SEO Minion's Hreflang Checker before and after. The audit showed a difference in results.

hreflang_x-default

Fixes #158

Checklist

  • I have performed a self-review of my code
  • I have added thorough tests
  • I have updated the docs

@Y-developer Y-developer changed the title Added hreflang="x-default" tag for HeadHrefLangs component Added x-default hreflang tag for HeadHrefLangs component Apr 22, 2023
@Y-developer Y-developer changed the title Added x-default hreflang tag for HeadHrefLangs component Added x default hreflang tag for HeadHrefLangs component Apr 22, 2023
@Y-developer Y-developer changed the title Added x default hreflang tag for HeadHrefLangs component feat: Added x default hreflang tag for HeadHrefLangs component Apr 22, 2023
@Y-developer Y-developer changed the title feat: Added x default hreflang tag for HeadHrefLangs component feat: Added x-default hreflang tag for HeadHrefLangs component Apr 22, 2023
@@ -270,14 +270,32 @@ src
defaultLocale: "en",
locales: ["en", "fr", "es"],
routes: {
<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like there's a merge conflict there

Comment on lines +10 to +15
<Fragment>
<link
rel="alternate"
hreflang="x-default"
href={localizeUrl(currentUrl, defaultLanguage)}
/>
Copy link

@lwhiteley lwhiteley Nov 30, 2023

Choose a reason for hiding this comment

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

had the same issue but solved it in a different way to keep the render data driven

---
const supportedLanguages = i18next.languages || [];
const currentUrl = Astro.url.href;
const defaultLanguage = AstroI18next.config.defaultLocale;

const languageAlternatives = [
    { hrefLang: 'x-default', language: defaultLanguage }, 
    ...supportedLanguages.map((language) => ({ hrefLang: language, language }))
];

---

{
  languageAlternatives.map(({hrefLang, language}) => (
    <link
      rel="alternate"
      hreflang={hrefLang}
      href={localizeUrl(currentUrl, language)}
    />
  ))
}

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.

None yet

3 participants