Skip to content

Commit

Permalink
Generate alternate links for languages
Browse files Browse the repository at this point in the history
  • Loading branch information
starsep committed Feb 8, 2024
1 parent 92d0cde commit a245b22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/build_every_lang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ for lang in public/locales/*; do
continue
fi
export VITE_DEFAULT_LANG=$lang
export VITE_BASE_URL="/$lang/"
echo "Generating $lang"
npm run build -- --outDir "build/$lang" --base "/$lang"
done
14 changes: 14 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ const htmlPlugin = async (env) => {
...translationsEn,
...translationsTarget,
};
const baseUrl = env.VITE_BASE_URL ?? "";
const canonicalLinks = `<link href="${env.VITE_BACKEND_API_URL}${baseUrl}" rel="canonical" />`;
const alternateLinks = Object.keys(languages)
.map(
(lang) =>
`\t<link href="${env.VITE_BACKEND_API_URL}/${lang}/" rel="alternate" hreflang="${lang}" />`,
)
.join("\n");
const defaultAlternateLink = `\t<link href="${env.VITE_BACKEND_API_URL}/" rel="alternate" hreflang="x-default" />`;
const seoLinks = `${canonicalLinks}\n${alternateLinks}\n${defaultAlternateLink}`;
return {
name: "html-transform",
transformIndexHtml(html) {
Expand All @@ -32,6 +42,10 @@ const htmlPlugin = async (env) => {
.replace(
/<meta content="(.*?)" name="description">/,
`<meta content="${meta_description}" name="description">`,
)
.replace(
/<link href="https:\/\/openaedmap.org" rel="canonical" \/>/,
seoLinks,
);
},
};
Expand Down

0 comments on commit a245b22

Please sign in to comment.