feat(route): add Ian Spriggss (#13772)

* feat(route): add Ian Spriggss

* fix typo

* fix: add null checks
This commit is contained in:
Ethan Shen
2023-11-13 22:48:19 +08:00
committed by GitHub
parent b76ad36c68
commit af11b7e767
6 changed files with 138 additions and 0 deletions
+90
View File
@@ -0,0 +1,90 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const { category = 'portraits' } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;
const author = 'Ian Spriggs';
const rootUrl = 'https://ianspriggs.com';
const currentUrl = new URL(category, rootUrl).href;
const { data: response } = await got(currentUrl);
const $ = cheerio.load(response);
let items = $('div.work-item')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);
const image = item.find('img').first();
return {
title: item.find('div.work-info').text(),
link: item.find('a').prop('href'),
description: art(path.join(__dirname, 'templates/description.art'), {
images: image?.prop('src')
? [
{
src: image.prop('src').replace(/_thumbnail\./, '.'),
alt: image.prop('alt'),
},
]
: undefined,
}),
author,
pubDate: parseDate(item.find('div.work-info p').last(), 'YYYY'),
enclosure_url: image?.prop('src') ?? undefined,
enclosure_type: image?.prop('src') ? 'image/jpeg' : undefined,
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: detailResponse } = await got(item.link);
const content = cheerio.load(detailResponse);
const images = content('div.work-item img')
.toArray()
.map((item) => {
item = content(item);
return {
src: item.prop('src').replace(/-\d+x\d+\./, '.'),
alt: item.prop('alt'),
};
});
item.title = content('div.project-title').text();
item.description += art(path.join(__dirname, 'templates/description.art'), {
images,
description: content('div.nectar-fancy-ul').html(),
});
item.pubDate = parseDate(content('span.subheader').last().text(), 'YYYY');
return item;
})
)
);
const icon = new URL('favicon.ico', rootUrl).href;
ctx.state.data = {
item: items,
title: $('title').text(),
link: currentUrl,
description: $('meta[property="og:description"]').prop('content'),
language: $('html').prop('lang'),
icon,
logo: icon,
subtitle: $('a[aria-current="page"] span.menu-title-text').text(),
author,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/:category?': ['nczitzk'],
};
+17
View File
@@ -0,0 +1,17 @@
module.exports = {
'ianspriggs.com': {
_name: 'Ian Spriggs',
'.': [
{
title: 'Category',
docs: 'https://docs.rsshub.app/routes/blog#ian-spriggs-category',
source: ['/:category'],
target: (params) => {
const category = params.category;
return `/ianspriggs${category ? `/${category}` : ''}`;
},
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:category?', require('./'));
};
@@ -0,0 +1,13 @@
{{ each images image }}
<figure>
<img
{{ if image.alt }}
alt="{{ image.alt }}"
{{ /if }}
src="{{ image.src }}">
</figure>
{{ /each }}
{{ if description }}
{{@ description }}
{{ /if }}
+12
View File
@@ -132,6 +132,18 @@ username 为博主用户名,而非`xxx.hashnode.dev`中`xxx`所代表的 blog
<Route author="DIYgod" example="/blogs/diygod/gk" path="/blogs/diygod/gk"/>
## Ian Spriggss {#ian-spriggss}
### Category {#ian-spriggss-category}
<Route author="nczitzk" example="/ianspriggs/portraits" path="/ianspriggs/:category?" paramsDesc={['Category, see below, 3D PORTRAITS by default']} radar="1" rssbud="1">
| 3D PORTRAITS | CHARACTERS |
| ------------ | ---------- |
| portraits | characters |
</Route>
## JustRun {#justrun}
### JustRun {#justrun-justrun}