Skip to content

Commit e6bd4a2

Browse files
docs: Update README.md with changelog for show_progress
This commit updates the `README.md` file to include a changelog for the newly added `show_progress` feature. It also updates the example usage to demonstrate the new parameter.
1 parent 1ca768d commit e6bd4a2

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
LocalSiteMap is an open-source Python package designed for generating sitemaps from local files. It tracks `HTML` and `HTM` files, and generates complete sitemaps for the root website, including directories.
99

10+
### Changes in version 1.0.1:
11+
- Added `show_progress` boolean to print out mapping progress, pages mapped, and files found.
12+
1013
### Changes in version 1.0.0:
1114
- Added initial package code, with automatic directory crawling to generate the `sitemap.xml` file.
1215

@@ -59,7 +62,7 @@ base_url_of_your_website = "https://example.com"
5962
excluded = ["auth", "forms", "template.html", "media", ".git", ".vscode", "node_modules"] # Example exclusions
6063

6164
# Generate the sitemap
62-
generate_sitemap(root_directory, base_url_of_your_website, "sitemap.xml", excluded)
65+
generate_sitemap(root_directory, base_url_of_your_website, "sitemap.xml", excluded, show_progress=True)
6366
print("Sitemap generated in sitemap.xml")
6467
```
6568

localsitemap/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from xml.etree.ElementTree import Element, SubElement, tostring
44
from xml.dom import minidom
55

6-
def generate_sitemap(root_path, base_url, output_file="sitemap.xml", excluded_paths=None):
6+
def generate_sitemap(root_path, base_url, output_file="sitemap.xml", excluded_paths=None, show_progress=False):
77
"""
88
Generates a sitemap XML file by crawling a directory structure.
99
@@ -27,6 +27,8 @@ def generate_sitemap(root_path, base_url, output_file="sitemap.xml", excluded_pa
2727
full_dir_path = os.path.join(root, dir_name)
2828
if any(excluded in full_dir_path for excluded in excluded_paths):
2929
continue
30+
if show_progress:
31+
print(f"Mapping directory: {full_dir_path}")
3032
relative_dir_path = os.path.relpath(full_dir_path, root_path)
3133
url = os.path.join(base_url, relative_dir_path).replace("\\", "/") + "/"
3234
lastmod = datetime.datetime.fromtimestamp(os.path.getmtime(full_dir_path)).isoformat()
@@ -40,6 +42,10 @@ def generate_sitemap(root_path, base_url, output_file="sitemap.xml", excluded_pa
4042
for file in files:
4143
if file.endswith((".html", ".htm")):
4244
full_path = os.path.join(root, file)
45+
46+
if show_progress:
47+
print(f"Found file: {full_path}")
48+
4349
relative_path = os.path.relpath(full_path, root_path)
4450

4551
# Check if the file should be excluded
@@ -68,5 +74,9 @@ def generate_sitemap(root_path, base_url, output_file="sitemap.xml", excluded_pa
6874
reparsed = minidom.parseString(xml_string)
6975
pretty_xml = reparsed.toprettyxml(indent=" ")
7076

77+
if show_progress:
78+
print(f"Total pages mapped: {len(urlset)}")
79+
print(f"Saving sitemap to {output_file}...")
80+
7181
with open(output_file, "w", encoding="utf-8") as f:
7282
f.write(pretty_xml)

0 commit comments

Comments
 (0)