Skip to content

Commit 6628c80

Browse files
Merge pull request #53 from codeplaysoftware/add-sitemap-generation
Add Sitemap Generation
2 parents 27cfdcd + e08c93a commit 6628c80

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

.github/workflows/build.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ jobs:
3939
name: routes
4040
path: routes.txt
4141

42+
# Generate a sitemap.xml and save to the src directory
43+
generate-sitemap:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
47+
- name: Set up Python 3.11
48+
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d
49+
with:
50+
python-version: '3.11'
51+
cache: 'pip'
52+
- name: Install Dependencies
53+
run: pip install -r ./scripts/routes/requirements.txt --require-hashes --no-deps
54+
- name: Create Sitemap
55+
run: python ./scripts/routes/sitemap.py "$SITE_URL" "routes.txt" > src/sitemap.xml
56+
- name: Upload to GitHub Artifacts
57+
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b
58+
with:
59+
name: sitemap
60+
path: sitemap.xml
61+
4262
# Build the Angular site
4363
build:
4464
needs: generate-routes

angular.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"tsConfig": "tsconfig.app.json",
3030
"inlineStyleLanguage": "scss",
3131
"assets": [
32+
"src/sitemap.xml",
3233
"src/404.html",
3334
"src/favicon.png",
3435
"src/robots.txt",

scripts/routes/sitemap.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
3+
#
4+
# Copyright (C) Codeplay Software Limited.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use these files except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# For your convenience, a copy of the License has been included in this
13+
# repository.
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
#
21+
22+
import os
23+
import sys
24+
25+
26+
def load_routes(routes_file_path: str):
27+
with open(routes_file_path, mode='r', encoding='utf-8') as file:
28+
return file.read().split(os.linesep)
29+
30+
31+
def generate(base_url: str, routes_file_path: str):
32+
routes = load_routes(routes_file_path)
33+
route_urls = [f'\t<url><loc>{base_url}{x}</loc></url>' for x in routes]
34+
35+
output = f"""<?xml version="1.0" encoding="UTF-8"?>
36+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
37+
{os.linesep.join(route_urls)}
38+
</urlset>
39+
"""
40+
41+
return output
42+
43+
44+
if __name__ == '__main__':
45+
args = sys.argv[1:]
46+
47+
try:
48+
if len(args) != 2:
49+
raise ValueError('Please provide a valid feed base URL and routes.txt file path.')
50+
51+
print(generate(args[0], args[1]))
52+
except Exception as e:
53+
print(str(e))
54+
quit(1)

src/sitemap.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3+
<url><loc>https://sycl.tech/</loc></url>
4+
<url><loc>https://sycl.tech/getting-started</loc></url>
5+
<url><loc>https://sycl.tech/getting-started/academy</loc></url>
6+
<url><loc>https://sycl.tech/ecosystem</loc></url>
7+
<url><loc>https://sycl.tech/ecosystem/projects</loc></url>
8+
<url><loc>https://sycl.tech/ecosystem/presentations</loc></url>
9+
<url><loc>https://sycl.tech/ecosystem/research</loc></url>
10+
<url><loc>https://sycl.tech/ecosystem/implementations</loc></url>
11+
<url><loc>https://sycl.tech/calendar</loc></url>
12+
<url><loc>https://sycl.tech/news</loc></url>
13+
<url><loc>https://sycl.tech/playground</loc></url>
14+
<url><loc>https://sycl.tech/contributors</loc></url>
15+
<url><loc>https://sycl.tech/settings</loc></url>
16+
<url><loc>https://sycl.tech/privacy</loc></url>
17+
<url><loc>https://sycl.tech/cookies</loc></url>
18+
<url><loc>https://sycl.tech/404</loc></url>
19+
<url><loc>https://sycl.tech</loc></url>
20+
</urlset>

0 commit comments

Comments
 (0)