mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-10 17:14:34 +01:00
fix(nginx): tighten routing + add SEO redirects
fix(seo): canonical -> English for localized pages docs: reframe Self-Hosted vs Commercial builds + Common Issues
This commit is contained in:
1 parent
f24bf4ea98
commit
58a0053778
18 files changed
+405
-266
No files matched your search
@@ -240,7 +240,8 @@ function processFileForLanguage(
|
||||
defaultLink.href = buildUrl('', pagePath);
|
||||
document.head.appendChild(defaultLink);
|
||||
|
||||
const canonicalUrl = buildUrl(lang, pagePath);
|
||||
const localizedUrl = buildUrl(lang, pagePath);
|
||||
const canonicalUrl = buildUrl('', pagePath);
|
||||
let canonical = document.querySelector('link[rel="canonical"]');
|
||||
if (!canonical) {
|
||||
canonical = document.createElement('link');
|
||||
@@ -250,15 +251,15 @@ function processFileForLanguage(
|
||||
canonical.href = canonicalUrl;
|
||||
|
||||
const ogUrl = document.querySelector('meta[property="og:url"]');
|
||||
if (ogUrl) ogUrl.content = canonicalUrl;
|
||||
if (ogUrl) ogUrl.content = localizedUrl;
|
||||
const twitterUrl = document.querySelector('meta[name="twitter:url"]');
|
||||
if (twitterUrl) twitterUrl.content = canonicalUrl;
|
||||
if (twitterUrl) twitterUrl.content = localizedUrl;
|
||||
|
||||
injectOrganizationLd(document);
|
||||
|
||||
const localizedToolName = resolveToolName(translationKey, tools);
|
||||
if (localizedToolName) {
|
||||
injectToolBreadcrumb(document, lang, localizedToolName, canonicalUrl);
|
||||
injectToolBreadcrumb(document, lang, localizedToolName, localizedUrl);
|
||||
}
|
||||
|
||||
const links = document.querySelectorAll('a[href]');
|
||||
|
||||
@@ -92,31 +92,26 @@ function generateSitemap() {
|
||||
|
||||
for (const pageName of htmlFiles) {
|
||||
const priority = getPriority(pageName);
|
||||
const url = buildUrl('en', pageName);
|
||||
const lastmod = getLastMod('en', pageName);
|
||||
|
||||
for (const lang of languages) {
|
||||
const url = buildUrl(lang, pageName);
|
||||
const lastmod = getLastMod(lang, pageName);
|
||||
|
||||
sitemap += ` <url>
|
||||
sitemap += ` <url>
|
||||
<loc>${url}</loc>
|
||||
<lastmod>${lastmod}</lastmod>
|
||||
<changefreq>weekly</changefreq>
|
||||
<priority>${priority}</priority>
|
||||
`;
|
||||
|
||||
// Add hreflang alternates for all languages
|
||||
for (const altLang of languages) {
|
||||
const altUrl = buildUrl(altLang, pageName);
|
||||
sitemap += ` <xhtml:link rel="alternate" hreflang="${altLang}" href="${altUrl}"/>
|
||||
`;
|
||||
}
|
||||
|
||||
// Add x-default pointing to English
|
||||
const defaultUrl = buildUrl('en', pageName);
|
||||
sitemap += ` <xhtml:link rel="alternate" hreflang="x-default" href="${defaultUrl}"/>
|
||||
</url>
|
||||
for (const altLang of languages) {
|
||||
const altUrl = buildUrl(altLang, pageName);
|
||||
sitemap += ` <xhtml:link rel="alternate" hreflang="${altLang}" href="${altUrl}"/>
|
||||
`;
|
||||
}
|
||||
|
||||
const defaultUrl = buildUrl('en', pageName);
|
||||
sitemap += ` <xhtml:link rel="alternate" hreflang="x-default" href="${defaultUrl}"/>
|
||||
</url>
|
||||
`;
|
||||
}
|
||||
|
||||
sitemap += `</urlset>
|
||||
@@ -128,9 +123,8 @@ function generateSitemap() {
|
||||
const publicSitemapPath = path.resolve(__dirname, '../public/sitemap.xml');
|
||||
fs.writeFileSync(publicSitemapPath, sitemap);
|
||||
|
||||
const urlCount = htmlFiles.length * languages.length;
|
||||
console.log(
|
||||
`✅ Sitemap generated with ${urlCount} URLs (${htmlFiles.length} pages × ${languages.length} languages)`
|
||||
`✅ Sitemap generated with ${htmlFiles.length} canonical URLs (${languages.length} hreflang alternates each)`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,11 +69,9 @@ function findAll(html, regex) {
|
||||
function expectedCanonicalForFile(rel) {
|
||||
const parts = rel.split('/');
|
||||
const fileName = parts.pop();
|
||||
const langPrefix = parts.length > 0 ? parts.join('/') : '';
|
||||
const baseName = fileName.replace(/\.html$/, '');
|
||||
const slug = baseName === 'index' ? '' : baseName;
|
||||
const segments = [SITE_URL];
|
||||
if (langPrefix) segments.push(langPrefix);
|
||||
if (slug) segments.push(slug);
|
||||
return segments.join('/').replace(/\/+$/, '') || SITE_URL;
|
||||
}
|
||||
@@ -230,11 +228,9 @@ function auditSitemap() {
|
||||
.filter((d) => fs.statSync(path.join(LOCALES_DIR, d)).isDirectory());
|
||||
for (const lang of expectedLocales) {
|
||||
if (lang === 'en') continue;
|
||||
const sample = locs.find(
|
||||
(l) => l.includes(`/${lang}/`) || l.endsWith(`/${lang}`)
|
||||
);
|
||||
if (!sample) {
|
||||
warn('sitemap', `sitemap has no entry for locale "${lang}"`);
|
||||
const hreflangPattern = new RegExp(`hreflang="${lang}"`);
|
||||
if (!hreflangPattern.test(xml)) {
|
||||
warn('sitemap', `sitemap has no hreflang entry for locale "${lang}"`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user