-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(route): add 川流严选 * fix: add null check * fix: add null check
- Loading branch information
Showing
6 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/nice': ['nczitzk'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const { art } = require('@/utils/render'); | ||
const path = require('path'); | ||
const md = require('markdown-it')({ | ||
html: true, | ||
}); | ||
|
||
module.exports = async (ctx) => { | ||
const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 100; | ||
|
||
const rootUrl = 'https://chuanliu.org'; | ||
const apiRootUrl = 'https://s.chuanliu.org'; | ||
const currentUrl = new URL('nice/', rootUrl).href; | ||
const apiUrl = new URL('api/dis/api/v1/memo', apiRootUrl).href; | ||
|
||
const { data: response } = await got(apiUrl, { | ||
searchParams: { | ||
creatorId: 1, | ||
offset: 0, | ||
limit, | ||
}, | ||
}); | ||
|
||
const items = response.slice(0, limit).map((item) => { | ||
const contents = item.content.split(/\n/); | ||
|
||
const category = contents?.[0].replace(/^#/, '') ?? undefined; | ||
const title = contents?.[1] ?? undefined; | ||
const link = contents?.[2] ?? undefined; | ||
const author = contents?.[3] ?? undefined; | ||
const isStar = (contents?.[5] && contents[5] === 'star') ?? false; | ||
|
||
if (isStar) { | ||
contents.splice(5, 1); | ||
} | ||
|
||
return { | ||
title: `${isStar ? '[STAR] ' : ''}${title}`, | ||
link, | ||
description: art(path.join(__dirname, 'templates/description.art'), { | ||
description: md.render(contents?.join('\n\n') ?? ''), | ||
images: item.resourceList.map((i) => ({ | ||
src: i.externalLink, | ||
alt: i.filename, | ||
type: i.type, | ||
})), | ||
}), | ||
author, | ||
category: [category, isStar ? 'STAR' : undefined].filter(Boolean), | ||
guid: `chuanliu-nice#${item.id}`, | ||
pubDate: parseDate(item.createdTs, 'X'), | ||
updated: parseDate(item.updatedTs, 'X'), | ||
}; | ||
}); | ||
|
||
const { data: currentResponse } = await got(currentUrl); | ||
|
||
const $ = cheerio.load(currentResponse); | ||
|
||
const icon = new URL($('link[rel="shortcut icon"]').prop('href'), currentUrl).href; | ||
|
||
ctx.state.data = { | ||
item: items, | ||
title: $('title').text(), | ||
link: currentUrl, | ||
description: $('span.rainbow-text').first().text(), | ||
language: $('html').prop('lang'), | ||
icon, | ||
logo: icon, | ||
subtitle: $('title').text(), | ||
author: $('meta[name="author"]').prop('content'), | ||
allowEmpty: true, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
'chuanliu.org': { | ||
_name: '川流', | ||
'.': [ | ||
{ | ||
title: '严选', | ||
docs: 'https://docs.rsshub.app/routes/blog#chuan-liu-yan-xuan', | ||
source: ['/nice'], | ||
target: '/chuanliu/nice', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = (router) => { | ||
router.get('/nice', require('./nice')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{{ if images }} | ||
{{ each images image }} | ||
{{ if image?.src }} | ||
<figure> | ||
<img | ||
{{ if image.alt }} | ||
alt="{{ image.alt }}" | ||
{{ /if }} | ||
{{ if image.width }} | ||
alt="{{ image.width }}" | ||
{{ /if }} | ||
{{ if image.height }} | ||
alt="{{ image.height }}" | ||
{{ /if }} | ||
src="{{ image.src }}"> | ||
</figure> | ||
{{ /if }} | ||
{{ /each }} | ||
{{ /if }} | ||
|
||
{{ if description }} | ||
{{@ description }} | ||
{{ /if }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters