diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ede195a..a3d368f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,4 @@ jobs: - name: Install local package (plugins) run: uv pip install -e . - - name: Fix RSS plugin template - run: uv run python fix_rss_template.py - - run: uv run mkdocs gh-deploy --force \ No newline at end of file diff --git a/fix_rss_template.py b/fix_rss_template.py deleted file mode 100755 index 0a2fca0..0000000 --- a/fix_rss_template.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python3 -"""Patch mkdocs-rss-plugin template to fix RSS validation errors. - -Run this before `mkdocs build` to apply fixes. Idempotent - safe to run repeatedly. - -Fixes: -1. -> (RSS spec requires to be an email address) -2. Skip when length is None or non-positive (remote image 404) -3. Fix double-encoded HTML entities in title (MkDocs pre-escapes, |e escapes again) - -Usage: - python fix_rss_template.py - mkdocs build -""" -import sys -from pathlib import Path - -# Patched template content - full replacement for reliability -PATCHED_TEMPLATE = ''' - - - {# Mandatory elements #} - {% if feed.title is not none %}{{ feed.title|e }}{% endif %} - {% if feed.description is not none %}{{ feed.description|e }}{% endif %} - {% if feed.html_url is not none %}{{ feed.html_url }}{% endif %} - {% if feed.rss_url is not none %}{% endif %} - - {# Optional elements #} - {% if feed.author is not none %}{{ feed.author | e }}{% endif %} - {% if feed.repo_url is not none %}{{ feed.repo_url }}{% endif %} - {% if feed.language is not none %}{{ feed.language }}{% endif %} - - {# Timestamps and frequency #} - {{ feed.pubDate }} - {{ feed.buildDate }} - {{ feed.ttl }} - - {# Credits #} - {{ feed.generator }} - - {# Feed illustration #} - {% if feed.logo_url is defined %} - - {{ feed.logo_url }} - {{ feed.title }} - {% if feed.html_url is not none %}{{ feed.html_url }}{% endif %} - - {% endif %} - - {# Entries #} - {% for item in feed.entries %} - - {{ item.title|e|replace('&amp;', '&')|replace('&lt;', '<')|replace('&gt;', '>') }} - {# Authors loop - use dc:creator for names (RSS requires email) #} - {% if item.authors is not none %} - {% for author in item.authors %} - {{ author }} - {% endfor %} - {% endif %} - {# Categories loop #} - {% if item.categories is not none %} - {% for categorie in item.categories %} - {{ categorie }} - {% endfor %} - {% endif %} - {{ item.description|e|replace('&amp;', '&')|replace('&lt;', '<')|replace('&gt;', '>') }} - {% if item.link is not none %}{{ item.link|e }}{% endif %} - {{ item.pub_date }} - {% if item.link is not none %}{{ feed.title }}{% endif %} - {% if item.comments_url is not none %}{{ item.comments_url|e }}{% endif %} - {% if item.guid is not none %}{{ item.guid }}{% endif %} - {% if item.image is not none and item.image[2] is not none and item.image[2] > 0 %} - - {% endif %} - - {% endfor %} - - -''' - -def find_template_path(): - """Find the mkdocs-rss-plugin template file dynamically.""" - # Method 1: Import the plugin module - try: - import mkdocs_rss_plugin - plugin_dir = Path(mkdocs_rss_plugin.__file__).parent - template_path = plugin_dir / "templates" / "rss.xml.jinja2" - if template_path.exists(): - return template_path - except ImportError: - pass - - # Method 2: Search common virtualenv locations - base = Path(__file__).parent - for python_ver in ("python3.13", "python3.12", "python3.11", "python3.10"): - candidate = base / ".venv" / "lib" / python_ver / "site-packages" / "mkdocs_rss_plugin" / "templates" / "rss.xml.jinja2" - if candidate.exists(): - return candidate - - return None - -def main(): - template_path = find_template_path() - - if template_path is None: - print("ERROR: Could not find mkdocs-rss-plugin template.", file=sys.stderr) - print("Make sure the virtualenv is activated or the plugin is installed.", file=sys.stderr) - sys.exit(1) - - current_content = template_path.read_text() - - # Normalize whitespace for comparison (template may be minified or reformatted) - if PATCHED_TEMPLATE.strip() == current_content.strip(): - print(f"Already patched: {template_path}") - sys.exit(0) - - template_path.write_text(PATCHED_TEMPLATE) - print(f"Patched: {template_path}") - print(" - -> (RSS 2.0 compliance)") - print(" - enclosure length guard added (handles None values)") - print(" - fixed double-encoded HTML entities in title") - -if __name__ == "__main__": - main() diff --git a/pyproject.toml b/pyproject.toml index 4228ebe..cf43753 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ dependencies = [ "click==8.2.1", "mkdocs-material[imaging]>=9.7.6", "mkdocs-redirects>=1.2.2", - "mkdocs-rss-plugin>=1.17.1", + "mkdocs-rss-plugin @ git+https://github.com/Zerthick/mkdocs-rss-plugin.git@fix/rss-validation-errors", ] [project.optional-dependencies] diff --git a/uv.lock b/uv.lock index e2eca49..7429580 100644 --- a/uv.lock +++ b/uv.lock @@ -236,7 +236,7 @@ requires-dist = [ { name = "mdformat-mkdocs", marker = "extra == 'dev'", specifier = ">=3.0.1" }, { name = "mkdocs-material", extras = ["imaging"], specifier = ">=9.7.6" }, { name = "mkdocs-redirects", specifier = ">=1.2.2" }, - { name = "mkdocs-rss-plugin", specifier = ">=1.17.1" }, + { name = "mkdocs-rss-plugin", git = "https://github.com/Zerthick/mkdocs-rss-plugin.git?rev=fix%2Frss-validation-errors" }, { name = "pre-commit", marker = "extra == 'dev'", specifier = ">=4.2.0" }, ] provides-extras = ["dev"] @@ -582,8 +582,8 @@ wheels = [ [[package]] name = "mkdocs-rss-plugin" -version = "1.19.0" -source = { registry = "https://pypi.org/simple" } +version = "1.19.1.dev19" +source = { git = "https://github.com/Zerthick/mkdocs-rss-plugin.git?rev=fix%2Frss-validation-errors#100f2768060ae6963086b79f8480684fd1a7bea0" } dependencies = [ { name = "cachecontrol", extra = ["filecache"] }, { name = "gitpython" }, @@ -592,10 +592,6 @@ dependencies = [ { name = "requests" }, { name = "tzdata", marker = "sys_platform == 'win32'" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/22/e8/70055ec6d7105c0f7c84918e0f98180443b5065469b2877aca43067a5709/mkdocs_rss_plugin-1.19.0.tar.gz", hash = "sha256:0b9b7f14688393e5bd7d26a6dc14dfd2b228a8cdfe5b598a6677589b2159d957", size = 573045, upload-time = "2026-04-17T09:35:34.115Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/9f/00/1f2144fad080706c1ebebef83b7b5c0f8d80f9a2a06b33baabb94e33c84e/mkdocs_rss_plugin-1.19.0-py3-none-any.whl", hash = "sha256:5fdaffdee96745011c7c7786ed52b42a2d751f3aad84c188ffbedeb5a6e2994a", size = 33252, upload-time = "2026-04-17T09:35:32.372Z" }, -] [[package]] name = "more-itertools"