Skip to content

Commit 8dda9a3

Browse files
chore(sitemap): update lastmod dates in sitemap.xml; enhance sitemap generation script to dynamically fetch last modified dates
1 parent ac1dd00 commit 8dda9a3

3 files changed

Lines changed: 67 additions & 46 deletions

File tree

‎public/sitemap.xml‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
33
<url>
44
<loc>https://yourselftoscience.org/</loc>
5-
<lastmod>2025-08-20</lastmod>
5+
<lastmod>2025-08-19</lastmod>
66
<changefreq>weekly</changefreq>
77
<priority>1.0</priority>
88
</url>
@@ -14,25 +14,25 @@
1414
</url>
1515
<url>
1616
<loc>https://yourselftoscience.org/get-involved</loc>
17-
<lastmod>2025-08-20</lastmod>
17+
<lastmod>2025-07-16</lastmod>
1818
<changefreq>weekly</changefreq>
1919
<priority>0.9</priority>
2020
</url>
2121
<url>
2222
<loc>https://yourselftoscience.org/mission</loc>
23-
<lastmod>2025-08-20</lastmod>
23+
<lastmod>2025-08-19</lastmod>
2424
<changefreq>monthly</changefreq>
2525
<priority>0.9</priority>
2626
</url>
2727
<url>
2828
<loc>https://yourselftoscience.org/clinical-trials</loc>
29-
<lastmod>2025-08-20</lastmod>
29+
<lastmod>2025-07-31</lastmod>
3030
<changefreq>weekly</changefreq>
3131
<priority>0.8</priority>
3232
</url>
3333
<url>
3434
<loc>https://yourselftoscience.org/organ-body-tissue-donation</loc>
35-
<lastmod>2025-08-20</lastmod>
35+
<lastmod>2025-07-31</lastmod>
3636
<changefreq>weekly</changefreq>
3737
<priority>0.8</priority>
3838
</url>
@@ -44,133 +44,133 @@
4444
</url>
4545
<url>
4646
<loc>https://yourselftoscience.org/license/content</loc>
47-
<lastmod>2025-08-20</lastmod>
47+
<lastmod>2024-10-19</lastmod>
4848
<changefreq>yearly</changefreq>
4949
<priority>0.3</priority>
5050
</url>
5151
<url>
5252
<loc>https://yourselftoscience.org/license/code</loc>
53-
<lastmod>2025-08-20</lastmod>
53+
<lastmod>2024-10-19</lastmod>
5454
<changefreq>yearly</changefreq>
5555
<priority>0.3</priority>
5656
</url>
5757
<url>
5858
<loc>https://yourselftoscience.org/yourselftoscience.pdf</loc>
59-
<lastmod>2025-08-20</lastmod>
59+
<lastmod>2025-08-24</lastmod>
6060
<changefreq>weekly</changefreq>
6161
<priority>0.7</priority>
6262
</url>
6363
<url>
6464
<loc>https://yourselftoscience.org/index.html.md</loc>
65-
<lastmod>2025-08-20</lastmod>
65+
<lastmod>2025-07-31</lastmod>
6666
<changefreq>weekly</changefreq>
6767
<priority>0.8</priority>
6868
</url>
6969
<url>
7070
<loc>https://yourselftoscience.org/stats.md</loc>
71-
<lastmod>2025-08-20</lastmod>
71+
<lastmod>2025-07-31</lastmod>
7272
<changefreq>weekly</changefreq>
7373
<priority>0.7</priority>
7474
</url>
7575
<url>
7676
<loc>https://yourselftoscience.org/get-involved.md</loc>
77-
<lastmod>2025-08-20</lastmod>
77+
<lastmod>2025-07-31</lastmod>
7878
<changefreq>weekly</changefreq>
7979
<priority>0.7</priority>
8080
</url>
8181
<url>
8282
<loc>https://yourselftoscience.org/clinical-trials.md</loc>
83-
<lastmod>2025-08-20</lastmod>
83+
<lastmod>2025-07-31</lastmod>
8484
<changefreq>weekly</changefreq>
8585
<priority>0.6</priority>
8686
</url>
8787
<url>
8888
<loc>https://yourselftoscience.org/organ-body-tissue-donation.md</loc>
89-
<lastmod>2025-08-20</lastmod>
89+
<lastmod>2025-07-31</lastmod>
9090
<changefreq>weekly</changefreq>
9191
<priority>0.6</priority>
9292
</url>
9393
<url>
9494
<loc>https://yourselftoscience.org/clinical-trials?countries=Belgium</loc>
95-
<lastmod>2025-08-20</lastmod>
95+
<lastmod>2025-07-31</lastmod>
9696
<changefreq>weekly</changefreq>
9797
<priority>0.7</priority>
9898
</url>
9999
<url>
100100
<loc>https://yourselftoscience.org/clinical-trials?countries=Canada</loc>
101-
<lastmod>2025-08-20</lastmod>
101+
<lastmod>2025-07-31</lastmod>
102102
<changefreq>weekly</changefreq>
103103
<priority>0.7</priority>
104104
</url>
105105
<url>
106106
<loc>https://yourselftoscience.org/clinical-trials?countries=European%20Union</loc>
107-
<lastmod>2025-08-20</lastmod>
107+
<lastmod>2025-07-31</lastmod>
108108
<changefreq>weekly</changefreq>
109109
<priority>0.7</priority>
110110
</url>
111111
<url>
112112
<loc>https://yourselftoscience.org/clinical-trials?countries=Germany</loc>
113-
<lastmod>2025-08-20</lastmod>
113+
<lastmod>2025-07-31</lastmod>
114114
<changefreq>weekly</changefreq>
115115
<priority>0.7</priority>
116116
</url>
117117
<url>
118118
<loc>https://yourselftoscience.org/clinical-trials?countries=Iceland</loc>
119-
<lastmod>2025-08-20</lastmod>
119+
<lastmod>2025-07-31</lastmod>
120120
<changefreq>weekly</changefreq>
121121
<priority>0.7</priority>
122122
</url>
123123
<url>
124124
<loc>https://yourselftoscience.org/clinical-trials?countries=Liechtenstein</loc>
125-
<lastmod>2025-08-20</lastmod>
125+
<lastmod>2025-07-31</lastmod>
126126
<changefreq>weekly</changefreq>
127127
<priority>0.7</priority>
128128
</url>
129129
<url>
130130
<loc>https://yourselftoscience.org/clinical-trials?countries=Norway</loc>
131-
<lastmod>2025-08-20</lastmod>
131+
<lastmod>2025-07-31</lastmod>
132132
<changefreq>weekly</changefreq>
133133
<priority>0.7</priority>
134134
</url>
135135
<url>
136136
<loc>https://yourselftoscience.org/clinical-trials?countries=United%20Kingdom</loc>
137-
<lastmod>2025-08-20</lastmod>
137+
<lastmod>2025-07-31</lastmod>
138138
<changefreq>weekly</changefreq>
139139
<priority>0.7</priority>
140140
</url>
141141
<url>
142142
<loc>https://yourselftoscience.org/clinical-trials?countries=United%20States</loc>
143-
<lastmod>2025-08-20</lastmod>
143+
<lastmod>2025-07-31</lastmod>
144144
<changefreq>weekly</changefreq>
145145
<priority>0.7</priority>
146146
</url>
147147
<url>
148148
<loc>https://yourselftoscience.org/organ-body-tissue-donation?countries=Canada</loc>
149-
<lastmod>2025-08-20</lastmod>
149+
<lastmod>2025-07-31</lastmod>
150150
<changefreq>weekly</changefreq>
151151
<priority>0.7</priority>
152152
</url>
153153
<url>
154154
<loc>https://yourselftoscience.org/organ-body-tissue-donation?countries=France</loc>
155-
<lastmod>2025-08-20</lastmod>
155+
<lastmod>2025-07-31</lastmod>
156156
<changefreq>weekly</changefreq>
157157
<priority>0.7</priority>
158158
</url>
159159
<url>
160160
<loc>https://yourselftoscience.org/organ-body-tissue-donation?countries=Italy</loc>
161-
<lastmod>2025-08-20</lastmod>
161+
<lastmod>2025-07-31</lastmod>
162162
<changefreq>weekly</changefreq>
163163
<priority>0.7</priority>
164164
</url>
165165
<url>
166166
<loc>https://yourselftoscience.org/organ-body-tissue-donation?countries=United%20Kingdom</loc>
167-
<lastmod>2025-08-20</lastmod>
167+
<lastmod>2025-07-31</lastmod>
168168
<changefreq>weekly</changefreq>
169169
<priority>0.7</priority>
170170
</url>
171171
<url>
172172
<loc>https://yourselftoscience.org/organ-body-tissue-donation?countries=United%20States</loc>
173-
<lastmod>2025-08-20</lastmod>
173+
<lastmod>2025-07-31</lastmod>
174174
<changefreq>weekly</changefreq>
175175
<priority>0.7</priority>
176176
</url>

‎public/yourselftoscience.pdf‎

0 Bytes
Binary file not shown.

‎scripts/generateSitemap.js‎

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ const __dirname = path.dirname(__filename);
1010
// Define your site URL
1111
const SITE_URL = 'https://yourselftoscience.org';
1212

13+
// Helper function to get the last modified date of a file from Git
14+
function getLastModified(filePath) {
15+
try {
16+
const fullPath = path.resolve(__dirname, '..', filePath);
17+
const date = execFileSync('git', ['log', '-1', '--format=%as', fullPath]).toString().trim();
18+
if (date) {
19+
return date;
20+
}
21+
} catch (error) {
22+
// Fallback for files not in git or other errors
23+
}
24+
return new Date().toISOString().split('T')[0];
25+
}
26+
1327
// Generate the sitemap XML
1428
async function generateSitemap() {
1529
console.log('Generating sitemap.xml...');
@@ -28,8 +42,7 @@ async function generateSitemap() {
2842
2943
console.log(JSON.stringify({
3044
resources: resources.map(r => ({
31-
slug: r.slug,
32-
lastModified: new Date().toISOString().split('T')[0]
45+
slug: r.slug
3346
})),
3447
clinicalTrialCountries: clinicalTrialCountries,
3548
bodyDonationCountries: bodyDonationCountries
@@ -43,21 +56,21 @@ async function generateSitemap() {
4356
// Delete the temporary script
4457
fs.unlinkSync(tempScriptPath);
4558

46-
const today = new Date().toISOString().split('T')[0];
47-
4859
const staticPages = [
49-
{ url: `${SITE_URL}/`, priority: '1.0', changefreq: 'weekly' },
50-
{ url: `${SITE_URL}/stats`, priority: '0.9', changefreq: 'weekly' },
51-
{ url: `${SITE_URL}/get-involved`, priority: '0.9', changefreq: 'weekly' },
52-
{ url: `${SITE_URL}/mission`, priority: '0.9', changefreq: 'monthly' },
53-
{ url: `${SITE_URL}/clinical-trials`, priority: '0.8', changefreq: 'weekly' },
54-
{ url: `${SITE_URL}/organ-body-tissue-donation`, priority: '0.8', changefreq: 'weekly' },
55-
{ url: `${SITE_URL}/resources`, priority: '0.5', changefreq: 'monthly' }, // SEO-only page
56-
{ url: `${SITE_URL}/license/content`, priority: '0.3', changefreq: 'yearly' },
57-
{ url: `${SITE_URL}/license/code`, priority: '0.3', changefreq: 'yearly' },
58-
{ url: `${SITE_URL}/yourselftoscience.pdf`, priority: '0.7', changefreq: 'weekly' }
60+
{ url: `${SITE_URL}/`, priority: '1.0', changefreq: 'weekly', file: 'src/app/page.js', isDataDriven: true },
61+
{ url: `${SITE_URL}/stats`, priority: '0.9', changefreq: 'weekly', file: 'src/app/stats/page.js', isDataDriven: true },
62+
{ url: `${SITE_URL}/get-involved`, priority: '0.9', changefreq: 'weekly', file: 'src/app/get-involved/page.js' },
63+
{ url: `${SITE_URL}/mission`, priority: '0.9', changefreq: 'monthly', file: 'src/app/mission/page.js' },
64+
{ url: `${SITE_URL}/clinical-trials`, priority: '0.8', changefreq: 'weekly', file: 'src/app/clinical-trials/page.js', isDataDriven: true },
65+
{ url: `${SITE_URL}/organ-body-tissue-donation`, priority: '0.8', changefreq: 'weekly', file: 'src/app/organ-body-tissue-donation/page.js', isDataDriven: true },
66+
{ url: `${SITE_URL}/resources`, priority: '0.5', changefreq: 'monthly', file: 'src/app/resources/page.js', isDataDriven: true },
67+
{ url: `${SITE_URL}/license/content`, priority: '0.3', changefreq: 'yearly', file: 'LICENSE-CONTENT' },
68+
{ url: `${SITE_URL}/license/code`, priority: '0.3', changefreq: 'yearly', file: 'LICENSE-CODE' },
69+
{ url: `${SITE_URL}/yourselftoscience.pdf`, priority: '0.7', changefreq: 'weekly', file: 'public/yourselftoscience.pdf' }
5970
];
6071

72+
const dataDrivenLastMod = getLastModified('src/data/resources.js');
73+
6174
const markdownPages = [
6275
{ url: `${SITE_URL}/index.html.md`, priority: '0.8', changefreq: 'weekly' },
6376
{ url: `${SITE_URL}/stats.md`, priority: '0.7', changefreq: 'weekly' },
@@ -70,10 +83,15 @@ async function generateSitemap() {
7083
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">`;
7184

7285
staticPages.forEach(page => {
86+
let lastmod = getLastModified(page.file);
87+
if (page.isDataDriven) {
88+
// Use the more recent date between the page's own file and the data file
89+
lastmod = dataDrivenLastMod > lastmod ? dataDrivenLastMod : lastmod;
90+
}
7391
sitemap += `
7492
<url>
7593
<loc>${page.url}</loc>
76-
<lastmod>${today}</lastmod>
94+
<lastmod>${lastmod}</lastmod>
7795
<changefreq>${page.changefreq}</changefreq>
7896
<priority>${page.priority}</priority>
7997
</url>`;
@@ -83,7 +101,7 @@ async function generateSitemap() {
83101
sitemap += `
84102
<url>
85103
<loc>${page.url}</loc>
86-
<lastmod>${today}</lastmod>
104+
<lastmod>${dataDrivenLastMod}</lastmod>
87105
<changefreq>${page.changefreq}</changefreq>
88106
<priority>${page.priority}</priority>
89107
</url>`;
@@ -94,7 +112,7 @@ async function generateSitemap() {
94112
sitemap += `
95113
<url>
96114
<loc>${SITE_URL}/clinical-trials?countries=${encodeURIComponent(country)}</loc>
97-
<lastmod>${today}</lastmod>
115+
<lastmod>${dataDrivenLastMod}</lastmod>
98116
<changefreq>weekly</changefreq>
99117
<priority>0.7</priority>
100118
</url>`;
@@ -105,17 +123,20 @@ async function generateSitemap() {
105123
sitemap += `
106124
<url>
107125
<loc>${SITE_URL}/organ-body-tissue-donation?countries=${encodeURIComponent(country)}</loc>
108-
<lastmod>${today}</lastmod>
126+
<lastmod>${dataDrivenLastMod}</lastmod>
109127
<changefreq>weekly</changefreq>
110128
<priority>0.7</priority>
111129
</url>`;
112130
});
113131

132+
const resourceTemplateLastMod = getLastModified('src/app/resource/[slug]/page.js');
133+
const lastModForResources = dataDrivenLastMod > resourceTemplateLastMod ? dataDrivenLastMod : resourceTemplateLastMod;
134+
114135
resourcesData.forEach(resource => {
115136
sitemap += `
116137
<url>
117138
<loc>${SITE_URL}/resource/${resource.slug}</loc>
118-
<lastmod>${resource.lastModified}</lastmod>
139+
<lastmod>${lastModForResources}</lastmod>
119140
<changefreq>monthly</changefreq>
120141
<priority>0.5</priority>
121142
</url>`;

0 commit comments

Comments
 (0)