docs(core): sync en docs and minor cn docs fixes (#8356)

Co-authored-by: DIYgod <diy.d.god@gmail.com>
This commit is contained in:
Tony
2021-11-27 08:53:44 +00:00
committed by GitHub
co-authored by DIYgod
parent 896e2e22e5
commit 6de540a311
8 changed files with 452 additions and 76 deletions
+7 -3
View File
@@ -9,18 +9,22 @@ module.exports = [
items: [
{
text: 'Getting Started',
link: '/joinus/quick-start',
link: '/en/joinus/quick-start',
},
{
text: 'More details',
items: [
{
text: 'Script Standard',
link: '/en/joinus/script-standard',
},
{
text: 'Date Handling',
link: '/joinus/pub-date',
link: '/en/joinus/pub-date',
},
{
text: 'Use Cache',
link: '/joinus/use-cache',
link: '/en/joinus/use-cache',
},
],
},
+83 -45
View File
@@ -22,13 +22,15 @@ Deploy for public access may require:
1. [Google App Engine](https://cloud.google.com/appengine/)
## Docker Image
We recommend using the latest version of the docker image.
When the latest version is unavailable , you can use image with date tag. For example :
```
We recommend using the latest version `diygod/rsshub` (i.e. `diygod/rsshub:latest`) of the docker image.
When the latest version is unstable, you can use the image with a date tag for temporary use. For example:
```bash
$ docker pull diygod/rsshub:2021-06-18
```
Your can back to the latest version when code has been fixed and rebuild the image.
You can back to the latest version when the code has been fixed and rebuild the image.
## Docker Compose Deployment
@@ -98,7 +100,7 @@ $ docker stop rsshub
### Update
Remove old container
Remove the old container
```bash
$ docker stop rsshub
@@ -117,9 +119,11 @@ For example, adding `-e CACHE_EXPIRE=3600` will set the cache time to 1 hour.
$ docker run -d --name rsshub -p 1200:1200 -e CACHE_EXPIRE=3600 -e GITHUB_ACCESS_TOKEN=example diygod/rsshub
```
This deployment method does not include puppeteer and Redis dependencies. Use the Docker Compose deployment method or deploy external dependencies yourself if you need it.
To configure more options please refer to [Configuration](#configuration).
# Ansible Deployment
## Ansible Deployment
This Ansible playbook includes RSSHub, Redis, browserless (uses Docker) and Caddy 2
@@ -161,18 +165,18 @@ $ git clone https://github.com/DIYgod/RSSHub.git
$ cd RSSHub
```
Execute the following commands to install dependencies
Execute the following commands to install dependencies (Do not add the `--production` parameter for development).
Using `npm`
```bash
$ npm ci
$ npm ci --production
```
Or `yarnv1` (not recommended)
```bash
$ yarn
$ yarn --production
```
### Launch
@@ -212,7 +216,7 @@ CACHE_EXPIRE=600
Please notice that it will not override already existed environment variables, more rules please refer to [dotenv](https://github.com/motdotla/dotenv)
This deployment method does not include puppeteer and redis dependencies. Use the Docker Compose deployment method or deploy external dependencies yourself if you need it.
This deployment method does not include puppeteer and Redis dependencies. Use the Docker Compose deployment method or deploy external dependencies yourself if you need it.
To configure more options please refer to [Configuration](#configuration).
@@ -242,7 +246,7 @@ in pkgs.stdenv.mkDerivation {
## Deploy to Heroku
### Notice:
### Notice:
Heroku accounts with unverified payment methods have only 550 hours of credit per month (about 23 days), and up to 1,000 hours per month with verified payment methods.
@@ -277,7 +281,7 @@ Execute `git clone https://github.com/DIYgod/RSSHub.git` to pull the latest code
#### Deploy to Flexible Environment
Under RSSHub's root directory, create a file `app.yaml` with the following content:
Under RSSHub's root directory, create a file `app.yaml` with the following content:
```yaml
# [START app_yaml]
@@ -307,7 +311,7 @@ env_variables:
#### Deploy to standard environment
Under RSSHub's root directory, create a file `app.yaml` with the following content:
Under RSSHub's root directory, create a file `app.yaml` with the following content:
```yaml
# [START app_yaml]
@@ -364,13 +368,36 @@ RSSHub supports two caching methods: memory and redis
`CACHE_CONTENT_EXPIRE`: content cache expiry time in seconds, it will be recalculated when it is accessed, default to `1 * 60 * 60`
`REDIS_URL`: Redis target address(invalid when `CACHE_TYPE` is set to memory), default to `redis://localhost:6379/`
`REDIS_URL`: Redis target address (invalid when `CACHE_TYPE` is set to memory), default to `redis://localhost:6379/`
### Proxy Configurations
Partial routes have a strict anti-crawler policy, and can be configured to use proxy
Partial routes have a strict anti-crawler policy, and can be configured to use proxy.
`PROXY_PROTOCOL`: Using proxy, Supports socks, socks5, socks5h, http, https, etc. See [socks-proxy-agent](https://www.npmjs.com/package/socks-proxy-agent) NPM package page and [source](https://github.com/TooTallNate/node-socks-proxy-agent/blob/master/src/agent.ts) for what these protocols mean. See also [cURL OOTW: SOCKS5](https://daniel.haxx.se/blog/2020/05/26/curl-ootw-socks5/) for reference.
Proxy can be configured via either **Proxy URI** or **Proxy options**. When both are configured, RSSHub will use the configuration in **Proxy URI**.
#### Proxy URI
`PROXY_URI`: Proxy supports socks4, socks5(hostname is resolved locally, not recommanded), socks5h(hostname is
resolved by the SOCKS server, recommanded, prevents DNS poisoning or DNS leak), http, https. See [socks-proxy-agent](https://www.npmjs.com/package/socks-proxy-agent) NPM package page. See also [cURL OOTW: SOCKS5](https://daniel.haxx.se/blog/2020/05/26/curl-ootw-socks5/).
> Proxy URI's format:
>
> - `{protocol}://{host}:{port}`
> - `{protocol}://{username}:{password}@{host}:{port}` (with credentials)
>
> Some examples:
>
> - `socks4://127.0.0.1:1080`
> - `socks5h://user:pass@127.0.0.1:1080` (username as `user`, password as `pass`)
> - `socks://127.0.0.1:1080` (`socks5h` when protocol is `socks`)
> - `http://127.0.0.1:8080`
> - `http://user:pass@127.0.0.1:8080`
> - `https://127.0.0.1:8443`
#### Proxy options
`PROXY_PROTOCOL`: Using proxy, supports socks, http, https, etc. See [socks-proxy-agent](https://www.npmjs.com/package/socks-proxy-agent) NPM package page and [source](https://github.com/TooTallNate/node-socks-proxy-agent/blob/master/src/agent.ts) for what these protocols mean. See also [cURL OOTW: SOCKS5](https://daniel.haxx.se/blog/2020/05/26/curl-ootw-socks5/) for reference.
`PROXY_HOST`: host or IP of the proxy
@@ -379,21 +406,22 @@ Partial routes have a strict anti-crawler policy, and can be configured to use p
`PROXY_AUTH`: credentials to authenticate a user agent to proxy server, `Proxy-Authorization: Basic ${process.env.PROXY_AUTH}`
`PROXY_URL_REGEX`: regex for url of enabling proxy, default to `.*`
### CORS Request
RSSHub by default reject CORS requests. This behavior can be modified via setting `ALLOW_ORIGIN: *` or `ALLOW_ORIGIN: www.example.com`.
### User Authentication Configurations
Routes in `protected_route.js` will be protected using HTTP Basic Authentication.
When adding feeds using RSS readers with HTTP Basic Authentication support, authentication information is required, eg:http://usernam3:passw0rd@rsshub.app/protected/rsshub/routes.
When adding feeds using RSS readers with HTTP Basic Authentication support, authentication information is required, eg: https://usernam3:passw0rd@rsshub.app/protected/rsshub/routes.
For readers that do not support HTTP Basic authentication, please refer to [Access Control Configuration](#access-control-configuration).
`HTTP_BASIC_AUTH_NAME`: Http basic authentication username, default to `usernam3`, please change asap
`HTTP_BASIC_AUTH_NAME`: HTTP basic authentication username, default to `usernam3`, please change asap
`HTTP_BASIC_AUTH_PASS`: Http basic authentication password, default to `passw0rd`, please change asap
`HTTP_BASIC_AUTH_PASS`: HTTP basic authentication password, default to `passw0rd`, please change asap
### CORS Request
RSSHub by default reject CORS requests. This behavior can be modified via setting `ALLOW_ORIGIN: *` or `ALLOW_ORIGIN: www.example.com`.
### Access Control Configuration
@@ -442,15 +470,15 @@ See the relation between access key/code and white/blacklisting.
`REQUEST_TIMEOUT`: milliseconds to wait for the server to end the response before aborting the request with error, default to `3000`
`DEBUG_INFO`: display route information on homepage for debugging purpose. When set to neither `true` nor `false`, use parameter `debug` to enable display, eg: <https://rsshub.app/?debug=value_of_DEBUG_INFO> . Default to `true`
`DEBUG_INFO`: display route information on the homepage for debugging purposes. When set to neither `true` nor `false`, use parameter `debug` to enable display, eg: <https://rsshub.app/?debug=value_of_DEBUG_INFO> . Default to `true`
`NODE_ENV`: display error message on pages for authentication failing, default to `production` (i.e. no display)
`LOGGER_LEVEL`: specifies the maximum [level](https://github.com/winstonjs/winston#logging-levels) of messages to the console and log file, default to `info`
`NODE_NAME`: node name, used for load balancing, identify current node
`NODE_NAME`: node name, used for load balancing, identify the current node
`PUPPETEER_WS_ENDPOINT`: Browser websocket endpoint which can be used as an argument to puppeteer.connect, refer to [browserWSEndpoint](https://pptr.dev/#?product=Puppeteer&version=v1.14.0&show=api-browserwsendpoint)
`PUPPETEER_WS_ENDPOINT`: Browser WebSocket endpoint which can be used as an argument to puppeteer.connect, refer to [browserWSEndpoint](https://pptr.dev/#?product=Puppeteer&version=v1.14.0&show=api-browserwsendpoint)
`SENTRY`: [Sentry](https://sentry.io) dsn, used for error tracking
@@ -458,26 +486,26 @@ See the relation between access key/code and white/blacklisting.
`DISALLOW_ROBOT`: prevent indexing by search engine, default to enable, set false or 0 to disable
`HOTLINK_TEMPLATE`: Replace image link in description to avoid anti-hotlink protection, leave blank to disable this function. Usage reference [#2769](https://github.com/DIYgod/RSSHub/issues/2769). You may use any properity listed in [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL#Properties), format of JS template literal. e.g. `${protocol}//${host}${pathname}`, `https://i3.wp.com/${host}${pathname}`
`HOTLINK_TEMPLATE`: Replace image link in the description to avoid anti-hotlink protection, leave blank to disable this function. Usage reference [#2769](https://github.com/DIYgod/RSSHub/issues/2769). You may use any property listed in [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL#Properties), format of JS template literal. e.g. `${protocol}//${host}${pathname}`, `https://i3.wp.com/${host}${pathname}`
### Route-specific Configurations
::: tip Notice
Configs here is incomplete.
Configs here are incomplete.
See docs of specified route and `lib/config.js` for detail information.
See docs of the specified route and `lib/config.js` for detailed information.
:::
- pixiv: [Registration](https://accounts.pixiv.net/signup)
- `PIXIV_REFRESHTOKEN`: Please refer to [this article](https://gist.github.com/ZipFile/c9ebedb224406f4f11845ab700124362) to get a `refresh_token`
- `PIXIV_BYPASS_CDN`: bypass Cloudflare bot check by directly accessing Pixiv source server, defaults to disable, set `true` or `1` to enable
- `PIXIV_BYPASS_HOSTNAME`: Pixiv source server hostname or IP address, hostname will be resolved to IPv4 address via `PIXIV_BYPASS_DOH`, defaults to `public-api.secure.pixiv.net`
- `PIXIV_BYPASS_DOH`: DNS over HTTPS endpoint, it must be compatible with Cloudflare or Google DoH JSON schema, defaults to `https://1.1.1.1/dns-query`
- `PIXIV_IMG_PROXY`: Used as a proxy for image addresses, as pixiv images have anti-theft, default to `https://i.pixiv.cat`
@@ -510,13 +538,13 @@ See docs of specified route and `lib/config.js` for detail information.
- `GITHUB_ACCESS_TOKEN`: GitHub Access Token
- Instagram:
- Instagram:
- `IG_USERNAME`: Your Instagram username
- `IG_PASSWORD`: Your Instagram password
- `IG_PROXY`: Proxy URL for Instagram
Warning: Two Factor Authentication is *not* supported.
Warning: Two Factor Authentication is **not** supported.
- mail:
@@ -529,27 +557,37 @@ See docs of specified route and `lib/config.js` for detail information.
- `NHENTAI_USERNAME`: nhentai username or email
- `NHENTAI_PASSWORD`: nhentai password
- discuz cookies
- Discuz cookie
- `DISCUZ_COOKIE_{cid}`: Cookie of a forum powered by discuz, cid can be anything from 00 to 99. When visiting route discuz, using cid to specify this cookie.
- `DISCUZ_COOKIE_{cid}`: Cookie of a forum powered by Discuz, cid can be anything from 00 to 99. When visiting a Discuz route, use cid to specify this cookie.
- Mastodon user timeline: apply api here `https://mastodon.example/settings/applications`, please check scope `read:search`
- Last.fm
- `MASTODON_API_HOST`: api instance domain
- `LASTFM_API_KEY`: Last.fm API Key
- Mastodon user timeline: apply API here `https://mastodon.example/settings/applications`(repalce `mastodon.example`), please check scope `read:search`
- `MASTODON_API_HOST`: API instance domain
- `MASTODON_API_ACCESS_TOKEN`: user access token
- `MASTODON_API_ACCT_DOMAIN`: acct domain for particular instance
- Sci-hub for scientific journal routes:
- `SCIHUB_HOST`: The Sci-hub mirror address that is accssible from your location, default to `https://sci-hub.se`.
- `SCIHUB_HOST`: The Sci-hub mirror address that is accessible from your location, default to `https://sci-hub.se`.
- Wordpress:
- `WORDPRESS_CDN`: Proxy http image link with https link. Consider using:
| url | backbone |
| ---------------------------------------- | ------------ |
| https://imageproxy.pimg.tw/resize?url= | akamai |
| https://images.weserv.nl/?url= | cloudflare |
| https://pic1.xuehuaimg.com/proxy/ | cloudflare |
| https://cors.netnr.workers.dev/ | cloudflare |
| https://netnr-proxy.openode.io/ | digitalocean |
- `WORDPRESS_CDN`: Proxy HTTP image link with HTTPS link. Consider using:
| url | backbone |
| -------------------------------------- | ------------ |
| https://imageproxy.pimg.tw/resize?url= | akamai |
| https://images.weserv.nl/?url= | cloudflare |
| https://pic1.xuehuaimg.com/proxy/ | cloudflare |
| https://cors.netnr.workers.dev/ | cloudflare |
| https://netnr-proxy.openode.io/ | digitalocean |
- E-Hentai
- `EH_IPB_MEMBER_ID`: The value of `ipb_member_id` in the cookie header after logging in E-Hentai
- `EH_IPB_PASS_HASH`: The value of `ipb_pass_hash` in the cookie header after logging in E-Hentai
- `EH_SK`: The value of `sk` in the cookie header after logging in E-Hentai
+59
View File
@@ -0,0 +1,59 @@
# Date Handling
When crawling a web page, the web page usually provides a date. This tutorial will illustrate how a script should properly handle that situation
## No Date
**Do not add a date** when a website does not provide one. The `pubDate` option should be left empty.
## Standard
`pubDate` must be a
1. [Date Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
2. **Not recommended, only use for compatible** strings that can be parsed correctly because its behavior may be inconsistent across environments, [Date.parse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse). Please avoid using it
Also, the `pubDate` passed in from the script should correspond to the time zone/time used by the **server**. For more details, see the following:
## Use utilities class
We recommend using [Day.js](https://github.com/iamkun/dayjs) for date processing and time zone adjustment as of now. There are two related tool classes:
### Parse Date
This is a utility class for using [Day.js](https://github.com/iamkun/dayjs). In most cases, it is possible to use it directly to get the correct `Date Object`
Please refer to Day.js GitHub description for specific parsing parameters
```javascript
const { parseDate } = require('@/utils/parse-date');
const pubDate = parseDate('2020/12/30', 'YYYY/MM/DD');
```
If you need to parse a relative date, use `parseRelativeDate`.
::: warning Warning
Only works for relative date in Chinese for now
:::
```javascript
const { parseRelativeDate } = require('@/utils/parse-date');
const pubDate = parseRelativeDate('2天前');
const pubDate = parseRelativeDate('前天 15:36');
```
### Timezone
Some websites will not convert the time zone according to the location of a visitor. The time obtained will be the local time of the website, which may not be suitable for all RSS subscribers. In this case, you should specify the time zone manually:
::: warning Warning
Now, the time will be converted to server time, which facilitates middleware processing.
:::
```javascript
const timezone = require('@/utils/timezone');
const pubDate = timezone(new Date(), +8);
```
+143 -23
View File
@@ -13,11 +13,11 @@ We welcome all pull requests. Suggestions and feedback are also welcomed [here](
## Submit new RSS rule
Before you start writing RSS rule, please make sure that the source site does not provide RSS. Some web pages will include a link element with type `application/atom+xml` or `application/rss+xml` in the HTML header to indicate the RSS link.
Before you start writing an RSS rule, please make sure that the source site does not provide RSS. Some web pages will include a link element with type `application/atom+xml` or `application/rss+xml` in the HTML header to indicate the RSS link.
### Debug
First `yarn` or`npm install` to install dependencies, then execute `yarn dev` or`npm run dev`, open `http://localhost:1200` to see the effect, and the page will refresh automatically if files modified.
First, `yarn` or `npm install` to install dependencies, then execute `yarn dev` or `npm run dev`, open `http://localhost:1200` to see the effect, and the page will refresh automatically if files are modified.
### Add route
@@ -29,7 +29,7 @@ Create a new js script in [/lib/routes/](https://github.com/DIYgod/RSSHub/tree/m
#### Acquiring Data
- Typically the data are acquired via HTTP requests (via API or webpage) sent by [got](https://github.com/sindresorhus/got)
- Typically, the data are acquired via HTTP requests (via API or webpage) sent by [got](https://github.com/sindresorhus/got)
- Occasionally [puppeteer](https://github.com/GoogleChrome/puppeteer) is required for browser stimulation and page rendering in order to acquire the data
- The acquired data are most likely in JSON or HTML format
@@ -39,7 +39,7 @@ Create a new js script in [/lib/routes/](https://github.com/DIYgod/RSSHub/tree/m
1. **Acquire data via API using got**
Example:[/lib/routes/bilibili/coin.js](https://github.com/DIYgod/RSSHub/blob/master/lib/routes/bilibili/coin.js)。
Example: [/lib/routes/bilibili/coin.js](https://github.com/DIYgod/RSSHub/blob/master/lib/routes/bilibili/coin.js)。
Acquiring data via the official API provided by the data source using got:
@@ -57,7 +57,7 @@ Create a new js script in [/lib/routes/](https://github.com/DIYgod/RSSHub/tree/m
// The object contains a nested object called data, thus response.data.data is the actual data needed here
```
One of the leaf objects (response.data.data[0]):
One of the leaf objects (response.data.data[0]):
```json
{
@@ -75,7 +75,7 @@ Create a new js script in [/lib/routes/](https://github.com/DIYgod/RSSHub/tree/m
}
```
Processing the data further to generate objects in accordance with RSS specification, mainly title, link, description, publish time, then assign them to ctx.state.data, [produce RSS feed](#produce-rss-feed):
Processing the data further to generate objects in accordance with RSS specification, mainly title, link, description, publish time, then assign them to ctx.state.data, [produce RSS feed](#produce-rss-feed):
```js
ctx.state.data = {
@@ -125,9 +125,9 @@ Create a new js script in [/lib/routes/](https://github.com/DIYgod/RSSHub/tree/m
// use cheerio selector, select all 'div' elements with 'data-item_id' attribute, the result is an array of cheerio node objects
// use cheerio get() method to transform a cheerio node object array into a node array
// PS:every cheerio node is a HTML DOM
// PPS:cheerio selector is almost identical to jquery selector
// Refer to cheerio docs:https://cheerio.js.org/
// PS: every cheerio node is a HTML DOM
// PPS: cheerio selector is almost identical to jquery selector
// Refer to cheerio docs: https://cheerio.js.org/
```
Use map to traverse the array and parse out the result of each item
@@ -156,9 +156,9 @@ Create a new js script in [/lib/routes/](https://github.com/DIYgod/RSSHub/tree/m
3. **Acquire data via page rendering using puppeteer**
::: tip tips
::: tip Tips
This method consumes more resources and is less performant, use only when the above methods failed to acquire data, otherwise your pull requests will be rejected!
This method consumes more resources and is less performant, use only when the above methods are failed to acquire data. Otherwise, your pull requests will be rejected!
:::
@@ -210,16 +210,16 @@ Create a new js script in [/lib/routes/](https://github.com/DIYgod/RSSHub/tree/m
// the route is now done
// PS: the route acts as a notifier of new articles, it does not provide access to the content behind the paywall, thus not content were fetched
// PS: the route acts as a notifier of new articles. It does not provide access to the content behind the paywall. Thus no content was fetched
```
4. **Use general configuration routing**
A large number of websites can generate RSS through a configuration paradigm.
The general configuration is to easily generate RSS by reading json data through cheerio (**CSS selector, jQuery function**)
The general configuration is to generate RSS with ease by reading json data through cheerio (**CSS selector, jQuery function**)
First we need a few data:
First, we need a few data:
1. RSS source link
2. Data source link
@@ -239,7 +239,7 @@ Create a new js script in [/lib/routes/](https://github.com/DIYgod/RSSHub/tree/m
};
```
Our RSS does not have any content for now, the content needs to be completed by `item`
Our RSS does not have any content for now. The content needs to be completed by `item`.
Here is an example
```js
@@ -272,9 +272,9 @@ Create a new js script in [/lib/routes/](https://github.com/DIYgod/RSSHub/tree/m
#### Use Cache
All routes have a cache, the global cache time is set in `lib/config.js`, but the content returned by some interfaces is updated less frequently. At this time, you should set a longer cache time for these data.
All routes have a cache, the global cache time is set in `lib/config.js`, but the content returned by some interfaces is updated less frequently. For that, you should set a longer cache time for these data like the full text of an article.
For example, the bilibili column needs to get the full text of the article:[/lib/routes/bilibili/followings_article.js](https://github.com/DIYgod/RSSHub/blob/master/lib/routes/bilibili/followings_article.js)
For example, the bilibili column needs to get the full text of the article: [/lib/routes/bilibili/followings_article.js](https://github.com/DIYgod/RSSHub/blob/master/lib/routes/bilibili/followings_article.js)
Since the full text of all articles cannot be got from one API, each article needs to be requested once, and these data are generally unchanged, so these data should be stored in the cache to avoid requesting repeatedly
@@ -291,7 +291,7 @@ const description = await ctx.cache.tryGet(link, async () => {
});
```
The implementation of tryGet can be seen [here](https://github.com/DIYgod/RSSHub/blob/master/lib/middleware/cache.js#L128). The first parameter is the cache key, the second parameter is the cache data acquisition method, and the third parameter is the cache time, it should not be passed in normally. The cache time defaults to [CACHE_CONTENT_EXPIRE](/en/install/#cache-configurations), and each time accessing the cache will recalculate the expiration time
The implementation of tryGet can be seen [here](https://github.com/DIYgod/RSSHub/blob/master/lib/middleware/cache/index.js#L58). The first parameter is the cache key, the second parameter is the cache data acquisition method, and the third parameter is the cache time, it should not be passed in normally. The cache time defaults to [CACHE_CONTENT_EXPIRE](/en/install/#cache-configurations), and each time accessing the cache will recalculate the expiration time
---
@@ -386,7 +386,7 @@ ctx.state.data = {
### Add the documentation
1. Update [Documentation (/docs/en/README.md) ](https://github.com/DIYgod/RSSHub/blob/master/docs/en/README.md), preview the docs via `npm run docs:dev`
1. Update the corresponding file in [documentation (/docs/en/)](https://github.com/DIYgod/RSSHub/blob/master/docs/en) directory, preview the docs via `npm run docs:dev`
- Documentation uses vue component:
- `author`: route authors, separated by a single space
@@ -416,14 +416,14 @@ ctx.state.data = {
2. Multiple parameters:
```vue
<RouteEn author="HenryQW" example="/github/issue/DIYgod/RSSHub" path="/github/issue/:user/:repo" :paramsDesc="['用户名', '仓库名']" />
<RouteEn author="HenryQW" example="/github/issue/DIYgod/RSSHub" path="/github/issue/:user/:repo" :paramsDesc="['GitHub username', 'GitHub repo name']" />
```
Preview:
***
<RouteEn author="HenryQW" example="/github/issue/DIYgod/RSSHub" path="/github/issue/:user/:repo" :paramsDesc="['用户名', '仓库名']"/>
<RouteEn author="HenryQW" example="/github/issue/DIYgod/RSSHub" path="/github/issue/:user/:repo" :paramsDesc="['GitHub username', 'GitHub repo name']"/>
***
@@ -457,6 +457,126 @@ ctx.state.data = {
1. Execute `npm run format` to lint the code before you commit and open a pull request
## ## Submit new RSSHub Radar rule
## Submit new RSSHub Radar rule
TODO
### Debug
Open browser's RSSHub Radar extension settings, switch to rules list, scroll down and you will see a text box, copy the new rules into the text box and start debugging
### Code the rule
Add rules to [/assets/radar-rules.js](https://github.com/DIYgod/RSSHub/blob/master/assets/radar-rules.js)
Simplified rules will be used for the following illustration:
```js
{
'bilibili.com': {
_name: 'bilibili',
www: [{
title: '分区视频',
docs: 'https://docs.rsshub.app/social-media.html#bilibili',
source: '/v/*tpath',
target: (params) => {
let tid;
switch (params.tpath) {
case 'douga/mad':
tid = '24';
break;
default:
return false;
}
return `/bilibili/partion/${tid}`;
},
}],
},
'twitter.com': {
_name: 'Twitter',
'.': [{ // for twitter.com
title: 'User timeline',
docs: 'https://docs.rsshub.app/en/social-media.html#twitter',
source: '/:id',
target: (params) => {
if (params.id !== 'home') {
return '/twitter/user/:id';
}
},
}],
},
'pixiv.net': {
_name: 'Pixiv',
'www': [{
title: 'User Bookmark',
docs: 'https://docs.rsshub.app/en/social-media.html#pixiv',
source: '/bookmark.php',
target: (params, url) => `/pixiv/user/bookmarks/${new URL(url).searchParams.get('id')}`,
}],
},
'weibo.com': {
_name: '微博',
'.': [{
title: '博主',
docs: 'https://docs.rsshub.app/social-media.html#%E5%BE%AE%E5%8D%9A',
source: ['/u/:id', '/:id'],
target: (params, url, document) => {
const uid = document && document.documentElement.innerHTML.match(/\$CONFIG\['oid']='(\d+)'/)[1];
return uid ? `/weibo/user/${uid}` : '';
},
}],
},
}
```
The definition and usage of these fields are explained below:
#### title
Required, route name
The corresponding name in RSSHub docs, e.g. the `title` for `Twitter User timeline` is `User timeline`
#### docs
Required, docs link
e.g. the `docs` for `Twitter User timeline` is `https://docs.rsshub.app/en/social-media.html#twitter`
Note that it is not `https://docs.rsshub.app/en/social-media.html#twitter-user-timeline`, hash should be positioned to the H1 heading
#### source
Optional, source path, leave it blank and it will never match, only appears in `RSSHub for current website`
e.g. the `source` for `Twitter User timeline` is `/:id`
Let's say we are in `https://twitter.com/DIYgod`, which matches`twitter.com/:id`, the resulting params is `{id: 'DIYgod'}`, the extension will then generate an RSSHub subscription address based on the params `target`
Please note that `source` can only match URL Path, if the parameters are in URL Param and URL Hash please use `target`
#### target
Optional, RSSHub path, leave it blank to not generate an RSSHub path
The corresponding path in RSSHub docs, e.g. the `target` for `Twitter User timeline` is `/twitter/user/:id`
The source path in the previous step matches `id` with `DIYgod`, the `:id` in RSSHub path will be replaced with `DIYgod`, resulting in `/twitter/user/DIYgod`, which is the result we want
Furthermore, if the source path does not match the desired parameters, we can use `target` as a function with `params`, `url` and `document` parameters
`params` are the parameters matched by `source` in the previous step, `url` is the page url, `document` is the page document
Note that the `target` method runs in a sandbox, any changes to `document` will not be reflected in the web page
### RSSBud
[RSSBud](https://github.com/Cay-Zhang/RSSBud) supports RSSHub Radar rules and will also be updated automatically, but please note that:
- Using `'.'` subdomain allows RSSBud to support common mobile domains such as `m` / `mobile`
- Using `document` in `target` does not apply to RSSBud: RSSBud is not a browser extension, it only fetches and analyzes the URL of a website
### Additional Information
Adding `radar="1"` in the RSSHub docs will show a `support browser extension` badge
If RSSBud is also supported, adding `rssbud="1"` will show a `support rssbud` badge
+147
View File
@@ -0,0 +1,147 @@
# Script Standard
::: warning Warning
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 :
- `router.js` Register route
- `maintainer.js` Fetch route path and maintainer
- `radar.js` Fetch the website and the matching rules corresponding to the route: <https://github.com/DIYgod/RSSHub-Radar/>
- `templates` Rendering templates
**The above files are mandatory for all routes**
```
├───lib/v2
│ ├───furstar
│ ├─── templates
│ ├─── description.art
│ ├─── 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
```js
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
```js
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: <https://docs.rsshub.app/en/joinus/quick-start.html#submit-new-rsshub-radar-rule>
**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
```js
module.exports = {
'furstar.jp': {
_name: 'Furstar',
'.': [
{
title: '最新售卖角色列表',
docs: 'https://docs.rsshub.app/shopping.html#furstar-zui-xin-shou-mai-jiao-se-lie-biao',
source: ['/:lang', '/'],
target: '/furstar/characters/:lang',
},
{
title: '已经出售的角色列表',
docs: 'https://docs.rsshub.app/shopping.html#furstar-yi-jing-chu-shou-de-jiao-se-lie-biao',
source: ['/:lang/archive.php', '/archive.php'],
target: '/furstar/archive/:lang',
},
{
title: '画师列表',
docs: 'https://docs.rsshub.app/shopping.html#furstar-hua-shi-lie-biao',
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: <https://aui.github.io/art-template/docs/>
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
```art
<div>
<img src="{{ avatar }}" />
{{ if link !== null }}
<a href="{{ link }}">{{name}}</a>
{{ else }}
<a href="#">{{name}}</a>
{{ /if }}
</div>
```
```js
const { art } = require('@/utils/render');
const renderAuthor = (author) => art(path.join(__dirname, 'templates/author.art'), 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
+5
View File
@@ -0,0 +1,5 @@
# Use Cache
Some routes require visiting several pages when generating RSS feeds, and these pages are not likely to be changed very often. In this case, caching should be used for reducing the server load and saving unnecessary traffics/calculations. Here are some scenarios and details about the use of the caching tools.
<!-- @TODO After refactoring cache class -->
+6 -3
View File
@@ -181,6 +181,8 @@ $ yarn install --production
由于众所周知的原因,在中国使用 `npm` 下载依赖十分缓慢,建议挂一个代理或者考虑使用 [NPM 镜像](https://npm.taobao.org/)
### 启动
然后在 `RSSHub` 文件夹中运行下面的命令就可以启动
```bash
@@ -376,7 +378,7 @@ RSSHub 支持 `memory` 和 `redis` 两种缓存方式
部分路由反爬严格,可以配置使用代理抓取。
可通过**代理 URI **或**代理选项**两种方式来配置代理,当两种配置方式同时被设置时,RSSHub 将会使用**代理 URI **中的配置。
可通过**代理 URI**或**代理选项**两种方式来配置代理,当两种配置方式同时被设置时,RSSHub 将会使用**代理 URI**中的配置。
#### 代理 URI
@@ -390,8 +392,8 @@ RSSHub 支持 `memory` 和 `redis` 两种缓存方式
> 一些示例:
>
> - `socks4://127.0.0.1:1080`
> - `socks5h://user:pass@127.0.0.1:1080` (用户名为 `user`, 密码为 `pass`)
> - `socks://127.0.0.1:1080` (protocol 为 socks 时表示 `socks5h`)
> - `socks5h://user:pass@127.0.0.1:1080` (用户名为 `user`, 密码为 `pass`)
> - `socks://127.0.0.1:1080` (protocol 为 socks 时表示 `socks5h`)
> - `http://127.0.0.1:8080`
> - `http://user:pass@127.0.0.1:8080`
> - `https://127.0.0.1:8443`
@@ -577,6 +579,7 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行
- `MASTODON_API_ACCT_DOMAIN`: 该实例本地用户 acct 标识的域名
- MiniFlux 全部路由:
- `MINIFLUX_INSTANCE`: 用户所用的实例,默认为 MiniFlux 官方提供的 [付费服务地址](https://reader.miniflux.app)
- `MINIFLUX_TOKEN`: 用户的 API 密钥,请登录所用实例后于 `设置` -> `API 密钥` -> `创建一个新的 API 密钥` 处获取
+2 -2
View File
@@ -292,7 +292,7 @@ const description = await ctx.cache.tryGet(link, async () => {
});
```
tryGet 的实现可以看[这里](https://github.com/DIYgod/RSSHub/blob/master/lib/middleware/cache.js#L128),第一个参数为缓存的 key,第二个参数为缓存数据获取方法,第三个参数为缓存时间,正常情况不应该传入,缓存时间默认为 [CACHE_CONTENT_EXPIRE](/install/#缓存配置),且每次访问缓存会重新计算过期时间
tryGet 的实现可以看[这里](https://github.com/DIYgod/RSSHub/blob/master/lib/middleware/cache/index.js#L58),第一个参数为缓存的 key,第二个参数为缓存数据获取方法,第三个参数为缓存时间,正常情况不应该传入,缓存时间默认为 [CACHE_CONTENT_EXPIRE](/install/#缓存配置),且每次访问缓存会重新计算过期时间
* * *
@@ -547,7 +547,7 @@ ctx.state.data = {
#### source
可选,源站路径,留空则永远不会匹配成功,只会在 `当前网站适用的 RSSHub 中出现`
可选,源站路径,留空则永远不会匹配成功,只会在 `适用于当前网站的 RSSHub` 中出现
如 `Twitter 用户时间线` 规则的 `source` 为 `/:id`