Skip to content

Commit 0da3800

Browse files
authored
Merge pull request #8 from canonical/generate-sitemap
feat: Add generate_sitemap function
2 parents 267d680 + 8b83343 commit 0da3800

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
from canonicalwebteam.directory_parser.app import scan_directory # noqa
1+
from canonicalwebteam.directory_parser.app import ( # noqa
2+
scan_directory, # noqa
3+
generate_sitemap, # noqa
4+
)

canonicalwebteam/directory_parser/app.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import flask
12
import re
23
import subprocess
34
from contextlib import suppress
@@ -266,6 +267,22 @@ def get_git_last_modified_time(path):
266267
return None
267268

268269

270+
def generate_sitemap(directory_path, base_url):
271+
"""
272+
Generate sitemap given a directory path and a base url. It uses the
273+
local project's templates to generate the sitemap.
274+
275+
TODO: Include sitemap_template.xml in the directory_parser package
276+
"""
277+
tree = scan_directory(directory_path)
278+
xml_sitemap = flask.render_template(
279+
"/sitemap_template.xml",
280+
tree=tree["children"],
281+
base_url=base_url,
282+
)
283+
return xml_sitemap
284+
285+
269286
def scan_directory(path_name, base=None):
270287
"""
271288
We scan a given directory for valid pages and return a tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name="canonicalwebteam.directory-parser",
7-
version="1.1.0",
7+
version="1.1.1",
88
author="Canonical webteam",
99
author_email="webteam@canonical.com",
1010
url="https://github.com/canonical/canonicalwebteam.directory-parser",

0 commit comments

Comments
 (0)