fix(ci): restore full localized sitemap coverage and strict 404 validation
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 18s
Build & Deploy / 🧪 QA (push) Successful in 2m7s
Build & Deploy / 🏗️ Build (push) Successful in 2m49s
Build & Deploy / 🚀 Deploy (push) Failing after 22s
Build & Deploy / 🧪 Smoke Test (push) Has been skipped
Build & Deploy / ⚡ Lighthouse (push) Has been skipped
Build & Deploy / ♿ WCAG (push) Has been skipped
Build & Deploy / 🛡️ Quality Gates (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 5s
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 18s
Build & Deploy / 🧪 QA (push) Successful in 2m7s
Build & Deploy / 🏗️ Build (push) Successful in 2m49s
Build & Deploy / 🚀 Deploy (push) Failing after 22s
Build & Deploy / 🧪 Smoke Test (push) Has been skipped
Build & Deploy / ⚡ Lighthouse (push) Has been skipped
Build & Deploy / ♿ WCAG (push) Has been skipped
Build & Deploy / 🛡️ Quality Gates (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 5s
This commit is contained in:
85
lib/slugs.ts
85
lib/slugs.ts
@@ -1,29 +1,36 @@
|
||||
import { getTranslations } from 'next-intl/server';
|
||||
import enMessages from '../messages/en.json';
|
||||
import deMessages from '../messages/de.json';
|
||||
|
||||
type Messages = typeof enMessages;
|
||||
const getMessages = (locale: string): Messages => {
|
||||
return locale === 'de' ? (deMessages as any) : enMessages;
|
||||
};
|
||||
|
||||
/**
|
||||
* Maps a translated slug to original file slug
|
||||
* @param translatedSlug - The slug from URL (translated)
|
||||
* @param _locale - The current locale (unused, kept for API consistency)
|
||||
* @param locale - The current locale
|
||||
* @returns The original file slug, or input slug if no mapping exists
|
||||
*/
|
||||
export async function mapSlugToFileSlug(translatedSlug: string, _locale: string): Promise<string> {
|
||||
const t = await getTranslations('Slugs');
|
||||
|
||||
export async function mapSlugToFileSlug(translatedSlug: string, locale: string): Promise<string> {
|
||||
const messages = getMessages(locale);
|
||||
const slugs = messages.Slugs;
|
||||
|
||||
// Check pages
|
||||
if (t.has(`pages.${translatedSlug}`)) {
|
||||
return t(`pages.${translatedSlug}`);
|
||||
if (slugs.pages && translatedSlug in slugs.pages) {
|
||||
return slugs.pages[translatedSlug as keyof typeof slugs.pages];
|
||||
}
|
||||
|
||||
|
||||
// Check products
|
||||
if (t.has(`products.${translatedSlug}`)) {
|
||||
return t(`products.${translatedSlug}`);
|
||||
if (slugs.products && translatedSlug in slugs.products) {
|
||||
return slugs.products[translatedSlug as keyof typeof slugs.products];
|
||||
}
|
||||
|
||||
|
||||
// Check categories
|
||||
if (t.has(`categories.${translatedSlug}`)) {
|
||||
return t(`categories.${translatedSlug}`);
|
||||
if (slugs.categories && translatedSlug in slugs.categories) {
|
||||
return slugs.categories[translatedSlug as keyof typeof slugs.categories];
|
||||
}
|
||||
|
||||
|
||||
// Return original slug if no mapping found
|
||||
return translatedSlug;
|
||||
}
|
||||
@@ -31,28 +38,25 @@ export async function mapSlugToFileSlug(translatedSlug: string, _locale: string)
|
||||
/**
|
||||
* Maps an original file slug to translated slug for a locale
|
||||
* @param fileSlug - The original file slug
|
||||
* @param _locale - The target locale (unused, kept for API consistency)
|
||||
* @param locale - The target locale
|
||||
* @returns The translated slug, or input slug if no mapping exists
|
||||
*/
|
||||
export async function mapFileSlugToTranslated(fileSlug: string, _locale: string): Promise<string> {
|
||||
const t = await getTranslations('Slugs');
|
||||
|
||||
// Find the key that maps to this file slug
|
||||
const sections = ['pages', 'products', 'categories'];
|
||||
|
||||
for (const section of sections) {
|
||||
if (t.has(section)) {
|
||||
const sectionData = t.raw(section);
|
||||
if (sectionData && typeof sectionData === 'object') {
|
||||
for (const [translatedSlug, mappedSlug] of Object.entries(sectionData)) {
|
||||
if (mappedSlug === fileSlug) {
|
||||
return translatedSlug;
|
||||
}
|
||||
export async function mapFileSlugToTranslated(fileSlug: string, locale: string): Promise<string> {
|
||||
const messages = getMessages(locale);
|
||||
const slugs = messages.Slugs;
|
||||
|
||||
const sections = [slugs.pages, slugs.products, slugs.categories];
|
||||
|
||||
for (const sectionData of sections) {
|
||||
if (sectionData && typeof sectionData === 'object') {
|
||||
for (const [translatedSlug, mappedSlug] of Object.entries(sectionData)) {
|
||||
if (mappedSlug === fileSlug) {
|
||||
return translatedSlug;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Return original slug if no mapping found
|
||||
return fileSlug;
|
||||
}
|
||||
@@ -60,18 +64,19 @@ export async function mapFileSlugToTranslated(fileSlug: string, _locale: string)
|
||||
/**
|
||||
* Gets all translated slugs for a section
|
||||
* @param section - The section name (pages, products, categories)
|
||||
* @param _locale - The current locale (unused, kept for API consistency)
|
||||
* @param locale - The current locale
|
||||
* @returns Object mapping translated slugs to file slugs
|
||||
*/
|
||||
export async function getSlugMappings(section: 'pages' | 'products' | 'categories', _locale: string): Promise<Record<string, string>> {
|
||||
const t = await getTranslations('Slugs');
|
||||
|
||||
if (t.has(section)) {
|
||||
const sectionData = t.raw(section);
|
||||
if (sectionData && typeof (sectionData as any) === 'object') {
|
||||
return sectionData as Record<string, string>;
|
||||
}
|
||||
export async function getSlugMappings(
|
||||
section: 'pages' | 'products' | 'categories',
|
||||
locale: string,
|
||||
): Promise<Record<string, string>> {
|
||||
const messages = getMessages(locale);
|
||||
const sectionData = messages.Slugs[section];
|
||||
|
||||
if (sectionData && typeof sectionData === 'object') {
|
||||
return sectionData as Record<string, string>;
|
||||
}
|
||||
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user