Add sitemap.py#14
Conversation
📝 WalkthroughWalkthroughA new 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
| 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 | ||
| }) |
There was a problem hiding this comment.
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)
| def generate_json(self) -> str: | ||
| """生成 JSON 格式(供前端使用)""" | ||
| return json.dumps({ | ||
| "generated_at": datetime.now().isoformat(), | ||
| "total_urls": len(self.urls), | ||
| "urls": self.urls | ||
| }, indent=2) |
There was a problem hiding this comment.
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)
| 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) | ||
|
|
There was a problem hiding this comment.
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.
| 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)
No description provided.