Skip to content

Commit

Permalink
feat(route): instructables projects (DIYgod#12179)
Browse files Browse the repository at this point in the history
* add instructables projects

* docs

* add maintainer.js; correct radar.js

* fix doc

* fix radar.js

* fix maintainer.js

* add pubDate

* fix teachers category
  • Loading branch information
wolfg1969 authored Mar 27, 2023
1 parent 294e690 commit 6785933
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/en/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ Official Website: <https://news.yahoo.co.jp/pages/article/20200207>

<RouteEn author="LogicJake" example="/instapaper/person/viridiano" path="/instapaper/person"/>

## Instructables

### Projects

<RouteEn author="wolfg1969" example="/instructables/projects/circuits" path="/instructables/projects/:category?" :paramsDesc="['Category, empty by default, can be found in URL or see the table below']" radar="1">

| All | Circuits | Workshop | Craft | Cooking | Living | Outside | Teachers |
| --- | -------- | -------- | ----- | ------- | ------ | ------- | -------- |
| | circuits | workshop | craft | cooking | living | outside | teachers |

</RouteEn>

## Japanpost

### Track & Trace Service
Expand Down
12 changes: 12 additions & 0 deletions docs/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ pageClass: routes

<Route author="LogicJake" example="/instapaper/person/viridiano" path="/instapaper/person"/>

## Instructables

### Projects

<Route author="wolfg1969" example="/instructables/projects/circuits" path="/instructables/projects/:category?" :paramsDesc="['项目类别。默认空值为全部,从网页地址中得知,见下表']" radar="1">

| All | Circuits | Workshop | Craft | Cooking | Living | Outside | Teachers |
| --- | -------- | -------- | ----- | ------- | ------ | ------- | -------- |
| | circuits | workshop | craft | cooking | living | outside | teachers |

</Route>

## iYouport

### 首页(旧版)
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/instructables/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/projects/:category?': ['wolfg1969'],
};
55 changes: 55 additions & 0 deletions lib/v2/instructables/projects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const got = require('@/utils/got');

module.exports = async (ctx) => {
const category = ctx.params.category ?? 'all';

const siteDomain = 'www.instructables.com';
const apiKey = 'NU5CdGwyRDdMVnVmM3l4cWNqQzFSVzJNZU5jaUxFU3dGK3J2L203MkVmVT02ZWFYeyJleGNsdWRlX2ZpZWxkcyI6WyJvdXRfb2YiLCJzZWFyY2hfdGltZV9tcyIsInN0ZXBCb2R5Il0sInBlcl9wYWdlIjo1MH0=';

let pathPrefix, projectFilter;
if (category === 'all') {
pathPrefix = '';
projectFilter = '';
} else {
pathPrefix = `${category}/`;
const filterValue = `${category.charAt(0).toUpperCase()}${category.slice(1)}`;
projectFilter = category !== 'teachers' ? ` && category:=${filterValue}` : `&& teachers:=${filterValue}`;
}

const link = `https://${siteDomain}/${pathPrefix}projects?projects=all`;

const response = await got({
method: 'get',
url: `https://${siteDomain}/api_proxy/search/collections/projects/documents/search`,
headers: {
Referer: link,
Host: siteDomain,
'x-typesense-api-key': apiKey,
},
searchParams: {
q: '*',
query_by: 'title,stepBody,screenName',
page: 1,
per_page: 50,
sort_by: 'publishDate:desc',
include_fields: 'title,urlString,coverImageUrl,screenName,publishDate,favorites,views,primaryClassification,featureFlag,prizeLevel,IMadeItCount',
filter_by: `featureFlag:=true${projectFilter}`,
},
});

const data = response.data;

ctx.state.data = {
title: 'Instructables Projects', // 项目的标题
link, // 指向项目的链接
description: 'Instructables Projects', // 描述项目
language: 'en', // 频道语言
item: data.hits.map((item) => ({
title: item.document.title,
link: `https://${siteDomain}/${item.document.urlString}`,
author: item.document.screenName,
pubDate: new Date(item.document.publishDate).toUTCString(),
category: item.document.primaryClassification,
})),
};
};
19 changes: 19 additions & 0 deletions lib/v2/instructables/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
'instructables.com': {
_name: 'Instructables',
'.': [
{
title: 'All Projects - Instructables',
docs: 'https://docs.rsshub.app/other.html#instructables',
source: ['/projects'],
target: '/instructables/projects',
},
{
title: 'Projects - Instructables',
docs: 'https://docs.rsshub.app/other.html#instructables',
source: ['/:category/projects'],
target: (params) => `/instructables/projects/${params.category}`,
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/instructables/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/projects/:category?', require('./projects'));
};

0 comments on commit 6785933

Please sign in to comment.