Skip to content

Commit 01ebd37

Browse files
fix(build): Automate sitemap generation in CI for static export
1 parent 4797f61 commit 01ebd37

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
cache: 'npm'
4343
- name: Install dependencies
4444
run: npm install
45+
- name: Generate Sitemap
46+
run: npm run generate-sitemap
4547
- name: Build
4648
run: npm run build
4749
- name: Setup Pages

.gitignore

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
node_modules/
2-
out/
3-
.next/
1+
# Dependencies
2+
/node_modules
3+
4+
# Build and Output directories
5+
/out
6+
/.next
7+
8+
# Configuration and environment files
49
.env
10+
11+
# Generated files
12+
/public/sitemap.xml

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"dev": "next dev",
88
"build": "next build",
99
"start": "next start",
10-
"lint": "next lint"
10+
"lint": "next lint",
11+
"generate-sitemap": "node scripts/generate-sitemap.js"
1112
},
1213
"author": "Serhii Cherneha",
1314
"license": "SEE LICENSE",
Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { availableLanguages } from '../lib/translations';
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const { availableLanguages } = require('../lib/translations');
25

36
const BASE_URL = 'https://radix.pp.ua';
4-
const languages = availableLanguages;
57

68
function generateSitemap() {
79
let xml = `<?xml version="1.0" encoding="UTF-8"?>`;
@@ -10,12 +12,11 @@ function generateSitemap() {
1012
xml += `<url>`;
1113
xml += `<loc>${BASE_URL}</loc>`;
1214

13-
for (const lang of languages) {
15+
for (const lang of availableLanguages) {
1416
xml += `<xhtml:link rel="alternate" hreflang="${lang}" href="${BASE_URL}" />`;
1517
}
1618

1719
xml += `<xhtml:link rel="alternate" hreflang="x-default" href="${BASE_URL}" />`;
18-
1920
xml += `<lastmod>${new Date().toISOString().split('T')[0]}</lastmod>`;
2021
xml += `<changefreq>monthly</changefreq>`;
2122
xml += `<priority>1.0</priority>`;
@@ -25,18 +26,11 @@ function generateSitemap() {
2526
return xml;
2627
}
2728

28-
const Sitemap = () => {};
29-
30-
export const getServerSideProps = ({ res }) => {
29+
function main() {
3130
const sitemap = generateSitemap();
31+
const sitemapPath = path.join(__dirname, '../public', 'sitemap.xml');
32+
fs.writeFileSync(sitemapPath, sitemap);
33+
console.log(`Sitemap generated at ${sitemapPath}`);
34+
}
3235

33-
res.setHeader('Content-Type', 'application/xml');
34-
res.write(sitemap);
35-
res.end();
36-
37-
return {
38-
props: {},
39-
};
40-
};
41-
42-
export default Sitemap;
36+
main();

0 commit comments

Comments
 (0)