SuperAPI AI Directory

csdn-article-publish

Writing & research

View repository

Updated 10-16 01:28

About this skill

CSDN Blog Article Publish Skills

Skill Overview

  • Supports reading the content of a Markdown file in a specified directory and saving it as a CSDN draft
  • Generate a Markdown article and save it to a local file
  • Save a Markdown article as a CSDN draft
  • Supports local pre-validation, checking for missing configuration items, title, number of tags, abstract length, required fields for publishing, and other issues before sending the request
  • Automatically maintain the local article mapping file csdn_article_map.json, recording file -> articleId -> url
  • Update an article based on the article ID or a Markdown file that has been saved before
  • Publish an article (requires additional fields)

⚠️ Important Notes

  • Rate limiting prevention: CSDN has an API rate limiting mechanism, please do not call the API frequently
  • Recommended operations:
    • The interval between a single save/update operation should be at least 5-10 seconds
    • It is recommended to save/update no more than 5 articles per day
    • Appropriately increase the interval time during batch operations
    • Prefer using draft status, and publish only after confirming there are no errors

Usage Flow

Step 1: Configure request headers

Determine whether the following exists in the current directory: csdn_config.json file, if the file does not exist, please copy config/config_example.jsonto the working directory and rename it to csdn_config.json, the file needs to be modified by the user according to the example document, and the request header information should be filled in: config_example.json

How to obtain request headers

  1. Log in to CSDN and open https://editor.csdn.net/md/ Markdown-style article editor
  2. Fill in the title and content, and click Save as Draft
  3. Open the browser developer tools (F12)
  4. Switch to the Network tab
  5. Find the saveArticle request, right-click → Copy → Copy as cURL
  6. Extract the following request headers from the curl command:
    • Cookie: User login Cookie
    • x-ca-nonce: Unique request identifier (UUID)
    • x-ca-signature: Signature
    • x-ca-signature-headers: Signature header list
    • x-ca-key: API Key

Configuration file format

{
  "headers": {
    "Cookie": "用户Cookie",
    "x-ca-nonce": "UUID",
    "x-ca-signature": "签名",
    "x-ca-signature-headers": "x-ca-key,x-ca-nonce",
    "x-ca-key": "API Key"
  },
  "defaults": {
    "readType": "public",
    "type": "original",
    "pubStatus": "draft",
    "creation_statement": 0,
    "tags": "",
    "categories": ""
  }
}

For detailed field descriptions, see config_example.json

The script will perform local validation before sending the request:

  • Check whether required request headers are missing or still have example values
  • Check whether the Cookie is obviously incomplete
  • Check whether x-ca-signature-headers contains x-ca-key,x-ca-nonce
  • Check whether the default configuration's readType、type、pubStatus、creation_statement is valid

Step 2: Generate a Markdown article

  1. Generate article content according to user requirements (Markdown format)
  2. Save to the following in the current working directory: csdnarticle/ folder
  3. File naming suggestion:{文章标题}.md
# 确保 csdnarticle 目录存在
mkdir -p csdnarticle

Step 3: Save the draft

Save a local Markdown file as a CSDN draft:

# 方式1:通过 --file 参数指定 Markdown 文件(推荐)
node {skills目录}/scripts/csdn_article.js save \
  --title "Python 异步编程实战" \
  --file csdnarticle/Python异步编程实战.md

# 方式2:通过 --content 参数直接传递内容
node {skills目录}/scripts/csdn_article.js save \
  --title "Python 异步编程实战" \
  --content "# Python 异步编程实战\n\n## 简介\n\n本文介绍Python异步编程..."

# 方式3:仅使用 --file 参数,自动提取文件名作为标题
node {skills目录}/scripts/csdn_article.js save \
  --file csdnarticle/Python异步编程实战.md

Parameter description:

  • --title: Article title (optional when using --file; if not provided, the file name is used)
  • --content: Markdown content (choose one of this and --file)
  • --file: Markdown file path (choose one of this and --content; recommended)
  • --config: Configuration file path (default: csdn_config.json)

When using --file after a successful save, the script will generate csdn_article_map.jsonin the current working directory, recording the article ID and URL corresponding to that Markdown file. The original --id parameter is still retained, and subsequently update / publish can either continue to explicitly pass --id, or reuse this mapping.

Step 4: Check the draft

Guide the user to check in the CSDN editor whether the article layout, formatting, and content are correct, and after confirming there are no issues, proceed to the next step.

Step 5: Publish the article (if publishing is needed)

Use the publish command, passing the publish configuration through the --extra parameter:

node {skills目录}/scripts/csdn_article.js publish \
  --id 159048943 \
  --title "Python 异步编程实战" \
  --file csdnarticle/Python异步编程实战.md \
  --extra '{"tags":"python,async","readType":"public","type":"original","creation_statement":1,"description":"Python 异步编程实战发布摘要"}'

--extra parameter description:

Field Description Optional values
tags Tags (comma-separated, up to 5) python,async
readType Visibility scope public (default), private, read_need_fans, read_need_vip
type Article type original (default), repost, translated
creation_statement Creation statement 0=no statement (default), 1=part of the content is AI-assisted, 2=content is integrated and created from online sources, 3=personal opinion, for reference only
description Article summary (maximum 256 characters) -

For detailed API parameters, see api_reference.md

Local pre-validation

The script will intercept the following common issues before sending the request and provide repair suggestions:

  • Missing configuration item: missing Cookie、x-ca-nonce、x-ca-signature、x-ca-signature-headers、x-ca-key
  • Configuration placeholder not replaced: still retains your_cookie_here、xxxxxx and other example values
  • Empty title: --title not provided and the filename cannot generate a title
  • Too many tags:tags exceeds 5
  • Summary too long:description exceeds 256 characters
  • Missing publish field:publish mode does not provide a summary, or the publish enum value is invalid
  • Update/publish cannot find the article: neither --idwas passed, nor is there a reusable local mapping

Local article mapping file

  • Filename:csdn_article_map.json
  • Generation timing: when using save / update / publish and passing in --file and after a successful request
  • Purpose: record the correspondence between the Markdown file and the article ID and article URL
  • Effect: when subsequently executing update / publish , if the same --filecontinues to be used, you can continue to explicitly pass --id, or you can omit --id and switch to automatically reusing the mapping

Example:

# 首次保存,生成本地映射
node {skills目录}/scripts/csdn_article.js save \
  --file csdnarticle/Python异步编程实战.md

# 之后基于同一个文件更新,既可以继续传 --id,也可以直接复用映射
node {skills目录}/scripts/csdn_article.js update \
  --id 159048943 \
  --file csdnarticle/Python异步编程实战.md

# 或者省略 --id,自动从本地映射读取
node {skills目录}/scripts/csdn_article.js update \
  --file csdnarticle/Python异步编程实战.md

# 发布时同样既支持显式传 --id,也支持直接复用映射
node {skills目录}/scripts/csdn_article.js publish \
  --id 159048943 \
  --file csdnarticle/Python异步编程实战.md \
  --extra '{"tags":"python,async","description":"Python 异步编程的实战经验总结","creation_statement":1}'

# 或者省略 --id,自动从本地映射读取
node {skills目录}/scripts/csdn_article.js publish \
  --file csdnarticle/Python异步编程实战.md \
  --extra '{"tags":"python,async","description":"Python 异步编程的实战经验总结","creation_statement":1}'

Directory structure

csdn-article-publish/
├── SKILL.md                          # 技能说明文档
├── scripts/
│   └── csdn_article.js              # Node.js 脚本(核心执行脚本)
├── config/
│   ├── config_example.json           # 用户配置文件示例
│   └── user_agents.json             # 随机User-Agent列表
└── references/
  ├── api_reference.md             # CSDN API 详细文档
  └── troubleshooting.md           # 常见问题排查指南

At runtime, it will also generate csdn_article_map.jsonin the current working directory; this file is not maintained in the repository.

Scenario examples

Example 1: Generate and save a draft

"Help me write an article about Python asynchronous programming, titled 'Python Asynchronous Programming in Practice', and save it to the CSDN draft box"

Execution flow:

  1. Generate article content (Markdown format)
  2. Save to csdnarticle/Python异步编程实战.md
  3. Call the save command:
    # 方式1:使用 --file 参数(推荐)
    node scripts/csdn_article.js save \
      --title "Python 异步编程实战" \
      --file csdnarticle/Python异步编程实战.md
    
    # 方式2:使用 --content 参数(内容较短时)
    node scripts/csdn_article.js save \
      --title "Python 异步编程实战" \
      --content "# Python 异步编程实战\n\n## 简介\n\n本文介绍..."
    
  4. Return the article ID for the user's subsequent operations

Example 2: Update a draft

"Update my previous CSDN draft (ID: 159048943), and change the title to 'Advanced Python Asynchronous Programming'"

Execution flow:

  1. Update the Markdown content according to the new requirements
  2. Save to csdnarticle/Python异步编程进阶.md
  3. Call update command:
    # 方式1:使用 --file 参数(推荐,若已有本地映射可省略 --id)
    node scripts/csdn_article.js update \
      --id 159048943 \
      --title "Python 异步编程进阶" \
      --file csdnarticle/Python异步编程进阶.md
    
    # 方式2:使用 --content 参数
    node scripts/csdn_article.js update \
      --id 159048943 \
      --title "Python 异步编程进阶" \
      --content "# Python 异步编程进阶\n\n## 新增内容..."
    

Example 3: Publish an article

"Help me publish the article with ID 159048943 to CSDN, with tags python,async"

Execution flow:

  1. Guide the user to confirm fields such as creation_statement, readType, type
  2. Call publish command:
    # 方式1:使用 --file 参数(推荐,若已有本地映射可省略 --id)
    node scripts/csdn_article.js publish \
      --id 159048943 \
      --title "Python 异步编程实战" \
      --file csdnarticle/Python异步编程实战.md \
      --extra '{"tags":"python,async","creation_statement":1,"readType":"public","type":"original","description":"Python 异步编程的发布版摘要"}'
    
    # 方式2:使用 --content 参数
    node scripts/csdn_article.js publish \
      --id 159048943 \
      --title "Python 异步编程实战" \
      --content "# Python 异步编程实战\n\n..." \
      --extra '{"tags":"python,async","creation_statement":1,"description":"Python 异步编程的发布版摘要"}'
    

Troubleshooting

For common issues such as expired request headers, invalid signatures, rate limiting, and publish failures, refer to troubleshooting.md