feat(route): add 竹百TOP20 (#12639)
* feat(route): add 竹百TOP20 * fix matches
This commit is contained in:
@@ -520,3 +520,7 @@ Tag 有很多,可从首页点进 Tag 以后的 URL 获取,例如 `https://me
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
### TOP 20
|
||||
|
||||
<Route author="nczitzk" example="/zhubai/top20" path="/zhubai/top20"/>
|
||||
@@ -1,3 +1,4 @@
|
||||
module.exports = {
|
||||
'/top20': ['nczitzk'],
|
||||
'/:id': ['naixy28'],
|
||||
};
|
||||
|
||||
@@ -8,5 +8,12 @@ module.exports = {
|
||||
source: ['/'],
|
||||
},
|
||||
],
|
||||
analy: [
|
||||
{
|
||||
title: 'TOP 20',
|
||||
docs: 'https://docs.rsshub.app/blog.html#zhu-bai',
|
||||
source: ['/'],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/top20', require('./top20'));
|
||||
router.get('/:id', require('./index'));
|
||||
};
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
{{ each content c }}
|
||||
{{ if c.text }}
|
||||
{{ c.text }}
|
||||
{{ else if c.type === 'paragraph' }}
|
||||
<p>{{@ c.children | parseContent }}</p>
|
||||
{{ else if c.type === 'link' }}
|
||||
<a href="{{ c.url }}">{{@ c.children | parseContent }}</a>
|
||||
{{ else if c.type === 'image' }}
|
||||
<img src="{{ c.url }}" height="{{ c.naturalHeight }}" width="{{ c.naturalWidth }}">
|
||||
{{ else if c.type === 'list-item' }}
|
||||
<li>{{@ c.children | parseContent }}</li>
|
||||
{{ else if c.type === 'bulleted-list' }}
|
||||
<ul>{{@ c.children | parseContent }}</ul>
|
||||
{{ else if c.type === 'numbered-list' }}
|
||||
<ol>{{@ c.children | parseContent }}</ol>
|
||||
{{ else if c.type === 'block-quote' }}
|
||||
<blockquote>{{@ c.children | parseContent }}</blockquote>
|
||||
{{ else if c.type === 'heading-one' }}
|
||||
<h1>{{@ c.children | parseContent }}</h1>
|
||||
{{ else if c.type === 'heading-two' }}
|
||||
<h2>{{@ c.children | parseContent }}</h2>
|
||||
{{ else if c.type === 'heading-three' }}
|
||||
<h3>{{@ c.children | parseContent }}</h3>
|
||||
{{ else if c.type === 'heading-four' }}
|
||||
<h4>{{@ c.children | parseContent }}</h4>
|
||||
{{ else if c.type === 'heading-five' }}
|
||||
<h5>{{@ c.children | parseContent }}</h5>
|
||||
{{ else if c.type === 'heading-six' }}
|
||||
<h6>{{@ c.children | parseContent }}</h6>
|
||||
{{ /if }}
|
||||
{{ /each }}
|
||||
@@ -0,0 +1,57 @@
|
||||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
const parseContent = (content) =>
|
||||
art(path.join(__dirname, 'templates/description.art'), {
|
||||
content,
|
||||
});
|
||||
|
||||
art.defaults.imports.parseContent = parseContent;
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 20;
|
||||
|
||||
const rootUrl = 'https://analy.zhubai.wiki';
|
||||
const apiRootUrl = 'https://open.zhubai.wiki';
|
||||
const apiUrl = `${apiRootUrl}/a/zb/s/ht/pl/wk`;
|
||||
|
||||
const response = await got({
|
||||
method: 'post',
|
||||
url: apiUrl,
|
||||
});
|
||||
|
||||
let items = response.data.data.slice(0, limit).map((item) => ({
|
||||
link: item.fp ?? item.pq ?? item.pu,
|
||||
}));
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const matches = item.link.match(/\/(fp|pq|pu)\/([\w-]+)\/(\d+)/);
|
||||
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: `https://${matches[2]}.zhubai.love/api/posts/${matches[3]}`,
|
||||
});
|
||||
|
||||
const data = detailResponse.data;
|
||||
|
||||
item.title = data.title;
|
||||
item.author = data.author.name;
|
||||
item.pubDate = parseDate(data.created_at);
|
||||
item.description = parseContent(JSON.parse(data.content));
|
||||
item.link = `https://${matches[2]}.zhubai.love/posts/${matches[3]}`;
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '竹白 - TOP20',
|
||||
link: rootUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user