Script Standard


This standard is still WIP and may change over time, so please remember to check it often!

When writing a new route, RSSHub will read the following in a folder :

The above files are mandatory for all routes

โ”‚   โ”œโ”€โ”€โ”€furstar
โ”‚       โ”œโ”€โ”€โ”€ templates
โ”‚           โ”œโ”€โ”€โ”€
โ”‚       โ”œโ”€โ”€โ”€ router.js
โ”‚       โ”œโ”€โ”€โ”€ maintainer.js
โ”‚       โ”œโ”€โ”€โ”€ radar.js
โ”‚       โ”œโ”€โ”€โ”€ someOtherJs.js
โ”‚   โ””โ”€โ”€โ”€test
โ”‚   โ””โ”€โ”€โ”€someOtherScript

All eligible routes under /v2 path will be loaded automatically without the need of updating router.js

# Route Example

Refer to furstar: ./lib/v2/furstar

You can copy the folder as a start-up route template

# Register Route

router.js should export a method that provides a @koa/router object when we initialize the route

# Naming Standard

RSSHub will append all the route folder names in front of the actual route by default. The route maintainers can think that the one he gets is the root. We will append the corresponding namespace under which the developers have all the control

# Example

module.exports = function (router) {
    router.get('/characters/:lang?', require('./index'));
    router.get('/artists/:lang?', require('./artists'));
    router.get('/archive/:lang?', require('./archive'));

# Maintainer List

maintainer.js should export an object from which we will retrieve the maintainer information when we get the path-related information, etc.

  • key: @koa/router Corresponding path
  • value: Array, includes all maintainers' Github Username

Github ID may be a better choice, but it is inconvenient to deal with the follow-up, so use GitHub Username for now.

# Example

module.exports = {
    '/characters/:lang?': ['NeverBehave'],
    '/artists/:lang?': ['NeverBehave'],
    '/archive/:lang?': ['NeverBehave'],

npm run build:maintainer will generate a list of maintainers under assets/build

# Radar Rules

Writing style: (opens new window)

We currently require all routes to include this file and include the corresponding domain name -- we don't require an exact route match. The minimum requirement is that it will show up on the corresponding site. This file will also be used later to help with bug feedback.

# Example

module.exports = {
    '': {
        _name: 'Furstar',
        '.': [
                title: 'ๆœ€ๆ–ฐๅ”ฎๅ–่ง’่‰ฒๅˆ—่กจ',
                docs: '',
                source: ['/:lang', '/'],
                target: '/furstar/characters/:lang',
                title: 'ๅทฒ็ปๅ‡บๅ”ฎ็š„่ง’่‰ฒๅˆ—่กจ',
                docs: '',
                source: ['/:lang/archive.php', '/archive.php'],
                target: '/furstar/archive/:lang',
                title: '็”ปๅธˆๅˆ—่กจ',
                docs: '',
                source: ['/'],
                target: '/furstar/artists',

npm run build:radar will generate a complete radar-rules.js under /assets/build/

# Template

We currently require all routes, when rendering content with HTML such as description, must use the art engine for layout

art documentation: (opens new window)

Apart from that, all templates should be placed in the script's templates folder: We will use this to provide custom template switching/rendering, etc.

# Example

    <img src="{{ avatar }}" />
    {{ if link !== null }}
    <a href="{{ link }}">{{name}}</a>
    {{ else }}
    <a href="#">{{name}}</a>
    {{ /if }}
const { art } = require('@/utils/render');
const renderAuthor = (author) => art(path.join(__dirname, 'templates/'), author);

# ctx.state.json

The script can also provide a custom object for debugging: Access the corresponding route + .debug.json to get the corresponding content

We don't have any restrictions on the formatting of this part yet, it's completely optional, and we will see where this option goes