diff --git a/.github/workflows/sync_build_deploy.yml b/.github/workflows/sync_build_deploy.yml index c2007f7..124b710 100644 --- a/.github/workflows/sync_build_deploy.yml +++ b/.github/workflows/sync_build_deploy.yml @@ -61,6 +61,7 @@ jobs: - name: Install dependencies run: pip install -r util/requirements.txt + # New added modules - name: Add module if: ${{ (github.event.inputs.repo_user != '') && (github.event.inputs.repo_name != '') }} run: | @@ -69,11 +70,10 @@ jobs: - name: Commit module if: ${{ (github.event.inputs.repo_user != '') && (github.event.inputs.repo_name != '') }} run: | - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" git add modules git commit -sm "[MODULE] ${{ github.event.inputs.repo_name }}" || true git push || true + #### - name: Sync if: ${{ env.IS_SYNC == 'true' }} @@ -102,6 +102,20 @@ jobs: run: | python util/cli.py index --push + # Sitemap generator + - name: Generate sitemap + if: ${{ env.IS_SYNC == 'true' }} + run: | + python generate_sitemap.py + + - name: Commit sitemap + if: ${{ env.IS_SYNC == 'true' }} + run: | + git add json/sitemap.xml + git commit -sm "[SITEMAP] Update sitemap.xml" || true + git push || true + #### + - name: Upload logs uses: actions/upload-artifact@v3 with: diff --git a/generate_sitemap.py b/generate_sitemap.py new file mode 100644 index 0000000..7b2bde8 --- /dev/null +++ b/generate_sitemap.py @@ -0,0 +1,45 @@ +import json +import xml.etree.ElementTree as ET +from xml.dom import minidom +from datetime import datetime + +# Open modules.json +with open('json/modules.json') as json_data: + data = json.load(json_data) + +# Access the "modules" object +modules = data.get("modules", []) + +# Create the root element for the sitemap +urlset = ET.Element("urlset", xmlns="http://www.sitemaps.org/schemas/sitemap/0.9") + +# Base URL for the modules +base_url = "http://mmrl.dergoogler.com/?module=" + +# Add URLs to the sitemap +for module in modules: + + # Convert Unix timestamp to datetime object + dt_object = datetime.utcfromtimestamp(module["timestamp"]) + + # Format the datetime object as 'YYYY-MM-DD' + formatted_date = dt_object.strftime('%Y-%m-%d') + + module_id = module["id"] + url = base_url + module_id + url_element = ET.SubElement(urlset, "url") + loc_element = ET.SubElement(url_element, "loc") + lastmod_element = ET.SubElement(url_element, "lastmod") + lastmod_element.text = formatted_date + loc_element.text = url + +# Convert the ElementTree to a string +sitemap = ET.tostring(urlset, encoding="utf-8", method="xml") + +xmlstr = minidom.parseString(sitemap).toprettyxml(indent=" ") + +# Write to a file +with open("json/sitemap.xml", "w") as f: + f.write(xmlstr) + +print("Sitemap generated successfully.")