From 5adb4a4d8cde56548a433489ff6a10fa4670b621 Mon Sep 17 00:00:00 2001 From: Guorui Yu Date: Wed, 15 Nov 2023 23:58:54 +0800 Subject: [PATCH] feat(route): cmpxchg8b (#13802) * feat(route): cmpxchg8b Signed-off-by: yuguorui * Update website/docs/routes/programming.mdx * docs: move to blog --------- Signed-off-by: yuguorui --- lib/v2/cmpxchg8b/articles.js | 43 +++++++++++++++++++++++++++++ lib/v2/cmpxchg8b/maintainer.js | 3 ++ lib/v2/cmpxchg8b/radar.js | 13 +++++++++ lib/v2/cmpxchg8b/router.js | 3 ++ website/docs/routes/blog.mdx | 6 ++++ website/docs/routes/programming.mdx | 1 - 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 lib/v2/cmpxchg8b/articles.js create mode 100644 lib/v2/cmpxchg8b/maintainer.js create mode 100644 lib/v2/cmpxchg8b/radar.js create mode 100644 lib/v2/cmpxchg8b/router.js diff --git a/lib/v2/cmpxchg8b/articles.js b/lib/v2/cmpxchg8b/articles.js new file mode 100644 index 00000000000000..20b7c72c73fec4 --- /dev/null +++ b/lib/v2/cmpxchg8b/articles.js @@ -0,0 +1,43 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const baseUrl = 'https://lock.cmpxchg8b.com/'; +const title = 'cmpxchg8b'; + +module.exports = async (ctx) => { + const { data: response } = await got(baseUrl); + + const $ = cheerio.load(response); + const author = $('p.author').text().trim(); + const list = $('section#articles section') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.find('li').text(), + link: new URL(item.find('li a').attr('href'), baseUrl).toString(), + author, + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + const $ = cheerio.load(response); + + // extract the body but removing