360 Secure SkillHub
360 安全技能中心

md-web

把本地或对话中的 Markdown 上传到用户自有 S3 兼容存储桶的 md-web/ 目录,由桶内 Docsify 查看器渲染为公开链接;并提供查看器初始化、生命周期过期策略、凭据配置与错误排查流程。

分类:自动化
rockbenben
rockbenben
热度 81.93
最近更新 2026-12-02 14:04:08

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add rockbenben/md-web
兼容性
通用兼容
联网要求
需要联网
数据出网
必须出网
Metadata
name
md-web
description
Publish raw Markdown to a public Docsify link in the user's S3-compatible bucket, or set up its shared viewer, on explicit request. 发布 Markdown 公开链接、初始化或更新查看器。
metadata
{"version":"1.3.15","openclaw":{"homepage":"https://github.com/rockbenben/aishort-skills/tree/main/skills/md-web","emoji":"🌐","requires":{"bins":["node"]},"envVars":[{"name":"MD_WEB_ACCESS_KEY","required":false,"description":"Bucket access key fallback when access_key is omitted from config.json."},{"name":"MD_WEB_SECRET_KEY","required":false,"description":"Bucket secret key fallback when secret_key is omitted from config.json."}],"files":["upload.js","docsify-server/**"]}}

MD Web — Publish Raw Markdown to S3/Docsify

Upload one raw .md file to the user's S3-compatible bucket under md-web/; a Docsify viewer in that bucket renders it at a public URL. {SKILL_DIR} is this skill's directory — always substitute the real path and quote all path arguments.

Authorization & Security Guardrails

  • Public publish gate: Only an explicit request for online publication or a public/shareable link authorizes uploading (including retries). Inform the user that the link is public before uploading; resolve ambiguous sharing scope first, review and redact out-of-scope sensitive content, and publish raw Markdown (do not convert to HTML).
  • Shared viewer setup gate (--setup): --setup uploads assets/<bundle-hash>/ and replaces shared bucket-root README.md and index.html (old assets remain for cached pages; existing document URLs stay valid). Explain affected root paths and obtain explicit authorization before running --setup --confirm-shared-writes unless already authorized in this task. Never pass --confirm-shared-writes merely to bypass an error.
  • Retention policy gate (expire_days): Setting, changing, or removing (0) expire_days modifies the bucket's lifecycle policy (scoped to one md-web/ rule while preserving other rules). Omit expire_days unless explicitly requested, and obtain authorization before changing it.
  • Credentials & untrusted HTML: Config and deployment hints live in ~/.md-web/config.json and ~/.md-web/.deployed (legacy adjacent config migrates automatically with 0700/0600 permissions on macOS/Linux; Windows relies on user directory ACLs or MD_WEB_ACCESS_KEY / MD_WEB_SECRET_KEY env vars; no root/elevated privileges are ever needed). Keep secrets out of chat, version control, and shared output; prefer a dedicated bucket. The viewer renders inline HTML — its CSP blocks inline scripts and its route guard restricts loads to same-origin md-web/, but page elements are not sanitized, so review unfamiliar markup before publishing.

Workflow

1. Check Configuration

Check ~/.md-web/config.json (%USERPROFILE%\.md-web\config.json on Windows).

  • If the user config exists, use it and fill in any missing required fields. The script checks this file first.
  • If it is absent, upload.js migrates a legacy config.json beside the script on the next setup or publish. If neither file exists, follow First-Time Configuration below.

2. Prepare Markdown Input

Use the user's existing .md file, or write chat content to a unique scratch file in the OS temp directory (/tmp/, $TEMP, %TEMP%, or $env:TEMP) and delete only that temp file after the upload attempt (never modify or delete a user file).

Viewer constraints to respect before uploading:

  • Start with # Title (sets browser tab title); YAML front matter is stripped automatically (document must be non-empty afterward).
  • Only the .md file is uploaded — use absolute https:// URLs for images (relative paths break).
  • GFM, tables, <details>, and inline HTML render; Mermaid and LaTeX/KaTeX do not render (use tables, lists, or images instead).

3. Publish (and Setup If Prompted)

node "{SKILL_DIR}/upload.js" "<local-file>" "<remote-key>"
  • <remote-key>: short lowercase ASCII slug (e.g. api-docs, even for Chinese docs; non-ASCII collapses to doc). The script adds timestamp + random suffix + .md under md-web/ so re-publishing always creates a new link.
  • Handling setup & lifecycle signals:
    • SETUP_REQUIRED: Obtain viewer-setup authorization per guardrails above, run setup, then retry the same publish command:
      node "{SKILL_DIR}/upload.js" --setup --confirm-shared-writes
      
      Setup also applies expire_days (note: publishing does not detect expire_days changes; run setup after editing expire_days, upgrading the viewer, or switching bucket/endpoint).
    • SETUP_CONFLICT: A concurrent setup changed index.html or the S3 provider lacks ETag/conditional write support (If-Match / If-None-Match). Inspect the active viewer before retrying; never force-overwrite.
    • Warning: lifecycle —: Viewer setup succeeded, but retention was not confirmed (missing lifecycle permission, unsupported/incomplete XML, rule conflict, or concurrent edit). Serialize lifecycle changes with other admins, inspect actual bucket policy, and do not blindly broaden credentials.

4. Reply & Error Triage

  • Success: Last stdout line is the public URL. Reply with document title/slug, clickable link, and any material setup/retention warning (do not dump the full doc unless asked).
  • Failure: Report the cause and the recovery step. Link to the existing local Markdown when available. For a document composed in chat, return the prepared text if the user still needs a copy.
Error contains Likely cause & fix
SignatureDoesNotMatch, InvalidAccessKeyId Wrong credentials or wrong region (auto for R2; exact region for AWS)
AccessDenied on upload Token lacks Object Read & Write or is scoped to another bucket
NoSuchBucket Typo in bucket or wrong account endpoint
CONFIG_MISSING Follow First-Time Configuration to create the user config.
CONFIG_INVALID Follow the specific diagnostic. For a JSON error, repair the existing file locally as a JSON object. Preserve its fields and keep credential values out of logs.
ENOTFOUND or invalid endpoint/URL Check the S3 API hostname in endpoint and the viewer's HTTP(S) address in public_url (prefer HTTPS).
Missing config fields Complete config.json or export MD_WEB_ACCESS_KEY / MD_WEB_SECRET_KEY
Page shows "Looking for a document?" Document expired (expire_days) or public_url points to another bucket

First-Time Configuration

  1. Explain that an S3-compatible bucket with public read access is required; reference README.md (中文) for R2/S3/B2/Spaces/Wasabi/COS steps.
  2. Gather required fields (endpoint without https://, bucket, public_url — custom domain recommended over rate-limited r2.dev — and access_key / secret_key with Object Read & Write). Offer that the user edit ~/.md-web/config.json directly or export MD_WEB_ACCESS_KEY / MD_WEB_SECRET_KEY (file takes precedence if both exist) to keep secrets out of chat.
  3. Optional fields: region (default auto; AWS needs real region e.g. us-east-1), expire_days (omit unless requested; requires provider lifecycle permission — R2 Admin Read & Write or AWS PutBucketLifecycleConfiguration).
  4. Create ~/.md-web/ (0700 on macOS/Linux) and write ~/.md-web/config.json (0600 before writing secrets):
    {
      "access_key": "...",
      "secret_key": "...",
      "endpoint": "ACCOUNT_ID.r2.cloudflarestorage.com",
      "bucket": "md-web",
      "region": "auto",
      "public_url": "https://pub-XXXX.r2.dev"
    }
    
  5. Run --setup --confirm-shared-writes when viewer setup is authorized. Continue to document upload only if the user also requested publication.