Skip to content

Commit

Permalink
feat: Remove multilingual support seo (#1367)
Browse files Browse the repository at this point in the history
  • Loading branch information
oktapodia authored Oct 4, 2024
1 parent a83c0e9 commit 609ff01
Showing 1 changed file with 21 additions and 48 deletions.
69 changes: 21 additions & 48 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,35 @@ function withoutTrailingSlash(url: string) {
return url.endsWith('/') ? url.slice(0, -1) : url;
}

function generateAlternates(path: string) {
return {
languages: {
...locales.reduce((acc, loc) => {
const pages = {
...acc,
[loc]: withoutTrailingSlash(
`${process.env.NEXT_PUBLIC_SITE_URL}${loc !== 'en' ? `/${loc}` : ''}${path}`,
),
};

return pages;
}, {}),
},
};
}

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
// paths
const routes = pages.flatMap((route: SitemapPage) => {
return locales.map((locale) => {
return {
url: withoutTrailingSlash(
`${process.env.NEXT_PUBLIC_SITE_URL}${locale !== 'en' ? `/${locale}` : ''}${route.path}`,
),
lastModified: new Date().toISOString().split('T')[0],
changeFrequency: 'weekly' as ChangeFrequency,
alternates: generateAlternates(route.path),
priority: route.priority,
};
});
return {
url: withoutTrailingSlash(
`${process.env.NEXT_PUBLIC_SITE_URL}${route.path}`,
),
lastModified: new Date().toISOString().split('T')[0],
changeFrequency: 'weekly' as ChangeFrequency,
priority: route.priority,
};
});

// articles by slug
const articles = await getArticles().then(
(article: StrapiResponse<BlogArticleData>) => {
return locales.flatMap((locale) => {
return article.data.map((el) => {
return {
url: withoutTrailingSlash(
`${process.env.NEXT_PUBLIC_SITE_URL}${locale !== 'en' ? `/${locale}` : ''}${JUMPER_LEARN_PATH}${el.attributes.Slug}`,
),
lastModified: new Date(
el.attributes.updatedAt ||
el.attributes.publishedAt ||
Date.now(),
)
.toISOString()
.split('T')[0],
changeFrequency: 'weekly' as ChangeFrequency,
alternates: generateAlternates(
`${JUMPER_LEARN_PATH}${el.attributes.Slug}`,
),
priority: 0.8,
};
});
return article.data.map((el) => {
return {
url: withoutTrailingSlash(
`${process.env.NEXT_PUBLIC_SITE_URL}${JUMPER_LEARN_PATH}${el.attributes.Slug}`,
),
lastModified: new Date(
el.attributes.updatedAt || el.attributes.publishedAt || Date.now(),
)
.toISOString()
.split('T')[0],
changeFrequency: 'weekly' as ChangeFrequency,
priority: 0.8,
};
});
},
);
Expand Down

0 comments on commit 609ff01

Please sign in to comment.