feat(route): add Font Story (DynaC TW) (#7565)
This commit is contained in:
@@ -201,3 +201,7 @@ pageClass: routes
|
||||
### 文章
|
||||
|
||||
<Route author="junbaor SkiTiSu" example="/blogs/wangyin" path="/blogs/wangyin"/>
|
||||
|
||||
## 華康字型故事
|
||||
|
||||
<Route author="tpnonthealps" example="/fontstory" path="/fontstory" />
|
||||
|
||||
@@ -4140,6 +4140,9 @@ router.get('/tongli/news/:type', lazyloadRouteHandler('./routes/tongli/news'));
|
||||
// OR
|
||||
router.get('/or/:id?', lazyloadRouteHandler('./routes/or'));
|
||||
|
||||
// 字型故事
|
||||
router.get('/fontstory', require('./routes/fontstory/tw'));
|
||||
|
||||
// HKEPC
|
||||
router.get('/hkepc/:category?', lazyloadRouteHandler('./routes/hkepc/index'));
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
function getArticle(ctx, list) {
|
||||
const now = list.map((line) =>
|
||||
ctx.cache.tryGet(line, async () => {
|
||||
const a_r = await got.get(`https://www.dynacw.com.tw/fontstory/${line}`);
|
||||
const $ = cheerio.load(a_r.data);
|
||||
const t_r = $('h2.col-xs-12.tc-deeppink').first().text();
|
||||
const tag = $('div.date-txt.col-xs-8.tc-gray').first().text();
|
||||
$('main.container').find('ol.breadcrumb.hidden-xs').remove();
|
||||
$('main.container').find('section.row').first().remove();
|
||||
$('main.container').find('section.pages.row').remove();
|
||||
const desc = $('main.container').html();
|
||||
|
||||
return {
|
||||
title: `${t_r}(${tag})`,
|
||||
description: desc,
|
||||
pubDate: timezone(parseDate($('div.date-txt.col-xs-4.tc-gray.text-right').text(), 'YYYY年MM月DD日'), +8),
|
||||
link: `https://www.dynacw.com.tw/fontstory/${line}`,
|
||||
};
|
||||
})
|
||||
);
|
||||
return Promise.all(now);
|
||||
}
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: 'https://www.dynacw.com.tw/fontstory/fontstory.aspx',
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const dom = $('div.font-item.col-xs-12');
|
||||
const relink = dom.map((_index, li) => $(li).find('a').first().attr('href'));
|
||||
const list = relink.toArray();
|
||||
|
||||
const rss = await getArticle(ctx, list.slice(0, 10));
|
||||
ctx.state.data = {
|
||||
title: '字型故事|華康字型',
|
||||
link: 'https://www.dynacw.com.tw/fontstory/fontstory.aspx',
|
||||
item: rss,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user