From a9ef9dd427d87d339ea4ed41b9c2effca901dc27 Mon Sep 17 00:00:00 2001 From: Rjnishant Date: Tue, 8 Aug 2023 15:17:31 +0530 Subject: [PATCH 01/11] feat(route): add Stock Edge --- docs/en/finance.md | 5 +++++ lib/v2/stockedge/daily-news.js | 29 +++++++++++++++++++++++++++++ lib/v2/stockedge/maintainer.js | 3 +++ lib/v2/stockedge/radar.js | 13 +++++++++++++ lib/v2/stockedge/router.js | 3 +++ lib/v2/stockedge/utils.js | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 86 insertions(+) create mode 100644 lib/v2/stockedge/daily-news.js create mode 100644 lib/v2/stockedge/maintainer.js create mode 100644 lib/v2/stockedge/radar.js create mode 100644 lib/v2/stockedge/router.js create mode 100644 lib/v2/stockedge/utils.js diff --git a/docs/en/finance.md b/docs/en/finance.md index cf78e419699dd9..ad830c3e5ff5a0 100644 --- a/docs/en/finance.md +++ b/docs/en/finance.md @@ -125,6 +125,11 @@ Language +## Stock Edge + +### Daily Updates News + + ## TokenInsight ::: tip Tips diff --git a/lib/v2/stockedge/daily-news.js b/lib/v2/stockedge/daily-news.js new file mode 100644 index 00000000000000..89c05967904efd --- /dev/null +++ b/lib/v2/stockedge/daily-news.js @@ -0,0 +1,29 @@ +const { getData, getList } = require('./utils'); + +module.exports = async (ctx) => { + const baseUrl = 'https://web.stockedge.com/app/equities'; + const apiPath = 'https://api.stockedge.com/Api/DailyDashboardApi/GetLatestNewsItems'; + const apiInfo = 'https://api.stockedge.com/Api/SecurityDashboardApi/GetSecurityOverview'; + + const data = await getData(apiPath); + const list = getList(data); + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const info = await getData(`${apiInfo}/${item.securityID}`); + item.description = info?.AboutCompanyText; + return item; + }) + ) + ); + + ctx.state.data = { + title: 'Stock Edge', + link: baseUrl, + item: items, + description: 'Daily Updates on stockedge.com', + logo: 'https://web.stockedge.com/assets/icon/favicon.png', + icon: 'https://web.stockedge.com/assets/img/light/icon.png', + language: 'en-us', + }; +}; diff --git a/lib/v2/stockedge/maintainer.js b/lib/v2/stockedge/maintainer.js new file mode 100644 index 00000000000000..eb5a05fd2a0a7f --- /dev/null +++ b/lib/v2/stockedge/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/daily-updates/news': ['Rjnishant530'], +}; diff --git a/lib/v2/stockedge/radar.js b/lib/v2/stockedge/radar.js new file mode 100644 index 00000000000000..7549daf412d8b2 --- /dev/null +++ b/lib/v2/stockedge/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'stockedge.com': { + _name: 'Stock Edge', + '.': [ + { + title: 'Daily Updates News', + docs: 'https://docs.rsshub.app/en/finance.html#stock-edge', + source: ['/daily-updates/news'], + target: '/stockedge/daily-updates/news', + }, + ], + }, +}; diff --git a/lib/v2/stockedge/router.js b/lib/v2/stockedge/router.js new file mode 100644 index 00000000000000..d68b867c46e36f --- /dev/null +++ b/lib/v2/stockedge/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/daily-updates/news', require('./daily-news')); +}; diff --git a/lib/v2/stockedge/utils.js b/lib/v2/stockedge/utils.js new file mode 100644 index 00000000000000..c96273e7c3dd94 --- /dev/null +++ b/lib/v2/stockedge/utils.js @@ -0,0 +1,33 @@ +const timezone = require('@/utils/timezone'); +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); + +const baseUrl = 'https://web.stockedge.com/share/'; +const getData = (url) => + got + .get(url, { + headers: { + Host: 'api.stockedge.com', + Origin: 'https://web.stockedge.com', + Referer: 'https://web.stockedge.com/', + accept: 'application/json, text/plain, */*', + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:113.0) Gecko/20100101 Firefox/113.0', + }, + }) + .json(); + +const getList = (data) => + data.map((value) => { + const { ID, Description: title, Date, NewsitemSecurities, NewsitemSectors, NewsitemIndustries } = value; + const securityID = NewsitemSecurities[0].SecurityID; + return { + id: ID, + title: `${title} [${NewsitemSectors.map((v) => v.SectorName).join(', ')}]`, + securityID, + link: `${baseUrl}${NewsitemSecurities[0].SecuritySlug}/${securityID}`, + pubDate: timezone(parseDate(Date), 0), + category: [...NewsitemIndustries.map((v) => v.IndustryName), ...NewsitemSectors.map((v) => v.SectorName)], + }; + }); + +module.exports = { getData, getList }; From 608c7d627d6fb760ac7192bad4e997f334b4b2fd Mon Sep 17 00:00:00 2001 From: Rjnishant Date: Tue, 8 Aug 2023 15:28:31 +0530 Subject: [PATCH 02/11] fix(parseTime): utils --- lib/v2/stockedge/utils.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/v2/stockedge/utils.js b/lib/v2/stockedge/utils.js index c96273e7c3dd94..82d40e02204d36 100644 --- a/lib/v2/stockedge/utils.js +++ b/lib/v2/stockedge/utils.js @@ -1,4 +1,3 @@ -const timezone = require('@/utils/timezone'); const got = require('@/utils/got'); const { parseDate } = require('@/utils/parse-date'); @@ -25,7 +24,7 @@ const getList = (data) => title: `${title} [${NewsitemSectors.map((v) => v.SectorName).join(', ')}]`, securityID, link: `${baseUrl}${NewsitemSecurities[0].SecuritySlug}/${securityID}`, - pubDate: timezone(parseDate(Date), 0), + pubDate: parseDate(Date), category: [...NewsitemIndustries.map((v) => v.IndustryName), ...NewsitemSectors.map((v) => v.SectorName)], }; }); From 0ef37bbfcc7676732e09c2b89479d139a8026db3 Mon Sep 17 00:00:00 2001 From: Nishant Singh <57475999+Rjnishant530@users.noreply.github.com> Date: Wed, 9 Aug 2023 05:47:59 +0530 Subject: [PATCH 03/11] Update docs/en/finance.md Co-authored-by: Tony --- docs/en/finance.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/finance.md b/docs/en/finance.md index ad830c3e5ff5a0..1df9ce702d37e3 100644 --- a/docs/en/finance.md +++ b/docs/en/finance.md @@ -128,6 +128,7 @@ Language ## Stock Edge ### Daily Updates News + ## TokenInsight From 2bcbbcf2330fb40afb56365ef0123851d19da45d Mon Sep 17 00:00:00 2001 From: Rjnishant Date: Wed, 9 Aug 2023 06:00:06 +0530 Subject: [PATCH 04/11] fix(stockedge):minor changes --- lib/v2/stockedge/daily-news.js | 2 +- lib/v2/stockedge/utils.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/v2/stockedge/daily-news.js b/lib/v2/stockedge/daily-news.js index 89c05967904efd..2f204a4c3c6621 100644 --- a/lib/v2/stockedge/daily-news.js +++ b/lib/v2/stockedge/daily-news.js @@ -1,7 +1,7 @@ const { getData, getList } = require('./utils'); module.exports = async (ctx) => { - const baseUrl = 'https://web.stockedge.com/app/equities'; + const baseUrl = 'https://web.stockedge.com/daily-updates?section=news'; const apiPath = 'https://api.stockedge.com/Api/DailyDashboardApi/GetLatestNewsItems'; const apiInfo = 'https://api.stockedge.com/Api/SecurityDashboardApi/GetSecurityOverview'; diff --git a/lib/v2/stockedge/utils.js b/lib/v2/stockedge/utils.js index 82d40e02204d36..107777585501f4 100644 --- a/lib/v2/stockedge/utils.js +++ b/lib/v2/stockedge/utils.js @@ -10,21 +10,20 @@ const getData = (url) => Origin: 'https://web.stockedge.com', Referer: 'https://web.stockedge.com/', accept: 'application/json, text/plain, */*', - 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:113.0) Gecko/20100101 Firefox/113.0', }, }) .json(); const getList = (data) => data.map((value) => { - const { ID, Description: title, Date, NewsitemSecurities, NewsitemSectors, NewsitemIndustries } = value; + const { ID, Description: title, Date: createdOn, NewsitemSecurities, NewsitemSectors, NewsitemIndustries } = value; const securityID = NewsitemSecurities[0].SecurityID; return { id: ID, title: `${title} [${NewsitemSectors.map((v) => v.SectorName).join(', ')}]`, securityID, link: `${baseUrl}${NewsitemSecurities[0].SecuritySlug}/${securityID}`, - pubDate: parseDate(Date), + pubDate: parseDate(createdOn), category: [...NewsitemIndustries.map((v) => v.IndustryName), ...NewsitemSectors.map((v) => v.SectorName)], }; }); From a255a6ee73e44ca4377e86827fd0500988aa9bc3 Mon Sep 17 00:00:00 2001 From: Rjnishant Date: Wed, 9 Aug 2023 17:04:52 +0530 Subject: [PATCH 05/11] feat(route): add 'A list apart' --- lib/v2/alistapart/maintainer.js | 3 ++ lib/v2/alistapart/radar.js | 19 ++++++++++ lib/v2/alistapart/router.js | 3 ++ lib/v2/alistapart/topic.js | 67 +++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 lib/v2/alistapart/maintainer.js create mode 100644 lib/v2/alistapart/radar.js create mode 100644 lib/v2/alistapart/router.js create mode 100644 lib/v2/alistapart/topic.js diff --git a/lib/v2/alistapart/maintainer.js b/lib/v2/alistapart/maintainer.js new file mode 100644 index 00000000000000..5e586c2d5a8ab5 --- /dev/null +++ b/lib/v2/alistapart/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:topic?': ['Rjnishant530'], +}; diff --git a/lib/v2/alistapart/radar.js b/lib/v2/alistapart/radar.js new file mode 100644 index 00000000000000..911dadcd62bf30 --- /dev/null +++ b/lib/v2/alistapart/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'alistapart.com': { + _name: 'A List Apart', + '.': [ + { + title: 'Articles', + docs: 'https://docs.rsshub.app/en/programming.html#a-list-apart', + source: ['/articles/'], + target: '/alistapart', + }, + { + title: 'Topics', + docs: 'https://docs.rsshub.app/en/programming.html#a-list-apart', + source: ['/blog/topic/:topic'], + target: '/alistapart/:topic', + }, + ], + }, +}; diff --git a/lib/v2/alistapart/router.js b/lib/v2/alistapart/router.js new file mode 100644 index 00000000000000..aed9d7d1f0a45c --- /dev/null +++ b/lib/v2/alistapart/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:topic?', require('./topic')); +}; diff --git a/lib/v2/alistapart/topic.js b/lib/v2/alistapart/topic.js new file mode 100644 index 00000000000000..dc41b35f749337 --- /dev/null +++ b/lib/v2/alistapart/topic.js @@ -0,0 +1,67 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const { topic } = ctx.params; + const baseUrl = 'https://alistapart.com'; + let route; + if (topic) { + route = `/blog/topic/${topic}`; + } else { + route = '/articles'; + } + const { data: response } = await got(`${baseUrl}${route}`); + const $ = cheerio.load(response); + + const listItems = $('main.site-main article') + .toArray() + .map((item) => { + item = $(item); + const a = item.find('h2.entry-title a'); + const author = item + .find('span.author a span') + .toArray() + .map((item) => $(item).text()) + .join(', '); + const pubDate = item.find('span.posted-on time.entry-date').attr('datetime'); + const updated = item.find('span.posted-on time.updated').attr('datetime'); + return { + title: a.text(), + link: String(a.attr('href')), + pubDate, + author, + updated, + }; + }); + + const items = await Promise.all( + listItems.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + const $ = cheerio.load(response); + item.category = $('div.entry-topic span.cat-links a') + .toArray() + .map((item) => $(item).text()); + item.description = $('div.entry-content') + .clone() + .children('div') + .remove() + .end() + .map((index, element) => $(element).html()) + .get() + .join(''); + return item; + }) + ) + ); + + ctx.state.data = { + title: 'A List Apart', + link: `${baseUrl}${route}`, + item: items, + description: 'Articles on aListApart.com', + logo: 'https://i0.wp.com/alistapart.com/wp-content/uploads/2019/03/cropped-icon_navigation-laurel-512.jpg?fit=192,192&ssl=1', + icon: 'https://i0.wp.com/alistapart.com/wp-content/uploads/2019/03/cropped-icon_navigation-laurel-512.jpg?fit=32,32&ssl=1', + language: 'en-us', + }; +}; From 4a9057101f7f4b19041d4b96969b1913ba2be717 Mon Sep 17 00:00:00 2001 From: Rjnishant Date: Wed, 9 Aug 2023 17:07:24 +0530 Subject: [PATCH 06/11] docs --- docs/en/programming.md | 68 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/docs/en/programming.md b/docs/en/programming.md index 1d7c0e3a49a01c..005b63dda024ea 100644 --- a/docs/en/programming.md +++ b/docs/en/programming.md @@ -10,6 +10,74 @@ pageClass: routes +## A List Apart + +### Articles + + + +### Topics + + + +You have the option to utilize the main heading or use individual categories as topics for the path. + +Topics : + +| Code | +|-------------------------| +| Application Development | +| Browsers | +| CSS | +| HTML | +| JavaScript | +| The Server Side | + + +| Content | +|-----------------| +| Community | +| Content Strategy| +| Writing | + + +| Design | +|-------------------| +| Brand Identity | +| Graphic Design | +| Layout & Grids | +| Mobile/Multidevice| +| Responsive Design | +| Typography & Web Fonts| + + +| Industry & Business| +|---------------------| +| Business | +| Career | +| Industry | +| State of the Web | + + +| Process | +|-------------------| +| Creativity | +| Project Management| +| Web Strategy | +| Workflow & Tools | + + +| User Experience | +|------------------| +| Accessibility | +| Information Architecture| +| Interaction Design| +| Usability | +| User Research | + + + + ## AtCoder ### Present Contests From fc7454cc8b28ce2e82077e8f6235d6c4fe78d135 Mon Sep 17 00:00:00 2001 From: Rjnishant Date: Wed, 9 Aug 2023 17:51:56 +0530 Subject: [PATCH 07/11] parse time --- lib/v2/alistapart/topic.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/v2/alistapart/topic.js b/lib/v2/alistapart/topic.js index dc41b35f749337..e0ca4ed963719d 100644 --- a/lib/v2/alistapart/topic.js +++ b/lib/v2/alistapart/topic.js @@ -1,5 +1,6 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const { topic } = ctx.params; @@ -23,8 +24,8 @@ module.exports = async (ctx) => { .toArray() .map((item) => $(item).text()) .join(', '); - const pubDate = item.find('span.posted-on time.entry-date').attr('datetime'); - const updated = item.find('span.posted-on time.updated').attr('datetime'); + const pubDate = parseDate(item.find('span.posted-on time.entry-date').attr('datetime')); + const updated = parseDate(item.find('span.posted-on time.updated').attr('datetime')); return { title: a.text(), link: String(a.attr('href')), From 9856fc7f360104286a79d6ed9094ccf7c1ff489d Mon Sep 17 00:00:00 2001 From: Rjnishant Date: Thu, 10 Aug 2023 18:50:50 +0530 Subject: [PATCH 08/11] use wordpress api --- docs/en/programming.md | 98 ++++++++++++++++----------------- lib/v2/alistapart/index.js | 30 ++++++++++ lib/v2/alistapart/maintainer.js | 1 + lib/v2/alistapart/router.js | 3 +- lib/v2/alistapart/topic.js | 62 +++++---------------- lib/v2/alistapart/utils.js | 20 +++++++ 6 files changed, 112 insertions(+), 102 deletions(-) create mode 100644 lib/v2/alistapart/index.js create mode 100644 lib/v2/alistapart/utils.js diff --git a/docs/en/programming.md b/docs/en/programming.md index 005b63dda024ea..3b5aa00d46b501 100644 --- a/docs/en/programming.md +++ b/docs/en/programming.md @@ -18,63 +18,57 @@ pageClass: routes ### Topics - + You have the option to utilize the main heading or use individual categories as topics for the path. Topics : -| Code | -|-------------------------| -| Application Development | -| Browsers | -| CSS | -| HTML | -| JavaScript | -| The Server Side | - - -| Content | -|-----------------| -| Community | -| Content Strategy| -| Writing | - - -| Design | -|-------------------| -| Brand Identity | -| Graphic Design | -| Layout & Grids | -| Mobile/Multidevice| -| Responsive Design | -| Typography & Web Fonts| - - -| Industry & Business| -|---------------------| -| Business | -| Career | -| Industry | -| State of the Web | - - -| Process | -|-------------------| -| Creativity | -| Project Management| -| Web Strategy | -| Workflow & Tools | - - -| User Experience | -|------------------| -| Accessibility | -| Information Architecture| -| Interaction Design| -| Usability | -| User Research | - +| **Code** | _code_ | +|-------------------------|-------------------------| +| **Application Development** | _application-development_ | +| **Browsers** | _browsers_ | +| **CSS** | _css_ | +| **HTML** | _html_ | +| **JavaScript** | _javascript_ | +| **The Server Side** | _the-server-side_ | + +| **Content** | _content_ | +|-------------------------|-------------------------| +| **Community** | _community_ | +| **Content Strategy** | _content-strategy_ | +| **Writing** | _writing_ | + +| **Design** | _design_ | +|-------------------------|-------------------------| +| **Brand Identity** | _brand-identity_ | +| **Graphic Design** | _graphic-design_ | +| **Layout & Grids** | _layout-grids_ | +| **Mobile/Multidevice** | _mobile-multidevice_ | +| **Responsive Design** | _responsive-design_ | +| **Typography & Web Fonts** | _typography-web-fonts_ | + +| **Industry & Business** | _industry-business_ | +|-------------------------|-------------------------| +| **Business** | _business_ | +| **Career** | _career_ | +| **Industry** | _industry_ | +| **State of the Web** | _state-of-the-web_ | + +| **Process** | _process_ | +|-------------------------|-------------------------| +| **Creativity** | _creativity_ | +| **Project Management** | _project-management_ | +| **Web Strategy** | _web-strategy_ | +| **Workflow & Tools** | _workflow-tools_ | + +| **User Experience** | _user-experience_ | +|-------------------------|-------------------------| +| **Accessibility** | _accessibility_ | +| **Information Architecture** | _information-architecture_ | +| **Interaction Design** | _interaction-design_ | +| **Usability** | _usability_ | +| **User Research** | _user-research_ | diff --git a/lib/v2/alistapart/index.js b/lib/v2/alistapart/index.js new file mode 100644 index 00000000000000..d1c66bfd62571d --- /dev/null +++ b/lib/v2/alistapart/index.js @@ -0,0 +1,30 @@ +const { getData, getList } = require('./utils'); + +module.exports = async (ctx) => { + const baseUrl = 'https://alistapart.com'; + const route = '/wp-json/wp/v2/article'; + + const data = await getData(`${baseUrl}${route}`); + const listItems = await getList(data); + const items = await Promise.all( + listItems.map((item) => + ctx.cache.tryGet(item.link, async () => { + const category = await getData(`https://alistapart.com/wp-json/wp/v2/categories?post=${item.id}`); + item.category = category.map((v) => v.name); + const author = await getData(`https://alistapart.com/wp-json/wp/v2/coauthors?post=${item.id}`); + item.author = author.map((v) => v.name).join(', '); + return item; + }) + ) + ); + + ctx.state.data = { + title: 'A List Apart', + link: `${baseUrl}/articles`, + item: items, + description: 'Articles on aListApart.com', + logo: 'https://i0.wp.com/alistapart.com/wp-content/uploads/2019/03/cropped-icon_navigation-laurel-512.jpg?fit=192,192&ssl=1', + icon: 'https://i0.wp.com/alistapart.com/wp-content/uploads/2019/03/cropped-icon_navigation-laurel-512.jpg?fit=32,32&ssl=1', + language: 'en-us', + }; +}; diff --git a/lib/v2/alistapart/maintainer.js b/lib/v2/alistapart/maintainer.js index 5e586c2d5a8ab5..cb0c09ffbda0a9 100644 --- a/lib/v2/alistapart/maintainer.js +++ b/lib/v2/alistapart/maintainer.js @@ -1,3 +1,4 @@ module.exports = { + '/': ['Rjnishant530'], '/:topic?': ['Rjnishant530'], }; diff --git a/lib/v2/alistapart/router.js b/lib/v2/alistapart/router.js index aed9d7d1f0a45c..c995b150d280a6 100644 --- a/lib/v2/alistapart/router.js +++ b/lib/v2/alistapart/router.js @@ -1,3 +1,4 @@ module.exports = (router) => { - router.get('/:topic?', require('./topic')); + router.get('/', require('./index')); + router.get('/:topic', require('./topic')); }; diff --git a/lib/v2/alistapart/topic.js b/lib/v2/alistapart/topic.js index e0ca4ed963719d..fab7cb8d0a1f89 100644 --- a/lib/v2/alistapart/topic.js +++ b/lib/v2/alistapart/topic.js @@ -1,56 +1,20 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +const { getData, getList } = require('./utils'); module.exports = async (ctx) => { - const { topic } = ctx.params; const baseUrl = 'https://alistapart.com'; - let route; - if (topic) { - route = `/blog/topic/${topic}`; - } else { - route = '/articles'; - } - const { data: response } = await got(`${baseUrl}${route}`); - const $ = cheerio.load(response); - - const listItems = $('main.site-main article') - .toArray() - .map((item) => { - item = $(item); - const a = item.find('h2.entry-title a'); - const author = item - .find('span.author a span') - .toArray() - .map((item) => $(item).text()) - .join(', '); - const pubDate = parseDate(item.find('span.posted-on time.entry-date').attr('datetime')); - const updated = parseDate(item.find('span.posted-on time.updated').attr('datetime')); - return { - title: a.text(), - link: String(a.attr('href')), - pubDate, - author, - updated, - }; - }); - + const searchRoute = '/wp-json/wp/v2/categories?search='; + const articleRoute = '/wp-json/wp/v2/article?categories='; + const { topic } = ctx.params; + const id = (await getData(`${baseUrl}${searchRoute}${topic}`))[0].id; + const data = await getData(`${baseUrl}${articleRoute}${id}`); + const listItems = await getList(data); const items = await Promise.all( listItems.map((item) => ctx.cache.tryGet(item.link, async () => { - const { data: response } = await got(item.link); - const $ = cheerio.load(response); - item.category = $('div.entry-topic span.cat-links a') - .toArray() - .map((item) => $(item).text()); - item.description = $('div.entry-content') - .clone() - .children('div') - .remove() - .end() - .map((index, element) => $(element).html()) - .get() - .join(''); + const category = await getData(`https://alistapart.com/wp-json/wp/v2/categories?post=${item.id}`); + item.category = category.map((v) => v.name); + const author = await getData(`https://alistapart.com/wp-json/wp/v2/coauthors?post=${item.id}`); + item.author = author.map((v) => v.name).join(', '); return item; }) ) @@ -58,9 +22,9 @@ module.exports = async (ctx) => { ctx.state.data = { title: 'A List Apart', - link: `${baseUrl}${route}`, + link: `${baseUrl}/blog/topic/${topic}`, item: items, - description: 'Articles on aListApart.com', + description: `${topic[0].toUpperCase() + topic.slice(1)} Articles on aListApart.com`, logo: 'https://i0.wp.com/alistapart.com/wp-content/uploads/2019/03/cropped-icon_navigation-laurel-512.jpg?fit=192,192&ssl=1', icon: 'https://i0.wp.com/alistapart.com/wp-content/uploads/2019/03/cropped-icon_navigation-laurel-512.jpg?fit=32,32&ssl=1', language: 'en-us', diff --git a/lib/v2/alistapart/utils.js b/lib/v2/alistapart/utils.js new file mode 100644 index 00000000000000..8308e539b397fb --- /dev/null +++ b/lib/v2/alistapart/utils.js @@ -0,0 +1,20 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const getData = (url) => got.get(url).json(); + +const getList = (data) => + data.map((value) => { + const { id, title, content, date_gmt, modified_gmt, link } = value; + return { + id, + title: title.rendered, + description: content.rendered, + link, + pubDate: timezone(parseDate(date_gmt), 0), + updated: timezone(parseDate(modified_gmt), 0), + }; + }); + +module.exports = { getData, getList }; From 15491ad1b9d57d6b4d433a17cb3110071bbcaf21 Mon Sep 17 00:00:00 2001 From: Rjnishant Date: Thu, 10 Aug 2023 22:15:56 +0530 Subject: [PATCH 09/11] add _embedded --- lib/v2/alistapart/index.js | 15 ++------------- lib/v2/alistapart/topic.js | 17 +++-------------- lib/v2/alistapart/utils.js | 4 +++- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/lib/v2/alistapart/index.js b/lib/v2/alistapart/index.js index d1c66bfd62571d..8be8b9eeade989 100644 --- a/lib/v2/alistapart/index.js +++ b/lib/v2/alistapart/index.js @@ -2,21 +2,10 @@ const { getData, getList } = require('./utils'); module.exports = async (ctx) => { const baseUrl = 'https://alistapart.com'; - const route = '/wp-json/wp/v2/article'; + const route = '/wp-json/wp/v2/article?_embed'; const data = await getData(`${baseUrl}${route}`); - const listItems = await getList(data); - const items = await Promise.all( - listItems.map((item) => - ctx.cache.tryGet(item.link, async () => { - const category = await getData(`https://alistapart.com/wp-json/wp/v2/categories?post=${item.id}`); - item.category = category.map((v) => v.name); - const author = await getData(`https://alistapart.com/wp-json/wp/v2/coauthors?post=${item.id}`); - item.author = author.map((v) => v.name).join(', '); - return item; - }) - ) - ); + const items = await getList(data); ctx.state.data = { title: 'A List Apart', diff --git a/lib/v2/alistapart/topic.js b/lib/v2/alistapart/topic.js index fab7cb8d0a1f89..22e09dd3b8e247 100644 --- a/lib/v2/alistapart/topic.js +++ b/lib/v2/alistapart/topic.js @@ -2,23 +2,12 @@ const { getData, getList } = require('./utils'); module.exports = async (ctx) => { const baseUrl = 'https://alistapart.com'; - const searchRoute = '/wp-json/wp/v2/categories?search='; + const searchRoute = '/wp-json/wp/v2/categories?slug='; const articleRoute = '/wp-json/wp/v2/article?categories='; const { topic } = ctx.params; const id = (await getData(`${baseUrl}${searchRoute}${topic}`))[0].id; - const data = await getData(`${baseUrl}${articleRoute}${id}`); - const listItems = await getList(data); - const items = await Promise.all( - listItems.map((item) => - ctx.cache.tryGet(item.link, async () => { - const category = await getData(`https://alistapart.com/wp-json/wp/v2/categories?post=${item.id}`); - item.category = category.map((v) => v.name); - const author = await getData(`https://alistapart.com/wp-json/wp/v2/coauthors?post=${item.id}`); - item.author = author.map((v) => v.name).join(', '); - return item; - }) - ) - ); + const data = await getData(`${baseUrl}${articleRoute}${id}&_embed`); + const items = await getList(data); ctx.state.data = { title: 'A List Apart', diff --git a/lib/v2/alistapart/utils.js b/lib/v2/alistapart/utils.js index 8308e539b397fb..5f68f3d687b82b 100644 --- a/lib/v2/alistapart/utils.js +++ b/lib/v2/alistapart/utils.js @@ -6,12 +6,14 @@ const getData = (url) => got.get(url).json(); const getList = (data) => data.map((value) => { - const { id, title, content, date_gmt, modified_gmt, link } = value; + const { id, title, content, date_gmt, modified_gmt, link, _embedded } = value; return { id, title: title.rendered, description: content.rendered, link, + category: _embedded['wp:term'][0].map((v) => v.name), + author: _embedded.author.map((v) => v.name).join(', '), pubDate: timezone(parseDate(date_gmt), 0), updated: timezone(parseDate(modified_gmt), 0), }; From c50438ad1ada3e918b5d41cff0d1a382c6aeb524 Mon Sep 17 00:00:00 2001 From: Rjnishant Date: Thu, 10 Aug 2023 22:18:31 +0530 Subject: [PATCH 10/11] fix --- lib/v2/alistapart/topic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/v2/alistapart/topic.js b/lib/v2/alistapart/topic.js index 22e09dd3b8e247..d9db2097ce62b6 100644 --- a/lib/v2/alistapart/topic.js +++ b/lib/v2/alistapart/topic.js @@ -5,7 +5,7 @@ module.exports = async (ctx) => { const searchRoute = '/wp-json/wp/v2/categories?slug='; const articleRoute = '/wp-json/wp/v2/article?categories='; const { topic } = ctx.params; - const id = (await getData(`${baseUrl}${searchRoute}${topic}`))[0].id; + const id = (await getData(`${baseUrl}${searchRoute}${topic}`))[0]?.id; const data = await getData(`${baseUrl}${articleRoute}${id}&_embed`); const items = await getList(data); From e85694af2aed1377c3f1ba52277852d88579724d Mon Sep 17 00:00:00 2001 From: TonyRL Date: Thu, 10 Aug 2023 17:49:10 +0000 Subject: [PATCH 11/11] docs: spoiler --- docs/en/programming.md | 16 +++++++++------- lib/v2/alistapart/maintainer.js | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/en/programming.md b/docs/en/programming.md index 3b5aa00d46b501..61802ea98e896b 100644 --- a/docs/en/programming.md +++ b/docs/en/programming.md @@ -4,12 +4,6 @@ pageClass: routes # Programming -## ACM - -### A.M.Turing Award Winners - - - ## A List Apart ### Articles @@ -22,7 +16,7 @@ pageClass: routes You have the option to utilize the main heading or use individual categories as topics for the path. -Topics : +::: details Topics | **Code** | _code_ | |-------------------------|-------------------------| @@ -70,8 +64,16 @@ Topics : | **Usability** | _usability_ | | **User Research** | _user-research_ | +::: + +## ACM + +### A.M.Turing Award Winners + + + ## AtCoder ### Present Contests diff --git a/lib/v2/alistapart/maintainer.js b/lib/v2/alistapart/maintainer.js index cb0c09ffbda0a9..508e3485a5a094 100644 --- a/lib/v2/alistapart/maintainer.js +++ b/lib/v2/alistapart/maintainer.js @@ -1,4 +1,4 @@ module.exports = { '/': ['Rjnishant530'], - '/:topic?': ['Rjnishant530'], + '/:topic': ['Rjnishant530'], };