Skip to content

Latest commit

Β 

History

History

hello-world

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

README.md

hello-world (Auto Summary)

Official example plugin β€” auto-fill article summary on publish when empty. Template for custom ReactPress plugins.

Part of the ReactPress publishing platform Β· plugin system docs

  • Plugin id: hello-world (historical id, unchanged)
  • Display name: Auto Summary
  • Version: see plugin.json

Features

Scenario Behavior
Summary already set on publish No change
Summary empty, body has content Strip Markdown, truncate, write summary
Summary and body both empty Use title if fallbackToTitle is enabled

Hooks

Subscribes to a single hook with a focused responsibility:

Hook Type Description
article.beforePublish filter Fill in summary before publish

Configuration

Declared via plugin.json β†’ settings.schema, stored in globalSetting.plugins.entries.hello-world.config.

Admin UI strings (plugin name, descriptions, field labels) live in src/locales/ (src/locales/{locale}.json); Chinese strings in plugin.json serve as fallback.

Field Type Default Description
enabled boolean true Enable auto summary
maxLength number 160 Max length (40–500)
suffix string … Suffix when truncated
fallbackToTitle boolean true Use title when body is empty

Update config (admin login required):

curl -X PUT http://localhost:3002/api/extension/plugins/hello-world/config \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{"config":{"enabled":true,"maxLength":120}}'

Config save triggers an automatic plugin reload β€” no server restart needed.

Usage

  1. pnpm dev (plugins are compiled automatically)
  2. Admin β†’ Plugins β†’ install hello-world β†’ Enable
  3. Click Settings on the plugin row (or visit /admin/plugins/hello-world/settings)
  4. Leave summary empty when writing β†’ publish β†’ summary field should be auto-filled

Example server logs:

[PluginService] [hello-world] registered (enabled=true, maxLength=160)
[PluginLoaderService] Loaded plugin "hello-world" v1.2.0

Directory structure

hello-world/
β”œβ”€β”€ plugin.json
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ README.md
└── src/
    β”œβ”€β”€ server/           # Node Hook logic
    β”‚   β”œβ”€β”€ index.ts
    β”‚   β”œβ”€β”€ config.ts
    β”‚   β”œβ”€β”€ summary.ts
    β”‚   └── types.ts
    └── locales/          # Admin UI strings
        β”œβ”€β”€ en.json
        └── zh.json
            ↓ tsc (server only)
        dist/
        └── index.js

Development

# from monorepo root
pnpm --filter @reactpress/plugin-hello-world run build
pnpm --filter @reactpress/plugin-hello-world run typecheck

# after editing src/server, rebuild and deactivate β†’ reactivate in admin

Dependencies:

  • @reactpressjs/reactpress-toolkit/plugin/server β€” HookService, PluginContext types

Use as a new plugin template

  1. Copy this directory to plugins/my-plugin/
  2. Update plugin.json id, name, hooks.subscribe
  3. Rewrite src/server/index.ts and business modules
  4. Add the id to plugins/package.json β†’ local list

See ../README.md for the plugin system overview.