Skip to content

Commit d8cffd6

Browse files
authored
Created a sitemap of the website. (#70)
#### Enhancements and Updates - Added a sitemap builder to the `builder` directory that generates a sitemap and logs it to the console. - Created a new model class for the sitemap builder to use. - Split off the page info needed by the sitemap builder into a separate TypeScript file. - Added metadata to the pages for the sitemap, like date last updated. #### General Technical Changes - Generated a `sitemap.xml` file with all the pages of the website. - Referred to this file in the `robots.txt` file. #### Dependencies - Added the `sitemap` dependency. - Added the `tsx` dependency as a dev dependency. #### Changes by @tahoni
2 parents 227962f + 8926a73 commit d8cffd6

22 files changed

+1990
-1984
lines changed

.npmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
@tahoni:registry=https://npm.pkg.github.com
2-
//npm.pkg.github.com/:_authToken=${NPM_TOKEN}
2+
//npm.pkg.github.com/:_authToken=${NPM_TOKEN_READ}

.vscode/tasks.json

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"options": {
1414
"env": {
1515
"NPM_TOKEN": "${NPM_TOKEN_READ}"
16-
},
17-
"detail": "Installs project dependencies using npm"
18-
}
16+
}
17+
},
18+
"detail": "Installs project dependencies using npm"
1919
},
2020
{
2121
"label": "Run Dev Server",
@@ -42,43 +42,32 @@
4242
"kind": "build",
4343
"isDefault": true
4444
},
45+
"problemMatcher": [],
4546
"options": {
4647
"env": {
4748
"GOOGLE_MAPS_API_KEY": "${GOOGLE_MAPS_API_KEY_LIVE}",
4849
"RECAPTCHA_V2_SITE_KEY": "${RECAPTCHA_V2_SITE_KEY_LIVE}"
4950
}
5051
},
51-
"problemMatcher": [],
5252
"detail": "Builds the project using Vite"
5353
},
5454
{
5555
"label": "Preview Build",
5656
"type": "npm",
5757
"script": "preview",
5858
"group": {
59-
"kind": "test",
59+
"kind": "build",
6060
"isDefault": true
6161
},
6262
"problemMatcher": [],
6363
"detail": "Previews the built project using Vite"
6464
},
65-
{
66-
"label": "Preview Build On Host",
67-
"type": "npm",
68-
"script": "host",
69-
"group": {
70-
"kind": "test",
71-
"isDefault": true
72-
},
73-
"problemMatcher": [],
74-
"detail": "Previews the built project using Vite on a spceific exposed host"
75-
},
7665
{
7766
"label": "Run Tests",
7867
"type": "npm",
7968
"script": "test",
8069
"group": {
81-
"kind": "test",
70+
"kind": "build",
8271
"isDefault": true
8372
},
8473
"problemMatcher": [],
@@ -89,7 +78,7 @@
8978
"type": "npm",
9079
"script": "lint",
9180
"group": {
92-
"kind": "test",
81+
"kind": "build",
9382
"isDefault": true
9483
},
9584
"problemMatcher": [],
@@ -100,7 +89,7 @@
10089
"type": "npm",
10190
"script": "audit",
10291
"group": {
103-
"kind": "test",
92+
"kind": "build",
10493
"isDefault": true
10594
},
10695
"problemMatcher": [],
@@ -111,7 +100,7 @@
111100
"type": "shell",
112101
"command": "npm audit",
113102
"group": {
114-
"kind": "test",
103+
"kind": "build",
115104
"isDefault": true
116105
},
117106
"problemMatcher": [],
@@ -122,7 +111,7 @@
122111
"type": "shell",
123112
"command": "npm audit fix",
124113
"group": {
125-
"kind": "test",
114+
"kind": "build",
126115
"isDefault": true
127116
},
128117
"problemMatcher": [],

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Table of Contents
66

7+
- [Version 3.6.6](#version-366---2025-06-01)
78
- [Version 3.6.5](#version-365---2025-05-15)
89
- [Version 3.6.4](#version-364---2025-05-14)
910
- [Version 3.6.3](#version-363---2025-05-14)
@@ -44,6 +45,31 @@
4445
- [Version 3.0.1](#version-301---2024-08-27)
4546
- [Version 3.0.0](#version-300---2024-08-18)
4647

48+
### [Version 3.6.6](https://github.com/tahoni/hpsc-web-vite/releases/tag/version-3.6.5) - _2025-06-01_
49+
50+
Created a sitemap of the website.
51+
52+
#### Enhancements and Updates
53+
54+
- Added a sitemap builder to the `builder` directory that generates a sitemap and logs it to the console.
55+
- Created a new model class for the sitemap builder to use.
56+
- Split off the page info needed by the sitemap builder into a separate TypeScript file.
57+
- Added metadata to the pages for the sitemap, like date last updated.
58+
59+
#### General Technical Changes
60+
61+
- Generated a `sitemap.xml` file with all the pages of the website.
62+
- Referred to this file in the `robots.txt` file.
63+
64+
#### Dependencies
65+
66+
- Added the `sitemap` dependency.
67+
- Added the `tsx` dependency as a dev dependency.
68+
69+
#### Changes by
70+
71+
@tahoni
72+
4773
### [Version 3.6.5](https://github.com/tahoni/hpsc-web-vite/releases/tag/version-3.6.5) - _2025-05-15_
4874

4975
Changed the canonical URL to just the domain name, since it is served like that

RELEASE_NOTES.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@
22

33
## Release Notes
44

5-
### Version 3.6.5 - _2025-05-15_
5+
### Version 3.6.6 - _2025-06-01_
66

7-
Changed the canonical URL to just the domain name, since it is served like that
8-
by the web server.
9-
Fixed all the pages being redirected to the home page on refresh.
7+
Created a sitemap of the website.
108

119
#### Enhancements and Updates
1210

13-
- Updated the canonical URL in `index.html` to just [https://hpsc.co.za](https://hpsc.co.za),
14-
without the `www` prefix.
11+
- Added a sitemap builder to the `builder` directory that generates a sitemap and logs it to the console.
12+
- Created a new model class for the sitemap builder to use.
13+
- Split off the page info needed by the sitemap builder into a separate TypeScript file.
14+
- Added metadata to the pages for the sitemap, like date last updated.
1515

1616
#### General Technical Changes
1717

18-
- Removed the permanent redirect (HTTP status 301) from the `.htaccess` rules
19-
that was redirecting all pages to the home page on manual refresh.
18+
- Generated a `sitemap.xml` file with all the pages of the website.
19+
- Referred to this file in the `robots.txt` file.
20+
21+
#### Dependencies
22+
23+
- Added the `sitemap` dependency.
24+
- Added the `tsx` dependency as a dev dependency.
2025

2126
#### Changes by
2227

builders/RoutesSitemap.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { SitemapStream, streamToPromise } from "sitemap";
2+
import { Readable } from "stream";
3+
import { SitemapMapping } from "../src/model/SitemapMapping";
4+
import { coreRoutes } from "../src/config/BaseRoutes";
5+
import { baseUrl } from "../src/constants/AppConstants";
6+
7+
export const generateRoutesSitemap = async () => {
8+
// An array with your links
9+
const links: SitemapMapping[] = coreRoutes.map((route) => {
10+
const priority: number = route.name === "Home" ? 1.0 : 0.5;
11+
return new SitemapMapping({
12+
url: route.path,
13+
priority: priority,
14+
lastmod: route.dateUpdated,
15+
});
16+
});
17+
18+
// Create a stream to write to
19+
const stream = new SitemapStream({
20+
hostname: baseUrl,
21+
lastmodDateOnly: true,
22+
});
23+
24+
// Return a promise that resolves with your XML string
25+
const data = await streamToPromise(Readable.from(links).pipe(stream));
26+
return data.toString();
27+
};
28+
29+
generateRoutesSitemap().then((xml) => {
30+
console.log(xml);
31+
});
32+
// This code builds a sitemap using the sitemap package and streams the links into it.
33+
// The sitemap is then converted to a string and logged to the console.
34+
// You can modify the links array to include your own URLs and their properties.
35+
// Make sure to replace "https://..." with your actual hostname.
36+
// You can also adjust the changefreq and priority as needed for your sitemap.
37+
// This code is a basic example and can be expanded to include more complex logic or additional features as needed.

0 commit comments

Comments
 (0)