Skip to content

Commit 1ca768d

Browse files
committed
Initial commit.
0 parents  commit 1ca768d

10 files changed

Lines changed: 366 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: '[Brief descriptive title of the issue]'
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
> [!NOTE]
21+
> If you cannot reproduce the issue consistently, please describe the circumstances under which it occurred.
22+
23+
**Expected behavior**
24+
A clear and concise description of what you expected to happen.
25+
26+
**Screenshots**
27+
If applicable, add screenshots to help explain your problem.
28+
29+
**Desktop (please complete the following information):**
30+
- OS: [e.g. Windows]
31+
- OS version: [e.g. Windows 11 (x64)]
32+
- Python: [e.g. 3.13]
33+
- Dependencies: [e.g. numpy==1.26.4, tensorflow==2.x]
34+
- Environment (if relevant): [e.g. Docker, virtual environment, or native installation]
35+
36+
**Relevant Code snippet (if available):**
37+
```python
38+
# Prints out hello world
39+
print("Hello world")
40+
```
41+
42+
**Additional context**
43+
Add any other context about the problem here that you think could help.
44+
45+
---
46+
47+
> [!IMPORTANT]
48+
> Please do not share any personal information in this report.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: '[Brief descriptive title of the feature request]'
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? If so, please explain**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered (workarounds)**
17+
A clear and concise description of any alternative solutions or features you've considered. This is `optional`.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.
21+
22+
---
23+
24+
> [!IMPORTANT]
25+
> Please do not share any personal information in this report.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Publish Python 🐍 distributions 📦 to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
build-n-publish:
10+
name: Build and publish Python 🐍 distributions 📦 to PyPI
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@master
14+
- name: Set up Python 3.12
15+
uses: actions/setup-python@v3
16+
with:
17+
python-version: '3.12'
18+
- name: Install pypa/setuptools
19+
run: >-
20+
python -m
21+
pip install setuptools wheel
22+
- name: Extract tag name
23+
id: tag
24+
run: echo ::set-output name=TAG_NAME::$(echo $GITHUB_REF | cut -d / -f 3)
25+
- name: Update version in setup.py
26+
run: >-
27+
sed -i "s/{{VERSION_PLACEHOLDER}}/${{ steps.tag.outputs.TAG_NAME }}/g" setup.py
28+
- name: Build a binary wheel
29+
run: >-
30+
python setup.py sdist bdist_wheel
31+
- name: Publish distribution 📦 to PyPI
32+
uses: pypa/gh-action-pypi-publish@master
33+
with:
34+
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__pycache__
2+
*.pyc
3+
dist/
4+
build/
5+
venv/
6+
.venv/

CONTRIBUTING.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Contributing to LocalSiteMap
2+
3+
Thank you for considering contributing to **LocalSiteMap**! Contributions, whether they are bug fixes, new features, or improvements to the documentation, are always welcome. Before contributing, please read the following guidelines to ensure smooth collaboration.
4+
5+
## Getting Started
6+
7+
1. **Fork the Repository**
8+
Create a fork of this repository to your GitHub account and clone it locally.
9+
10+
2. **Set Up the Environment**
11+
Ensure you have Python 3.6+ installed. You should also install compatible versions of the necessary dependencies for the project.
12+
13+
3. **Run Tests**
14+
Before making changes, run tests to confirm that everything works.
15+
16+
> [!TIP]
17+
> We sometimes include testing scripts in our projects for easy testing.
18+
19+
## How to Contribute
20+
21+
1. **Report Issues**
22+
Use the [GitHub Issues page](https://github.com/Infinitode/LocalSiteMap/issues) to report bugs or suggest features. Please include:
23+
- A clear description of the issue or suggestion.
24+
- Steps to reproduce (for bugs).
25+
26+
2. **Make Changes**
27+
- Use clear and descriptive commit messages.
28+
- (Optional) Write tests to show new functionality.
29+
- Ensure the code is **readable**. You can learn more about Python code readability here: https://peps.python.org/pep-0008/.
30+
31+
3. **Submit a Pull Request**
32+
- Push your changes to a feature branch in your fork.
33+
- Submit a pull request with a detailed explanation of what you've changed or added.
34+
- Ensure your PR passes all automated tests and adheres to the contribution guidelines.
35+
36+
## Community Guidelines
37+
38+
To maintain a positive and collaborative community, we ask that all contributors adhere to the following principles:
39+
40+
1. **Be Respectful**
41+
Treat others with respect, regardless of their background or expertise.
42+
43+
2. **Provide Constructive Feedback**
44+
Offer helpful and actionable suggestions during code reviews.
45+
46+
3. **Follow Licensing Requirements**
47+
Ensure that any derivative works comply with the [license](https://github.com/infinitode/localsitemap/blob/main/LICENSE).
48+
49+
By contributing, you agree to abide by these guidelines and this project's [license](https://github.com/infinitode/localsitemap/blob/main/LICENSE). Thank you for helping make **LocalSiteMap** better!

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
MIT License (Modified)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to make derivative works based on the Software, provided that any substantial changes to the Software are clearly distinguished from the original work and are distributed under a different name.
4+
5+
The original copyright notice and disclaimer must be retained in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# LocalSiteMap
2+
![Python Version](https://img.shields.io/badge/python-3.13-blue.svg)
3+
[![Code Size](https://img.shields.io/github/languages/code-size/infinitode/localsitemap)](https://github.com/infinitode/localsitemap)
4+
![Downloads](https://pepy.tech/badge/localsitemap)
5+
![License Compliance](https://img.shields.io/badge/license-compliance-brightgreen.svg)
6+
![PyPI Version](https://img.shields.io/pypi/v/localsitemap)
7+
8+
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.
9+
10+
### Changes in version 1.0.0:
11+
- Added initial package code, with automatic directory crawling to generate the `sitemap.xml` file.
12+
13+
> [!IMPORTANT]
14+
> `LocalSiteMap` crawls any directory found in the root folder, be sure to add exclusions for important directories, or hidden/resource/file directories.
15+
16+
## Installation
17+
18+
You can install LocalSiteMap using pip:
19+
20+
```bash
21+
pip install localsitemap
22+
```
23+
24+
## Supported Python Versions
25+
26+
LocalSiteMap supports the following Python versions:
27+
28+
- Python 3.6
29+
- Python 3.7
30+
- Python 3.8
31+
- Python 3.9
32+
- Python 3.10
33+
- Python 3.11/Later (Preferred)
34+
35+
Please ensure that you have one of these Python versions installed before using LocalSiteMap. LocalSiteMap may not work as expected on lower versions of Python than the supported.
36+
37+
## Features
38+
39+
- **Directory Crawling**: `LocalSiteMap` automatically crawls all subdirectories and files under the root directory, recursively adding them to your sitemap.
40+
- **Automatic Last Modified Checks**: The package also automatically checks when the file has last been modified when adding it to the sitemap.
41+
- - **Customizable**: You can customize the sitemap generation process by excluding specific directories or files.
42+
- **Easy to Use**: With just a few lines of code, you can generate a complete sitemap for your local website.
43+
- **Open Source**: LocalSiteMap is open source, allowing you to inspect, modify, and contribute to the code.
44+
45+
## Usage
46+
47+
### Generating a sitemap
48+
49+
```python
50+
from localsitemap import generate_sitemap
51+
52+
# Root site directory
53+
root_directory = r"path/to/your/website/directory"
54+
55+
# Domain of your website (where it is hosted)
56+
base_url_of_your_website = "https://example.com"
57+
58+
# List of file paths or directories to exclude from the sitemap
59+
excluded = ["auth", "forms", "template.html", "media", ".git", ".vscode", "node_modules"] # Example exclusions
60+
61+
# Generate the sitemap
62+
generate_sitemap(root_directory, base_url_of_your_website, "sitemap.xml", excluded)
63+
print("Sitemap generated in sitemap.xml")
64+
```
65+
66+
## Contributing
67+
68+
Contributions are welcome! If you encounter any issues, have suggestions, or want to contribute to LocalSiteMap, please open an issue or submit a pull request on [GitHub](https://github.com/infinitode/localsitemap).
69+
70+
## License
71+
72+
LocalSiteMap is released under the terms of the **MIT License (Modified)**. Please see the [LICENSE](https://github.com/infinitode/localsitemap/blob/main/LICENSE) file for the full text.
73+
74+
**Modified License Clause**
75+
76+
The modified license clause grants users the permission to make derivative works based on the LocalSiteMap software. However, it requires any substantial changes to the software to be clearly distinguished from the original work and distributed under a different name.

localsitemap/__init__.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import os
2+
import datetime
3+
from xml.etree.ElementTree import Element, SubElement, tostring
4+
from xml.dom import minidom
5+
6+
def generate_sitemap(root_path, base_url, output_file="sitemap.xml", excluded_paths=None):
7+
"""
8+
Generates a sitemap XML file by crawling a directory structure.
9+
10+
Parameters:
11+
root_path: The root directory of your website.
12+
base_url: The base URL of your website (e.g., "https://example.com").
13+
output_file: The name of the output XML file (default: "sitemap.xml").
14+
excluded_paths: A list of file paths or directories to exclude from the sitemap.
15+
"""
16+
if excluded_paths is None:
17+
excluded_paths = []
18+
19+
urlset = Element("urlset")
20+
urlset.set("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9")
21+
urlset.set("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
22+
urlset.set("xsi:schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd")
23+
24+
for root, dirs, files in os.walk(root_path):
25+
# Add directories to the sitemap
26+
for dir_name in dirs:
27+
full_dir_path = os.path.join(root, dir_name)
28+
if any(excluded in full_dir_path for excluded in excluded_paths):
29+
continue
30+
relative_dir_path = os.path.relpath(full_dir_path, root_path)
31+
url = os.path.join(base_url, relative_dir_path).replace("\\", "/") + "/"
32+
lastmod = datetime.datetime.fromtimestamp(os.path.getmtime(full_dir_path)).isoformat()
33+
lastmod = lastmod[:lastmod.find(".")+4] + "+00:00"
34+
35+
url_entry = SubElement(urlset, "url")
36+
SubElement(url_entry, "loc").text = url
37+
SubElement(url_entry, "lastmod").text = lastmod
38+
SubElement(url_entry, "priority").text = "0.80"
39+
40+
for file in files:
41+
if file.endswith((".html", ".htm")):
42+
full_path = os.path.join(root, file)
43+
relative_path = os.path.relpath(full_path, root_path)
44+
45+
# Check if the file should be excluded
46+
if any(excluded in full_path for excluded in excluded_paths):
47+
continue
48+
49+
url = os.path.join(base_url, relative_path).replace("\\", "/")
50+
lastmod = datetime.datetime.fromtimestamp(os.path.getmtime(full_path)).isoformat()
51+
lastmod = lastmod[:lastmod.find(".")+4] + "+00:00"
52+
53+
url_entry = SubElement(urlset, "url")
54+
SubElement(url_entry, "loc").text = url
55+
SubElement(url_entry, "lastmod").text = lastmod
56+
SubElement(url_entry, "priority").text = "0.80"
57+
58+
# Add homepage to the sitemap
59+
url_entry = SubElement(urlset, "url")
60+
SubElement(url_entry, "loc").text = base_url
61+
lastmod = datetime.datetime.fromtimestamp(os.path.getmtime(root_path)).isoformat()
62+
lastmod = lastmod[:lastmod.find(".")+4] + "+00:00"
63+
SubElement(url_entry, "lastmod").text = lastmod
64+
SubElement(url_entry, "priority").text = "1.00"
65+
66+
# Write the XML to a file
67+
xml_string = tostring(urlset, "utf-8")
68+
reparsed = minidom.parseString(xml_string)
69+
pretty_xml = reparsed.toprettyxml(indent=" ")
70+
71+
with open(output_file, "w", encoding="utf-8") as f:
72+
f.write(pretty_xml)

setup.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from setuptools import setup, find_packages
2+
3+
with open("README.md", "r", encoding="utf-8") as fh:
4+
long_description = fh.read()
5+
6+
setup(
7+
name='localsitemap',
8+
version='{{VERSION_PLACEHOLDER}}',
9+
author='Infinitode Pty Ltd',
10+
author_email='infinitode.ltd@gmail.com',
11+
description="LocalSiteMap is an open-source Python library designed to make dataset analysis much easier by generating helpful detailed plots using matplotlib based on your dataset.",
12+
long_description=long_description,
13+
long_description_content_type='text/markdown',
14+
url='https://github.com/infinitode/localsitemap',
15+
packages=find_packages(),
16+
classifiers=[
17+
'Development Status :: 5 - Production/Stable',
18+
'Intended Audience :: Developers',
19+
'License :: OSI Approved :: MIT License',
20+
'Programming Language :: Python :: 3.6',
21+
'Programming Language :: Python :: 3.7',
22+
'Programming Language :: Python :: 3.8',
23+
'Programming Language :: Python :: 3.9',
24+
'Programming Language :: Python :: 3.10',
25+
'Programming Language :: Python :: 3.11',
26+
'Programming Language :: Python :: 3.12',
27+
'Programming Language :: Python :: 3.13',
28+
],
29+
python_requires='>=3.6',
30+
install_requires=[
31+
'matplotlib>=3.0.0',
32+
'pandas>=1.0.0',
33+
'numpy>=1.18.0'
34+
],
35+
)

test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from localsitemap import generate_sitemap
2+
3+
# Example usage
4+
root_directory = r"path/to/your/website/directory"
5+
6+
# Domain of your website (where it is hosted)
7+
base_url_of_your_website = "https://example.com"
8+
9+
# List of file paths or directories to exclude from the sitemap
10+
excluded = ["auth", "forms", "template.html", "media", ".git", ".vscode", "node_modules"] # Example exclusions
11+
12+
# Generate the sitemap
13+
generate_sitemap(root_directory, base_url_of_your_website, "sitemap.xml", excluded)
14+
print("Sitemap generated in sitemap.xml")

0 commit comments

Comments
 (0)