mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-08-29 01:53:47 +08:00
Update contribution guide and add CONTRIBUTING.md (#667)
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
## 请参见[参与我们](https://docs.rsshub.app/joinus/)
|
||||
|
||||
## Please refer to [Join Us](https://docs.rsshub.app/en/joinus/)
|
||||
@@ -18,6 +18,8 @@ We welcome all pull requests. Suggestions and feedback are also welcomed [here](
|
||||
|
||||
## Write the script
|
||||
|
||||
RSSHub provides 3 methods for acquiring data, these methods are sorted by **recommended**:
|
||||
|
||||
### Access the target data source API
|
||||
|
||||
Use [axios](https://github.com/axios/axios) to access the target data source API, assign the acquired title, link, description and datetime to ctx.state.data (refer to Data for the list of parameters) , typically it looks like this: [/routes/bilibili/bangumi.js](https://github.com/DIYgod/RSSHub/blob/master/routes/bilibili/bangumi.js)
|
||||
@@ -26,6 +28,16 @@ Use [axios](https://github.com/axios/axios) to access the target data source API
|
||||
|
||||
If an API is not provided, data need to be scraped from HTML. Use [axios](https://github.com/axios/axios) to acquire the HTML and then use [cheerio](https://github.com/cheeriojs/cheerio) for scraping the relevant data and assign them to ctx.state.data, typically it looks like this: [/routes/jianshu/home.js](https://github.com/DIYgod/RSSHub/blob/master/routes/jianshu/home.js)
|
||||
|
||||
### Page rendering
|
||||
|
||||
::: tip tip
|
||||
|
||||
This method is comparatively less performant and consumes more resources, only use when necessary or your pull requests might be rejected.
|
||||
|
||||
:::
|
||||
|
||||
Some websites provides no API and pages require rendering too, use [puppeteer](https://github.com/GoogleChrome/puppeteer) render the pages via Headless Chrome and then use [cheerio](https://github.com/cheeriojs/cheerio) for scraping the relevant data and assign them to ctx.state.data, typically it looks like this: [/routes/sspai/series.js](https://github.com/DIYgod/RSSHub/blob/master/routes/sspai/series.js)
|
||||
|
||||
### Enable caching
|
||||
|
||||
All routes has a default cache expiry time set in `config.js`, it should be increased when the data source is not subject to frequent updates.
|
||||
|
||||
+13
-1
@@ -18,13 +18,25 @@ sidebar: auto
|
||||
|
||||
## 编写脚本
|
||||
|
||||
RSSHub 支持三种获取数据的办法, 方法按 **「推荐优先级」** 排列:
|
||||
|
||||
### 从接口获取数据
|
||||
|
||||
使用 [axios](https://github.com/axios/axios) 请求接口, 然后把获取的标题、链接、描述、发布时间等数据赋值给 ctx.state.data (每个字段的含义在下面说明) , 可以直接看这个典型的例子: [/routes/bilibili/bangumi.js](https://github.com/DIYgod/RSSHub/blob/master/routes/bilibili/bangumi.js)
|
||||
|
||||
### 从 HTML 获取数据
|
||||
|
||||
有时候数据是写在 HTML 里的, 没有接口供我们调用, 这时候可以使用 [axios](https://github.com/axios/axios) 请求 HTML 数据, 然后使用 [cheerio](https://github.com/cheeriojs/cheerio) 解析 HTML, 再把数据赋值给 ctx.state.data, 可以直接看这个典型的例子: [/routes/jianshu/home.js](https://github.com/DIYgod/RSSHub/blob/master/routes/jianshu/home.js)
|
||||
有时候数据是写在 HTML 里的, **没有接口供我们调用**, 这时候可以使用 [axios](https://github.com/axios/axios) 请求 HTML 数据, 然后使用 [cheerio](https://github.com/cheeriojs/cheerio) 解析 HTML, 再把数据赋值给 ctx.state.data, 可以直接看这个典型的例子: [/routes/jianshu/home.js](https://github.com/DIYgod/RSSHub/blob/master/routes/jianshu/home.js)
|
||||
|
||||
### 渲染页面获取数据
|
||||
|
||||
::: tip 提示
|
||||
|
||||
由于此方法性能较差且消耗较多资源, 使用前请确保以上两种方法无法获取数据, 不然将导致您的 pull requests 被拒绝!
|
||||
|
||||
:::
|
||||
|
||||
部分网站**没有接口供调用, 且页面需要渲染**才能获取正确的 HTML, 这时候可以使用 [puppeteer](https://github.com/GoogleChrome/puppeteer) 通过 Headless Chrome 渲染页面, 然后使用 [cheerio](https://github.com/cheeriojs/cheerio) 解析返回的 HTML, 再把数据赋值给 ctx.state.data, 可以直接看这个典型的例子: [/routes/sspai/series.js](https://github.com/DIYgod/RSSHub/blob/master/routes/sspai/series.js)
|
||||
|
||||
### 使用缓存
|
||||
|
||||
|
||||
Reference in New Issue
Block a user