mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-09 09:04:18 +01:00
seo fixes
This commit is contained in:
1 parent
83ff47db9b
commit
9e980cdea2
189 files changed
+17781
-2238
No files matched your search
@@ -11,46 +11,95 @@ const mainDistPath = path.join(projectRoot, 'dist');
|
||||
const targetDocsPath = path.join(mainDistPath, 'docs');
|
||||
|
||||
function copyDir(src, dest) {
|
||||
if (!fs.existsSync(dest)) {
|
||||
fs.mkdirSync(dest, { recursive: true });
|
||||
}
|
||||
if (!fs.existsSync(dest)) {
|
||||
fs.mkdirSync(dest, { recursive: true });
|
||||
}
|
||||
|
||||
const entries = fs.readdirSync(src, { withFileTypes: true });
|
||||
const entries = fs.readdirSync(src, { withFileTypes: true });
|
||||
|
||||
for (const entry of entries) {
|
||||
const srcPath = path.join(src, entry.name);
|
||||
const destPath = path.join(dest, entry.name);
|
||||
for (const entry of entries) {
|
||||
const srcPath = path.join(src, entry.name);
|
||||
const destPath = path.join(dest, entry.name);
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
copyDir(srcPath, destPath);
|
||||
} else {
|
||||
fs.copyFileSync(srcPath, destPath);
|
||||
}
|
||||
if (entry.isDirectory()) {
|
||||
copyDir(srcPath, destPath);
|
||||
} else {
|
||||
fs.copyFileSync(srcPath, destPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Including docs in dist...');
|
||||
|
||||
if (!fs.existsSync(docsDistPath)) {
|
||||
console.error('Error: Docs build not found. Please run "npm run docs:build" first.');
|
||||
process.exit(1);
|
||||
console.error(
|
||||
'Error: Docs build not found. Please run "npm run docs:build" first.'
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!fs.existsSync(mainDistPath)) {
|
||||
console.error('Error: Main dist folder not found. Please run "npm run build" first.');
|
||||
process.exit(1);
|
||||
console.error(
|
||||
'Error: Main dist folder not found. Please run "npm run build" first.'
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(`Copying from: ${docsDistPath}`);
|
||||
console.log(`Copying to: ${targetDocsPath}`);
|
||||
console.log(`Copying from: ${docsDistPath}`);
|
||||
console.log(`Copying to: ${targetDocsPath}`);
|
||||
|
||||
copyDir(docsDistPath, targetDocsPath);
|
||||
copyDir(docsDistPath, targetDocsPath);
|
||||
|
||||
console.log('Docs successfully included in dist/docs!');
|
||||
console.log('Docs successfully included in dist/docs!');
|
||||
|
||||
const files = fs.readdirSync(targetDocsPath);
|
||||
console.log(`Copied ${files.length} items to dist/docs`);
|
||||
const files = fs.readdirSync(targetDocsPath);
|
||||
console.log(`Copied ${files.length} items to dist/docs`);
|
||||
|
||||
addDocsToSitemap();
|
||||
} catch (error) {
|
||||
console.error('Error copying docs:', error.message);
|
||||
process.exit(1);
|
||||
console.error('Error copying docs:', error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function listDocsHtml(dir, prefix) {
|
||||
const urls = [];
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
if (entry.isDirectory()) {
|
||||
if (entry.name === 'assets' || entry.name.startsWith('.')) continue;
|
||||
urls.push(
|
||||
...listDocsHtml(path.join(dir, entry.name), `${prefix}/${entry.name}`)
|
||||
);
|
||||
} else if (entry.name.endsWith('.html') && entry.name !== '404.html') {
|
||||
const slug = entry.name.replace(/\.html$/, '');
|
||||
urls.push(slug === 'index' ? `${prefix}/` : `${prefix}/${slug}`);
|
||||
}
|
||||
}
|
||||
return urls;
|
||||
}
|
||||
|
||||
function addDocsToSitemap() {
|
||||
const siteUrl = (process.env.SITE_URL || 'https://www.bentopdf.com').replace(
|
||||
/\/+$/,
|
||||
''
|
||||
);
|
||||
const sitemapPath = path.join(mainDistPath, 'sitemap.xml');
|
||||
if (!fs.existsSync(sitemapPath)) {
|
||||
console.warn(
|
||||
'sitemap.xml not found in dist; skipping docs sitemap entries'
|
||||
);
|
||||
return;
|
||||
}
|
||||
let xml = fs.readFileSync(sitemapPath, 'utf-8');
|
||||
if (xml.includes(`<loc>${siteUrl}/docs/</loc>`)) return;
|
||||
|
||||
const urls = listDocsHtml(targetDocsPath, '/docs');
|
||||
const entries = urls
|
||||
.map(
|
||||
(url) =>
|
||||
` <url>\n <loc>${siteUrl}${url}</loc>\n <priority>0.6</priority>\n </url>\n`
|
||||
)
|
||||
.join('');
|
||||
xml = xml.replace('</urlset>', `${entries}</urlset>`);
|
||||
fs.writeFileSync(sitemapPath, xml);
|
||||
console.log(`Added ${urls.length} docs URLs to sitemap.xml`);
|
||||
}
|
||||
Reference in new issue
Block a user