docs: js to ts
This commit is contained in:
+1
-1
@@ -12,7 +12,7 @@ RSSHub provides the following APIs:
|
||||
|
||||
:::tip
|
||||
|
||||
This API **will not** return any routes under `lib/protected_router.js`.
|
||||
This API **will not** return any routes under `lib/protected_router.ts`.
|
||||
|
||||
:::
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ Configs in this sections are in beta stage, and **are turn off by default**. Ple
|
||||
|
||||
Configs here are incomplete.
|
||||
|
||||
See docs of the specified route and `lib/config.js` for detailed information.
|
||||
See docs of the specified route and `lib/config.ts` for detailed information.
|
||||
|
||||
:::
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ sidebar_position: 1
|
||||
|
||||
This guide is intended for advanced users who want to know how to create an RSS feed in detail. If you're new to creating RSS feeds, we recommend reading [Create Your Own RSSHub Route](/joinus/new-rss/start-code) first.
|
||||
|
||||
Once you have collected the data you want to include in your RSS feed, you can pass it to `ctx.set('data', obj)`. RSSHub's middleware [`template.js`](https://github.com/DIYgod/RSSHub/blob/master/lib/middleware/template.js) will then process the data and render the RSS output in the required format (which is RSS 2.0 by default). In addition to the fields mentioned in [Create your own RSSHub route](/joinus/new-rss/start-code), you can customize your RSS feed further using the following fields.
|
||||
Once you have collected the data you want to include in your RSS feed, you can pass it to `ctx.set('data', obj)`. RSSHub's middleware [`template.ts`](https://github.com/DIYgod/RSSHub/blob/master/lib/middleware/template.ts) will then process the data and render the RSS output in the required format (which is RSS 2.0 by default). In addition to the fields mentioned in [Create your own RSSHub route](/joinus/new-rss/start-code), you can customize your RSS feed further using the following fields.
|
||||
|
||||
It's important to note that not all fields are applicable to all output formats since RSSHub supports multiple output formats. The table below shows which fields are compatible with different output formats. We use the following symbols to denote compatibility: `A` for Atom, `J` for JSON Feed, `R` for RSS 2.0.
|
||||
|
||||
|
||||
@@ -67,9 +67,9 @@ sidebar_position: 2
|
||||
|
||||
When creating a new route in RSSHub, you need to organize your files in a specific way. Your namespace folder should be stored in the `lib/routes` directory and should include three mandatory files:
|
||||
|
||||
- `router.js` Registers the routes
|
||||
- `maintainer.js` Provides information about the route maintainer
|
||||
- `radar.js` Provide a [RSSHub Radar](https://github.com/DIYgod/RSSHub-Radar) rule for each route
|
||||
- `router.ts` Registers the routes
|
||||
- `maintainer.ts` Provides information about the route maintainer
|
||||
- `radar.ts` Provide a [RSSHub Radar](https://github.com/DIYgod/RSSHub-Radar) rule for each route
|
||||
|
||||
Your namespace folder structure should look like this:
|
||||
|
||||
@@ -78,16 +78,16 @@ Your namespace folder structure should look like this:
|
||||
│ ├───furstar
|
||||
│ ├─── templates
|
||||
│ ├─── description.art
|
||||
│ ├─── router.js
|
||||
│ ├─── maintainer.js
|
||||
│ ├─── radar.js
|
||||
│ ├─── someOtherJs.js
|
||||
│ ├─── router.ts
|
||||
│ ├─── maintainer.ts
|
||||
│ ├─── radar.ts
|
||||
│ ├─── someOtherJs.ts
|
||||
│ └───test
|
||||
│ └───someOtherNamespaces
|
||||
...
|
||||
```
|
||||
|
||||
**All eligible routes under the `lib/routes` path will be automatically loaded without the need for updating the `lib/router.js`.**
|
||||
**All eligible routes under the `lib/routes` path will be automatically loaded without the need for updating the `lib/router.ts`.**
|
||||
|
||||
### Namespace
|
||||
|
||||
@@ -100,11 +100,11 @@ RSSHub appends the name of all route namespace folders in front of the actual ro
|
||||
|
||||
### Registering a Route
|
||||
|
||||
To register a route, the `router.js` file should export a method that provides a Hoho route handler.
|
||||
To register a route, the `router.ts` file should export a method that provides a Hoho route handler.
|
||||
|
||||
### Maintainer List
|
||||
|
||||
The `maintainer.js` file should export an object that provides maintainer information related to the route, including:
|
||||
The `maintainer.ts` file should export an object that provides maintainer information related to the route, including:
|
||||
|
||||
- Key: Corresponding route path
|
||||
- Value: Array of string, including all maintainers' GitHub ID.
|
||||
@@ -119,9 +119,9 @@ The path should be the same as the `path` in the corresponding documentation bef
|
||||
|
||||
### Radar Rules
|
||||
|
||||
All routes are required to include the `radar.js` file, which includes the corresponding domain name. The minimum requirement for a successful match is for the rule to show up on the corresponding site which requires filling in the `title` and `docs` fields.
|
||||
All routes are required to include the `radar.ts` file, which includes the corresponding domain name. The minimum requirement for a successful match is for the rule to show up on the corresponding site which requires filling in the `title` and `docs` fields.
|
||||
|
||||
To generate a complete `radar-rules.js` file, use the following command: `yarn build:radar`, which will create the file under `assets/build/`.
|
||||
To generate a complete `radar-rules.ts` file, use the following command: `yarn build:radar`, which will create the file under `assets/build/`.
|
||||
|
||||
:::tip
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ sidebar_position: 3
|
||||
|
||||
# Using Cache
|
||||
|
||||
RSSHub have a cache module that expires after a short duration. You can change how long the cache lasts by modifying the `CACHE_EXPIRE` value in the `lib/config.js` file using environment variables. However, for interfaces that have less frequently updated content, it's better to specify a longer cache expiration time using `CACHE_CONTENT_EXPIRE` instead.
|
||||
RSSHub have a cache module that expires after a short duration. You can change how long the cache lasts by modifying the `CACHE_EXPIRE` value in the `lib/config.ts` file using environment variables. However, for interfaces that have less frequently updated content, it's better to specify a longer cache expiration time using `CACHE_CONTENT_EXPIRE` instead.
|
||||
|
||||
For example, to retrieve the full text of the first comment for each issue, you can make a request to `${baseUrl}/${user}/${repo}/issues/${id}`, since this data is unavailable through `${baseUrl}/${user}/${repo}/issues`. It's recommended to store this data in the cache to avoid making repeated requests to the server.
|
||||
|
||||
@@ -63,7 +63,7 @@ Any assignments to variables that are declared outside of the `tryGet()` functio
|
||||
|
||||
#### Defined in
|
||||
|
||||
[lib/middleware/cache/index.js](https://github.com/DIYgod/RSSHub/blob/master/lib/middleware/cache/index.js#L58)
|
||||
[lib/middleware/cache/index.ts](https://github.com/DIYgod/RSSHub/blob/master/lib/middleware/cache/index.ts#L58)
|
||||
|
||||
:::tip
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ If you want to see the results, we suggest you install the browser extension. Yo
|
||||
|
||||
## Code the rule
|
||||
|
||||
To create a new RSS feed, create a file called `radar.js` under the corresponding namespace in [/lib/routes/](https://github.com/DIYgod/RSSHub/tree/master/lib/routes). We will continue to use the example of creating an RSS feed for `GitHub Repo Issues`, which is described [here](/joinus/new-rss/before-start). The resulting code will look like this:
|
||||
To create a new RSS feed, create a file called `radar.ts` under the corresponding namespace in [/lib/routes/](https://github.com/DIYgod/RSSHub/tree/master/lib/routes). We will continue to use the example of creating an RSS feed for `GitHub Repo Issues`, which is described [here](/joinus/new-rss/before-start). The resulting code will look like this:
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
export default {
|
||||
'github.com': {
|
||||
_name: 'GitHub',
|
||||
'.': [
|
||||
@@ -44,7 +44,7 @@ The rest of the inner object keys are the subdomains of a website. If a website
|
||||
<TabItem value="github.com" label="github.com and www.github.com">
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
export default {
|
||||
'github.com': {
|
||||
_name: 'GitHub',
|
||||
// highlight-next-line
|
||||
@@ -64,7 +64,7 @@ module.exports = {
|
||||
<TabItem value="abc.github.com" label="abc.github.com">
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
export default {
|
||||
'github.com': {
|
||||
_name: 'GitHub',
|
||||
// highlight-next-line
|
||||
@@ -84,7 +84,7 @@ module.exports = {
|
||||
<TabItem value="abc.def.github.com" label="abc.def.github.com">
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
export default {
|
||||
'github.com': {
|
||||
_name: 'GitHub',
|
||||
// highlight-next-line
|
||||
@@ -149,7 +149,7 @@ Here are two examples of how to use the `target` field as a function:
|
||||
<TabItem value="params" label="Match using params">
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
export default {
|
||||
'github.com': {
|
||||
_name: 'GitHub',
|
||||
'.': [
|
||||
@@ -169,7 +169,7 @@ module.exports = {
|
||||
<TabItem value="url" label="Match using URL">
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
export default {
|
||||
'github.com': {
|
||||
_name: 'GitHub',
|
||||
'.': [
|
||||
|
||||
@@ -68,9 +68,9 @@ The documentation is written in MDX v3 and rendered with [Docusaurus v3](https:/
|
||||
|
||||
To add documentation to your route, use the `Route` React component. It works like HTML tag. The following are the most commonly used component properties:
|
||||
|
||||
- `author`: The route maintainer(s), separated by a single space. It should be the same as [`maintainer.js`](/joinus/new-rss/before-start#understand-the-basics-maintainer-js)
|
||||
- `author`: The route maintainer(s), separated by a single space. It should be the same as [`maintainer.ts`](/joinus/new-rss/before-start#understand-the-basics-maintainer-js)
|
||||
- `example`: The route example, with a leading `/`
|
||||
- `path`: The route path, which should be the same as the key in [`maintainer.js`](/joinus/new-rss/before-start#understand-the-basics-maintainer-js) with the namespace. In the above example, it is `/github/issue/:user/:repo?`
|
||||
- `path`: The route path, which should be the same as the key in [`maintainer.ts`](/joinus/new-rss/before-start#understand-the-basics-maintainer-js) with the namespace. In the above example, it is `/github/issue/:user/:repo?`
|
||||
- `paramsDesc`: The route parameter description, in an array of strings that support Markdown.
|
||||
- The description **must** follow the order in which they appear in the path.
|
||||
- The number of description should match with the number of parameters in `path`. If you miss a description, the build will fail.
|
||||
|
||||
@@ -86,11 +86,11 @@ When creating a namespace, it's important to avoid creating multiple namespaces
|
||||
|
||||
## Understand the Basics
|
||||
|
||||
### router.js
|
||||
### router.ts
|
||||
|
||||
Once you have created the namespace for your RSS route, the next step is to register it in the `router.js`
|
||||
Once you have created the namespace for your RSS route, the next step is to register it in the `router.ts`
|
||||
|
||||
For example, if you are creating an RSS feed for [GitHub Repo Issues](/routes/programming#github-repo-issues) and suppose you want users to enter a GitHub username and a repository name, and fall back to `RSSHub` if they don't enter the repository name, you can register your new RSS route in `github/router.js` using the following code:
|
||||
For example, if you are creating an RSS feed for [GitHub Repo Issues](/routes/programming#github-repo-issues) and suppose you want users to enter a GitHub username and a repository name, and fall back to `RSSHub` if they don't enter the repository name, you can register your new RSS route in `github/router.ts` using the following code:
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="Arrow Functions" label="Arrow Functions" default>
|
||||
@@ -115,7 +115,7 @@ export default function (router) {
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
When registering your new RSS route in `router.js`, you can define the route path and specify the corresponding function to be executed. In the code above, the `router.get()` method is used to specify the HTTP method and the path of the new RSS route. The first parameter of `router.get()` is the route path using [Hono routing](https://hono.dev/api/routing) syntax. The second parameter is the relative path of your new RSS rule, `issue.js`. Note that you can omit the `.js` extension.
|
||||
When registering your new RSS route in `router.ts`, you can define the route path and specify the corresponding function to be executed. In the code above, the `router.get()` method is used to specify the HTTP method and the path of the new RSS route. The first parameter of `router.get()` is the route path using [Hono routing](https://hono.dev/api/routing) syntax. The second parameter is the relative path of your new RSS rule, `issue.ts`. Note that you can omit the `.ts` extension.
|
||||
|
||||
In the example above, `issue` is an exact match, `:user` is a required parameter, and `:repo?` is an optional parameter. The `?` after `:repo` means that the parameter is optional. If the user does not enter repo, it will fall back to whatever is specified in your code (in this case, `RSSHub`).
|
||||
|
||||
@@ -127,18 +127,18 @@ For more advanced usage of `router`, see the [Hono Routing API Reference](https:
|
||||
|
||||
:::
|
||||
|
||||
### maintainer.js
|
||||
### maintainer.ts
|
||||
|
||||
This file is used to store information about the maintainer of the RSS routes. You can add your GitHub username to the value array. Note that the key here should exactly match the path in `router.js` :
|
||||
This file is used to store information about the maintainer of the RSS routes. You can add your GitHub username to the value array. Note that the key here should exactly match the path in `router.ts` :
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
export default {
|
||||
// highlight-next-line
|
||||
'/issue/:user/:repo?': ['DIYgod'],
|
||||
};
|
||||
```
|
||||
|
||||
The `maintainer.js` file is useful for keeping track of who is responsible for maintaining an RSS route. When a user encounters an issue with your RSS route, they can reach out to the maintainers listed in this file.
|
||||
The `maintainer.ts` file is useful for keeping track of who is responsible for maintaining an RSS route. When a user encounters an issue with your RSS route, they can reach out to the maintainers listed in this file.
|
||||
|
||||
### `templates` folder
|
||||
|
||||
@@ -146,11 +146,11 @@ The `templates` folder contains templates for your new RSS route. You only need
|
||||
|
||||
Each template file should have a `.art` file extension.
|
||||
|
||||
### radar.js
|
||||
### radar.ts
|
||||
|
||||
The `radar.js` file helps users subscribe to your new RSS route when they use [RSSHub Radar](https://github.com/DIYgod/RSSHub-Radar) or other software that is compatible with its format. We'll cover more about this in a later section.
|
||||
The `radar.ts` file helps users subscribe to your new RSS route when they use [RSSHub Radar](https://github.com/DIYgod/RSSHub-Radar) or other software that is compatible with its format. We'll cover more about this in a later section.
|
||||
|
||||
### Your new RSS route `issue.js`
|
||||
### Your new RSS route `issue.ts`
|
||||
|
||||
Now you can [start writing](/joinus/new-rss/start-code) your new RSS route.
|
||||
|
||||
|
||||
@@ -19,12 +19,12 @@ Different sites have different APIs. You can check the API documentation for the
|
||||
|
||||
### Create the main file
|
||||
|
||||
Open your code editor and create a new file. Since we are going to create an RSS feed for GitHub issues, it is suggested that you save the file as `issue.js`, but you can name it whatever you like.
|
||||
Open your code editor and create a new file. Since we are going to create an RSS feed for GitHub issues, it is suggested that you save the file as `issue.ts`, but you can name it whatever you like.
|
||||
|
||||
Here's the basic code to get you started:
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="issue.js" label="issue.js">
|
||||
<TabItem value="issue.ts" label="issue.ts">
|
||||
|
||||
```js
|
||||
// Import the necessary modules
|
||||
@@ -255,7 +255,7 @@ export default async (ctx) => {
|
||||
|
||||
### Creat the main file
|
||||
|
||||
To start, open your code editor and create a new file. Since we are going to create an RSS feed for GitHub issues, it is suggested that you save the file as `issue.js`. However, you can also name it whatever you like.
|
||||
To start, open your code editor and create a new file. Since we are going to create an RSS feed for GitHub issues, it is suggested that you save the file as `issue.ts`. However, you can also name it whatever you like.
|
||||
|
||||
Here's the basic code to get you started:
|
||||
|
||||
@@ -480,7 +480,7 @@ First, we need a few data:
|
||||
2. The data source link
|
||||
3. The RSS feed title (not the title of individual items)
|
||||
|
||||
Open your code editor and create a new file. Since we're going to create an RSS feed for GitHub issues, it's suggested that you save the file as `issue.js`, but you can name it whatever you like.
|
||||
Open your code editor and create a new file. Since we're going to create an RSS feed for GitHub issues, it's suggested that you save the file as `issue.ts`, but you can name it whatever you like.
|
||||
|
||||
Here's some basic code to get you started:
|
||||
|
||||
@@ -591,7 +591,7 @@ Using puppeteer is another approach to obtain data from websites. However, it is
|
||||
|
||||
### Creat the main file
|
||||
|
||||
To get started with puppeteer, create a new file in your code editor and save it with an appropriate name, such as `issue.js`. Then, require the necessary modules and set up the basic structure of the function:
|
||||
To get started with puppeteer, create a new file in your code editor and save it with an appropriate name, such as `issue.ts`. Then, require the necessary modules and set up the basic structure of the function:
|
||||
|
||||
```js
|
||||
// Require some useful modules
|
||||
|
||||
@@ -109,7 +109,7 @@ Use this section to include any additional information or comments you'd like to
|
||||
|
||||
The pull request title will be used as the commit message when your pull request is merged. Please follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) specification.
|
||||
|
||||
If you are adding a new route, including all required documentation and `radar.js`, use `route` as the scope. If you are adding new radar rules only, use `radar` as the scope.
|
||||
If you are adding a new route, including all required documentation and `radar.ts`, use `route` as the scope. If you are adding new radar rules only, use `radar` as the scope.
|
||||
|
||||
## Response to Code Review
|
||||
|
||||
|
||||
@@ -286,10 +286,10 @@ GitHub provides some official RSS feeds:
|
||||
|
||||
### Files Commits {#github-files-commits}
|
||||
|
||||
<Route author="zengxs" example="/github/file/DIYgod/RSSHub/master/lib/router.js" path="/github/file/:user/:repo/:branch/:filepath+" paramsDesc={['User name', 'Repo name', 'Branch name', 'File path']} radar="1">
|
||||
<Route author="zengxs" example="/github/file/DIYgod/RSSHub/master/lib/router.ts" path="/github/file/:user/:repo/:branch/:filepath+" paramsDesc={['User name', 'Repo name', 'Branch name', 'File path']} radar="1">
|
||||
| User name | Repo name | Branch name | File path |
|
||||
| --------- | --------- | ----------- | --------------- |
|
||||
| `DIYgod` | `RSSHub` | `master` | `lib/router.js` |
|
||||
| `DIYgod` | `RSSHub` | `master` | `lib/router.ts` |
|
||||
|
||||
> - If there are special characters such as `/` in the **branch name**, they need to be encoded with urlencode, usually `/` needs to be replaced with `%2f`
|
||||
>
|
||||
|
||||
@@ -12,7 +12,7 @@ RSSHub 提供下列 API:
|
||||
|
||||
:::tip
|
||||
|
||||
`protected_router.js`下的路由**不会被**包含在此 API 返回的结果当中.
|
||||
`protected_router.ts`下的路由**不会被**包含在此 API 返回的结果当中.
|
||||
|
||||
:::
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import Translate from '@docusaurus/Translate';
|
||||
|
||||
**Q: RSSHub Radar 是如何工作的?**
|
||||
|
||||
**A:** 进入新页面时, RSSHub Radar 先根据页面 link 标签[寻找](https://github.com/DIYgod/RSSHub-Radar/blob/master/src/js/content/utils.js#L25)页面自带 RSS,再根据远程更新的[规则](https://github.com/DIYgod/RSSHub/blob/master/assets/radar-rules.js)寻找适用当前页面和当前网站的 RSSHub 路由;再加一点点魔法。
|
||||
**A:** 进入新页面时, RSSHub Radar 先根据页面 link 标签[寻找](https://github.com/DIYgod/RSSHub-Radar/blob/master/src/js/content/utils.ts#L25)页面自带 RSS,再根据远程更新的[规则](https://github.com/DIYgod/RSSHub/blob/master/assets/radar-rules.js)寻找适用当前页面和当前网站的 RSSHub 路由;再加一点点魔法。
|
||||
|
||||
**Q: 演示地址可以用么?**
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ RSSHub 支持使用访问密钥 / 码进行访问控制。开启将会激活全
|
||||
|
||||
:::tip
|
||||
|
||||
此处信息不完整。完整配置请参考路由对应的文档和 `lib/config.js`。
|
||||
此处信息不完整。完整配置请参考路由对应的文档和 `lib/config.ts`。
|
||||
|
||||
:::
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ sidebar_position: 1
|
||||
|
||||
本指南面向希望深入了解如何制作 RSS 订阅源的高级用户。如果您是第一次制作 RSS 订阅源,我们建议先阅读 [制作自己的 RSSHub 路由](/zh/joinus/new-rss/start-code)。
|
||||
|
||||
一旦您获取了要包含在您的 RSS 订阅源中的数据,就可以将其传递给 `ctx.set('data', obj)`。然后RSSHub的中间件 [`template.js`](https://github.com/DIYgod/RSSHub/blob/master/lib/middleware/template.js) 将处理数据并以所需的格式呈现 RSS 输出(默认为RSS 2.0)。除了 [制作自己的 RSSHub 路由](/zh/joinus/new-rss/start-code) 中提到的字段外,您还可以使用以下字段进一步自定义 RSS 订阅源。
|
||||
一旦您获取了要包含在您的 RSS 订阅源中的数据,就可以将其传递给 `ctx.set('data', obj)`。然后RSSHub的中间件 [`template.ts`](https://github.com/DIYgod/RSSHub/blob/master/lib/middleware/template.ts) 将处理数据并以所需的格式呈现 RSS 输出(默认为RSS 2.0)。除了 [制作自己的 RSSHub 路由](/zh/joinus/new-rss/start-code) 中提到的字段外,您还可以使用以下字段进一步自定义 RSS 订阅源。
|
||||
|
||||
需要注意的是,并非所有字段都适用于所有的输出格式,因为 RSSHub 支持多种输出格式。下表显示了不同输出格式兼容的字段。我们使用以下符号表示兼容性:`A` 表示 Atom,`J` 表示 JSON Feed,`R` 表示 RSS 2.0。
|
||||
|
||||
|
||||
+11
-11
@@ -67,9 +67,9 @@ sidebar_position: 2
|
||||
|
||||
当在 RSSHub 中编写新的路由时,需要按特定方式组织文件。命名空间文件夹应该存储在 `lib/routes` 目录下,并且应包括三个必需文件:
|
||||
|
||||
- `router.js` 注册路由
|
||||
- `maintainer.js` 提供路由维护者信息
|
||||
- `radar.js` 为每个路由提供对应 [RSSHub Radar](https://github.com/DIYgod/RSSHub-Radar) 规则
|
||||
- `router.ts` 注册路由
|
||||
- `maintainer.ts` 提供路由维护者信息
|
||||
- `radar.ts` 为每个路由提供对应 [RSSHub Radar](https://github.com/DIYgod/RSSHub-Radar) 规则
|
||||
|
||||
命名空间文件夹结构应该像这样:
|
||||
|
||||
@@ -77,15 +77,15 @@ sidebar_position: 2
|
||||
│ ├───furstar
|
||||
│ ├─── templates
|
||||
│ ├─── description.art
|
||||
│ ├─── router.js
|
||||
│ ├─── maintainer.js
|
||||
│ ├─── radar.js
|
||||
│ ├─── someOtherJs.js
|
||||
│ ├─── router.ts
|
||||
│ ├─── maintainer.ts
|
||||
│ ├─── radar.ts
|
||||
│ ├─── someOtherJs.ts
|
||||
│ └───test
|
||||
│ └───someOtherNamespaces
|
||||
...
|
||||
|
||||
**所有符合条件的,在 `lib/routes` 路径下的路由将会被自动载入,无需更新 `lib/router.js`**
|
||||
**所有符合条件的,在 `lib/routes` 路径下的路由将会被自动载入,无需更新 `lib/router.ts`**
|
||||
|
||||
### 命名空间
|
||||
|
||||
@@ -98,11 +98,11 @@ RSSHub 会将所有路由命名空间的文件夹名附加到路由前面。路
|
||||
|
||||
### 注册路由
|
||||
|
||||
`router.js` 文件应导出一个方法,提供一个 Hoho route handler。
|
||||
`router.ts` 文件应导出一个方法,提供一个 Hoho route handler。
|
||||
|
||||
### 维护者列表
|
||||
|
||||
`maintainer.js` 文件应导出一个对象,提供与路由相关的维护者信息,包括:
|
||||
`maintainer.ts` 文件应导出一个对象,提供与路由相关的维护者信息,包括:
|
||||
|
||||
- 键: 对应的路由
|
||||
- 值:一个字符串数组,包括所有维护者的 GitHub ID。
|
||||
@@ -117,7 +117,7 @@ RSSHub 会将所有路由命名空间的文件夹名附加到路由前面。路
|
||||
|
||||
### Radar 规则
|
||||
|
||||
所有路由都需要包含 `radar.js` 文件,其中包括相应的域名。最低要求是规则出现在相应的站点上,即需要填写 `title` 和 `docs` 字段。
|
||||
所有路由都需要包含 `radar.ts` 文件,其中包括相应的域名。最低要求是规则出现在相应的站点上,即需要填写 `title` 和 `docs` 字段。
|
||||
|
||||
要生成完整的 `radar-rules.js` 文件,可使用以下命令:`yarn build:radar`,它将在 `assets/build/` 目录下创建文件。
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ RSSHub 有一个缓存模块,该缓存在短时间后过期。您可以通过
|
||||
|
||||
#### 定义在
|
||||
|
||||
[lib/middleware/cache/index.js](https://github.com/DIYgod/RSSHub/blob/master/lib/middleware/cache/index.js#L58)
|
||||
[lib/middleware/cache/index.ts](https://github.com/DIYgod/RSSHub/blob/master/lib/middleware/cache/index.ts#L58)
|
||||
|
||||
:::tip
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ sidebar_position: 3
|
||||
|
||||
## 编写规则
|
||||
|
||||
要制作新的 RSSHub Radar 规则,需要在 `/lib/routes/` 目录下,相应的域名空间创建 `radar.js` 文件。下面以制作 `GitHub 仓库 Issues` 的 RSS 源为例,详见此处。编写的代码应如下所示:
|
||||
要制作新的 RSSHub Radar 规则,需要在 `/lib/routes/` 目录下,相应的域名空间创建 `radar.ts` 文件。下面以制作 `GitHub 仓库 Issues` 的 RSS 源为例,详见此处。编写的代码应如下所示:
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
export default {
|
||||
'github.com': {
|
||||
_name: 'GitHub',
|
||||
'.': [
|
||||
@@ -44,7 +44,7 @@ module.exports = {
|
||||
<TabItem value="github.com" label="github.com 和 www.github.com">
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
export default {
|
||||
'github.com': {
|
||||
_name: 'GitHub',
|
||||
// highlight-next-line
|
||||
@@ -64,7 +64,7 @@ module.exports = {
|
||||
<TabItem value="abc.github.com" label="abc.github.com">
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
export default {
|
||||
'github.com': {
|
||||
_name: 'GitHub',
|
||||
// highlight-next-line
|
||||
@@ -84,7 +84,7 @@ module.exports = {
|
||||
<TabItem value="abc.def.github.com" label="abc.def.github.com">
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
export default {
|
||||
'github.com': {
|
||||
_name: 'GitHub',
|
||||
// highlight-next-line
|
||||
@@ -145,7 +145,7 @@ source 应为一个字符串数组。例如,如果 `GitHub 仓库 Issues` 的
|
||||
<TabItem value="params" label="使用 params 匹配">
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
export default {
|
||||
'github.com': {
|
||||
_name: 'GitHub',
|
||||
'.': [
|
||||
@@ -165,7 +165,7 @@ module.exports = {
|
||||
<TabItem value="url" label="使用 URL 匹配">
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
export default {
|
||||
'github.com': {
|
||||
_name: 'GitHub',
|
||||
'.': [
|
||||
|
||||
@@ -78,9 +78,9 @@ pnpm run start
|
||||
|
||||
要为您的路由添加文档,请使用 `Route` React 组件。它类似于 HTML 标签。以下是最常用的组件属性:
|
||||
|
||||
- `author`:路由维护者,用单个空格分隔。应与 [`maintainer.js`](/zh/joinus/new-rss/before-start#maintainerjs) 相同
|
||||
- `author`:路由维护者,用单个空格分隔。应与 [`maintainer.ts`](/zh/joinus/new-rss/before-start#maintainerjs) 相同
|
||||
- `example`:路由示例,以 `/` 开头
|
||||
- `path`:路由,应与添加命名空间后 [maintainer.js](/zh/joinus/new-rss/before-start#maintainerjs) 中的键相同。在之前的教程中,它为 `/github/issue/:user/:repo?`
|
||||
- `path`:路由,应与添加命名空间后 [maintainer.ts](/zh/joinus/new-rss/before-start#maintainerjs) 中的键相同。在之前的教程中,它为 `/github/issue/:user/:repo?`
|
||||
- `paramsDesc`:路由参数描述,以字符串数组形式,支持 Markdown。
|
||||
- 描述必须按照它们在路由中出现的顺序。
|
||||
- 描述的数量**应**与 `path` 中的参数数量匹配。如果漏掉一个描述,则构建过程会失败。
|
||||
|
||||
+9
-9
@@ -86,11 +86,11 @@ npm run dev
|
||||
|
||||
## 理解基础知识
|
||||
|
||||
### router.js
|
||||
### router.ts
|
||||
|
||||
一旦您为 RSS 路由创建了命名空间,下一步就是在 `router.js` 中注册它。
|
||||
一旦您为 RSS 路由创建了命名空间,下一步就是在 `router.ts` 中注册它。
|
||||
|
||||
例如,如果您为 [GitHub 仓库 Issues](/zh/routes/programming#github-yong-hu-cang-ku) 制作 RSS 源,并且假设您希望用户输入 GitHub 用户名和仓库名,如果他们没有输入仓库名,则返回到 `RSSHub`,您可以使用以下代码在 `github/router.js` 中注册您的新 RSS 路由:
|
||||
例如,如果您为 [GitHub 仓库 Issues](/zh/routes/programming#github-yong-hu-cang-ku) 制作 RSS 源,并且假设您希望用户输入 GitHub 用户名和仓库名,如果他们没有输入仓库名,则返回到 `RSSHub`,您可以使用以下代码在 `github/router.ts` 中注册您的新 RSS 路由:
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="Arrow Functions" label="箭头函数" active>
|
||||
@@ -115,7 +115,7 @@ export default function (router) {
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
在 `router.js` 中注册您的新 RSS 路由时,您可以定义路由路径并指定要执行的相应函数。在上面的代码中,`router.get()` 方法用于指定新的 RSS 路由的 HTTP 方法和路径。`router.get()` 的第一个参数是使用 [Hono 路由](https://hono.dev/api/routing) 语法的路由路径。第二个参数是您新的 RSS 规则 `issue.js` 的相对路径。您可以省略 `.js` 扩展名。
|
||||
在 `router.ts` 中注册您的新 RSS 路由时,您可以定义路由路径并指定要执行的相应函数。在上面的代码中,`router.get()` 方法用于指定新的 RSS 路由的 HTTP 方法和路径。`router.get()` 的第一个参数是使用 [Hono 路由](https://hono.dev/api/routing) 语法的路由路径。第二个参数是您新的 RSS 规则 `issue.js` 的相对路径。您可以省略 `.js` 扩展名。
|
||||
|
||||
在上面的示例中,`issue` 是一个精确匹配,`:user` 是一个必需参数,`:repo?` 是一个可选参数。`?` 在 `:repo` 之后表示该参数是可选的。如果用户没有输入仓库名,则会返回到您代码中指定的内容(这里是 `RSSHub`)。
|
||||
|
||||
@@ -127,18 +127,18 @@ export default function (router) {
|
||||
|
||||
:::
|
||||
|
||||
### maintainer.js
|
||||
### maintainer.ts
|
||||
|
||||
该文件用于存储 RSS 路由的维护者信息。您可以将您的 GitHub 用户名添加到该值数组中。请注意,此处的键应与 `router.js` 中的路径完全匹配:
|
||||
该文件用于存储 RSS 路由的维护者信息。您可以将您的 GitHub 用户名添加到该值数组中。请注意,此处的键应与 `router.ts` 中的路径完全匹配:
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
export default {
|
||||
// highlight-next-line
|
||||
'/issue/:user/:repo?': ['DIYgod'],
|
||||
};
|
||||
```
|
||||
|
||||
`maintainer.js` 文件有助于跟踪负责维护 RSS 路由的人员。当用户遇到 RSS 路由的问题时,他们可以联系此文件中列出的维护者。
|
||||
`maintainer.ts` 文件有助于跟踪负责维护 RSS 路由的人员。当用户遇到 RSS 路由的问题时,他们可以联系此文件中列出的维护者。
|
||||
|
||||
### `templates` 文件夹
|
||||
|
||||
@@ -146,7 +146,7 @@ module.exports = {
|
||||
|
||||
每个模板文件应该有一个 `.art` 文件扩展名。
|
||||
|
||||
### radar.js
|
||||
### radar.ts
|
||||
|
||||
文件可以帮助用户在使用 [RSSHub Radar](https://github.com/DIYgod/RSSHub-Radar) 或其他兼容其格式的软件时订阅您的新 RSS 路由。我们将在后面的部分更多介绍。
|
||||
|
||||
|
||||
@@ -19,12 +19,12 @@ sidebar_position: 3
|
||||
|
||||
### 创建主文件
|
||||
|
||||
打开您的代码编辑器并创建一个新文件。由于我们要为 GitHub 仓库 Issues 制作 RSS 源,因此建议将文件命名为 `issue.js`。
|
||||
打开您的代码编辑器并创建一个新文件。由于我们要为 GitHub 仓库 Issues 制作 RSS 源,因此建议将文件命名为 `issue.ts`。
|
||||
|
||||
以下是让您开始的基本代码:
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="issue.js" label="issue.js">
|
||||
<TabItem value="issue.ts" label="issue.ts">
|
||||
|
||||
```js
|
||||
// 导入所需模组
|
||||
@@ -252,7 +252,7 @@ export default async (ctx) => {
|
||||
|
||||
### 创建主文件
|
||||
|
||||
打开您的代码编辑器并创建一个新文件。由于我们要为 GitHub 仓库 Issues 制作 RSS 源,因此建议将文件命名为 `issue.js`。
|
||||
打开您的代码编辑器并创建一个新文件。由于我们要为 GitHub 仓库 Issues 制作 RSS 源,因此建议将文件命名为 `issue.ts`。
|
||||
|
||||
以下是让您开始的基本代码:
|
||||
|
||||
@@ -477,7 +477,7 @@ export default async (ctx) => {
|
||||
2. 数据来源链接
|
||||
3. RSS 订阅标题(不是每个文章的标题)
|
||||
|
||||
打开您的代码编辑器并创建一个新文件。由于我们要为 GitHub 仓库 Issues 制作 RSS 源,因此建议将文件命名为 `issue.js`。
|
||||
打开您的代码编辑器并创建一个新文件。由于我们要为 GitHub 仓库 Issues 制作 RSS 源,因此建议将文件命名为 `issue.ts`。
|
||||
|
||||
这是一些基础代码,你可以从这里开始:
|
||||
|
||||
@@ -588,7 +588,7 @@ export default async (ctx) => {
|
||||
|
||||
### 创建主文件
|
||||
|
||||
创建一个新文件并使用适当的名称保存,例如 `issue.js`。然后,导入所需模组并设置函数的基本结构:
|
||||
创建一个新文件并使用适当的名称保存,例如 `issue.ts`。然后,导入所需模组并设置函数的基本结构:
|
||||
|
||||
```js
|
||||
// 导入所需模组
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ NOROUTE
|
||||
|
||||
当您的拉取请求被合并时,拉取请求标题将用作提交信息。请遵循 [约定式提交](https://www.conventionalcommits.org/zh-hans/v1.0.0/#概述) 规范。
|
||||
|
||||
如果您正在添加新的路由,包括所有必需的文档和 `radar.js`,请以 `route` 作为范围。如果仅添加新的 Radar 规则,则请以 `radar` 作为范围。
|
||||
如果您正在添加新的路由,包括所有必需的文档和 `radar.ts`,请以 `route` 作为范围。如果仅添加新的 Radar 规则,则请以 `radar` 作为范围。
|
||||
|
||||
## 回复代码审查
|
||||
|
||||
|
||||
Reference in New Issue
Block a user