Skip to content

Add sitemap.py#14

Open
renshichu wants to merge 1 commit into
ubiquity:mainfrom
renshichu:feat/dynamic-sitemap
Open

Add sitemap.py#14
renshichu wants to merge 1 commit into
ubiquity:mainfrom
renshichu:feat/dynamic-sitemap

Conversation

@renshichu

Copy link
Copy Markdown

No description provided.

@coderabbitai

coderabbitai Bot commented Apr 11, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

A new scripts/sitemap.py file was added containing a SitemapGenerator class that builds sitemaps from app and plugin entries. The class provides methods to add apps and plugins with metadata including location, last modified date, change frequency, and priority. It generates output in two formats: XML following sitemap.org 0.9 specification and JSON with generation timestamp and URL count. A main() function populates the generator with sample data, outputs the XML to stdout, and writes it to sitemap.xml.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No description was provided by the author, so the description is empty rather than being related to or unrelated to the changeset. Add a brief description explaining the purpose of the sitemap generator and how it should be used.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add sitemap.py' directly and specifically describes the main change: adding a new sitemap generation script.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ece0198a-e2c5-4f3e-991d-cfa6cef1d384

📥 Commits

Reviewing files that changed from the base of the PR and between a2634c5 and 2f24d02.

📒 Files selected for processing (1)
  • scripts/sitemap.py

Comment thread scripts/sitemap.py
Comment on lines +18 to +38
def add_app(self, app_id: str, name: str, updated: datetime = None, priority: float = 0.8):
"""添加 App 页面"""
self.urls.append({
"loc": f"{self.base_url}/apps/{app_id}",
"lastmod": (updated or datetime.now()).strftime("%Y-%m-%d"),
"changefreq": "weekly",
"priority": priority,
"type": "app",
"name": name
})

def add_plugin(self, plugin_id: str, name: str, updated: datetime = None, priority: float = 0.7):
"""添加 Plugin 页面"""
self.urls.append({
"loc": f"{self.base_url}/plugins/{plugin_id}",
"lastmod": (updated or datetime.now()).strftime("%Y-%m-%d"),
"changefreq": "weekly",
"priority": priority,
"type": "plugin",
"name": name
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Validate identifiers and priority before adding URLs.

app_id / plugin_id are inserted directly into URL paths, and priority is unchecked. Invalid IDs or out-of-range priority values can produce invalid sitemap records.

Suggested hardening
+from urllib.parse import quote
+
 class SitemapGenerator:
@@
     def add_app(self, app_id: str, name: str, updated: datetime = None, priority: float = 0.8):
         """添加 App 页面"""
+        if not 0.0 <= priority <= 1.0:
+            raise ValueError("priority must be between 0.0 and 1.0")
         self.urls.append({
-            "loc": f"{self.base_url}/apps/{app_id}",
+            "loc": f"{self.base_url}/apps/{quote(app_id, safe='')}",
@@
     def add_plugin(self, plugin_id: str, name: str, updated: datetime = None, priority: float = 0.7):
         """添加 Plugin 页面"""
+        if not 0.0 <= priority <= 1.0:
+            raise ValueError("priority must be between 0.0 and 1.0")
         self.urls.append({
-            "loc": f"{self.base_url}/plugins/{plugin_id}",
+            "loc": f"{self.base_url}/plugins/{quote(plugin_id, safe='')}",
🧰 Tools
🪛 Ruff (0.15.9)

[warning] 18-18: PEP 484 prohibits implicit Optional

Convert to T | None

(RUF013)


[warning] 29-29: PEP 484 prohibits implicit Optional

Convert to T | None

(RUF013)

Comment thread scripts/sitemap.py
Comment on lines +65 to +71
def generate_json(self) -> str:
"""生成 JSON 格式(供前端使用)"""
return json.dumps({
"generated_at": datetime.now().isoformat(),
"total_urls": len(self.urls),
"urls": self.urls
}, indent=2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Align JSON schema with existing JsonPluginMap contract.

generate_json() emits generated_at/total_urls/urls, which does not match src/types.ts (Line 63-69) JsonPluginMap (version/generated/generator/totalPlugins/plugins). This will break typed consumers expecting the existing schema.

🧰 Tools
🪛 Ruff (0.15.9)

[warning] 66-66: Docstring contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean ( (LEFT PARENTHESIS)?

(RUF002)


[warning] 66-66: Docstring contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean ) (RIGHT PARENTHESIS)?

(RUF002)

Comment thread scripts/sitemap.py
Comment on lines +74 to +97
def main():
# 示例:生成站点地图
generator = SitemapGenerator()

# 添加 Apps
apps = [
("payment-processor", "Payment Processor"),
("wallet-connect", "Wallet Connect"),
("nft-minter", "NFT Minter"),
]

for app_id, name in apps:
generator.add_app(app_id, name)

# 添加 Plugins
plugins = [
("analytics", "Analytics Plugin"),
("auth-connector", "Auth Connector"),
("ipfs-uploader", "IPFS Uploader"),
]

for plugin_id, name in plugins:
generator.add_plugin(plugin_id, name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Replace hardcoded entries with config-driven input.

main() currently hardcodes sample apps/plugins, so generated sitemap data will drift from real routing/plugin config. This breaks the “dynamic sitemap” objective and conflicts with the documented local-config approach in docs/deno-only-simplification.md (Line 37-48).

Suggested change
-def main():
-    # 示例:生成站点地图
-    generator = SitemapGenerator()
-
-    # 添加 Apps
-    apps = [
-        ("payment-processor", "Payment Processor"),
-        ("wallet-connect", "Wallet Connect"),
-        ("nft-minter", "NFT Minter"),
-    ]
-
-    for app_id, name in apps:
-        generator.add_app(app_id, name)
-
-    # 添加 Plugins
-    plugins = [
-        ("analytics", "Analytics Plugin"),
-        ("auth-connector", "Auth Connector"),
-        ("ipfs-uploader", "IPFS Uploader"),
-    ]
-
-    for plugin_id, name in plugins:
-        generator.add_plugin(plugin_id, name)
+def main(apps, plugins):
+    generator = SitemapGenerator()
+    for app_id, name in apps:
+        generator.add_app(app_id, name)
+    for plugin_id, name in plugins:
+        generator.add_plugin(plugin_id, name)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def main():
# 示例:生成站点地图
generator = SitemapGenerator()
# 添加 Apps
apps = [
("payment-processor", "Payment Processor"),
("wallet-connect", "Wallet Connect"),
("nft-minter", "NFT Minter"),
]
for app_id, name in apps:
generator.add_app(app_id, name)
# 添加 Plugins
plugins = [
("analytics", "Analytics Plugin"),
("auth-connector", "Auth Connector"),
("ipfs-uploader", "IPFS Uploader"),
]
for plugin_id, name in plugins:
generator.add_plugin(plugin_id, name)
def main(apps, plugins):
generator = SitemapGenerator()
for app_id, name in apps:
generator.add_app(app_id, name)
for plugin_id, name in plugins:
generator.add_plugin(plugin_id, name)
🧰 Tools
🪛 Ruff (0.15.9)

[warning] 75-75: Comment contains ambiguous (FULLWIDTH COLON). Did you mean : (COLON)?

(RUF003)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant