AgentSkillsCN

fetch-url-md

使用 curl 自动检测 Markdown 版本,抓取网页内容。适用于 Claude 需要从同时提供 HTML 和 Markdown 格式的网站中获取文档时使用。首先检查是否存在 .md 版本(更高效、更简洁),若不可用则回退至 HTML。特别适合从 ui.shadcn.com、GitHub Wiki,或任何以 Markdown 格式同步内容的文档站点中抓取文档。

SKILL.md
--- frontmatter
name: fetch-url-md
description: Fetch web content with automatic markdown version detection using curl. Use when Claude needs to retrieve documentation from websites that offer both HTML and markdown formats. First checks if a .md version exists (more efficient and cleaner), then falls back to HTML if unavailable. Ideal for fetching documentation from sites like ui.shadcn.com, GitHub wikis, or any documentation site that mirrors content in markdown format.

Fetch URL with Markdown Detection

Overview

Efficiently fetch web content by prioritizing markdown versions when available. Uses curl to check for .md versions first, then falls back to the original URL.

Workflow

Follow these steps sequentially:

1. Parse the original URL

Extract the base URL and path from the user-provided URL.

Example:

  • Input: https://ui.shadcn.com/docs/components/radix/aspect-ratio
  • Markdown URL: https://ui.shadcn.com/docs/components/radix/aspect-ratio.md

2. Check for .md version

Use curl with HEAD request to check if .md version exists:

bash
curl -sI "https://ui.shadcn.com/docs/components/radix/aspect-ratio.md" | head -n 1
  • 200 OK - Markdown version exists, fetch it
  • 404 Not Found - Markdown version doesn't exist, use original URL
  • 3xx redirect - Follow the redirect or use original URL

3. Fetch content

If .md exists:

bash
curl -s "https://ui.shadcn.com/docs/components/radix/aspect-ratio.md"

If .md doesn't exist (fallback):

bash
curl -s "https://ui.shadcn.com/docs/components/radix/aspect-ratio"

Decision Tree

code
User provides URL
       │
       ▼
Construct .md URL (append .md)
       │
       ▼
curl -sI <markdown-url> | head -n 1
       │
   ┌───┴───┐
   │       │
200 OK   404/Other
   │       │
   ▼       ▼
Fetch    Fetch original
.md      HTML URL

Quick Reference

Check CommandFetch Command
curl -sI "<url>.md" | head -n 1curl -s "<url>.md"
curl -sI "<url>" | head -n 1curl -s "<url>"

Examples

Example 1: Markdown version available

bash
# Check
curl -sI "https://ui.shadcn.com/docs/components/radix/aspect-ratio.md" | head -n 1
# Output: HTTP/2 200

# Fetch
curl -s "https://ui.shadcn.com/docs/components/radix/aspect-ratio.md"

Example 2: Markdown version not available

bash
# Check
curl -sI "https://example.com/docs/guide.md" | head -n 1
# Output: HTTP/2 404

# Fallback - fetch original
curl -s "https://example.com/docs/guide"