From fe9c82a96766297fe6d224d670373823315695c9 Mon Sep 17 00:00:00 2001
From: Hengyu <76626546+5upernova-heng@users.noreply.github.com>
Date: Sat, 4 Mar 2023 02:37:22 +0800
Subject: [PATCH] feat(route): add nber route: NBER working paper (#12008)
* feat(route): add NBER working papers
* Modify the documentation
* Fix 'url is not defined' bug
* Remove async of get_element function
* Remove meaningless comments
* Update docs/en/journal.md
* Update docs/en/journal.md
* Change data acquisition methods to call api
* Remove wrong param 'ctx'
* Change documentation and radar
* Combine to file together & Cache each item & Add doi & Add pdf download link in description & Styling the description
* Add await in async function
* Clean the code
* Add config.cache.expire
* fix: typo
* Change 'abstract' acquisition method to parsing html from calling api
* Update lib/v2/nber/radar.js
* docs: fix typos
---------
---
docs/en/journal.md | 14 ++++++++
docs/journal.md | 14 ++++++++
lib/v2/nber/index.js | 48 ++++++++++++++++++++++++++++
lib/v2/nber/maintainer.js | 4 +++
lib/v2/nber/radar.js | 19 +++++++++++
lib/v2/nber/router.js | 4 +++
lib/v2/nber/template/description.art | 6 ++++
7 files changed, 109 insertions(+)
create mode 100644 lib/v2/nber/index.js
create mode 100644 lib/v2/nber/maintainer.js
create mode 100644 lib/v2/nber/radar.js
create mode 100644 lib/v2/nber/router.js
create mode 100644 lib/v2/nber/template/description.art
diff --git a/docs/en/journal.md b/docs/en/journal.md
index 0b0cd8b0cb9e90..ef1fa82a584654 100644
--- a/docs/en/journal.md
+++ b/docs/en/journal.md
@@ -234,6 +234,20 @@ Return results from 2020
| smart-cities | /technologyreview/smart-cities|
| space | /technologyreview/space |
+## National Bureau of Economic Research
+
+### All Papers
+
+
+
+### New Papers
+
+
+
+Papers that are published in this week.
+
+
+
## Nature Journal
::: tip Tips
diff --git a/docs/journal.md b/docs/journal.md
index 44eee8800eb5b8..a254d7fbd8c4f3 100644
--- a/docs/journal.md
+++ b/docs/journal.md
@@ -206,6 +206,20 @@ pageClass: routes
+## National Bureau of Economic Research
+
+### 全部论文
+
+
+
+### 新论文
+
+
+
+在网站上被标记为 "new" 的论文
+
+
+
## Nature 系列
::: tip Tips
diff --git a/lib/v2/nber/index.js b/lib/v2/nber/index.js
new file mode 100644
index 00000000000000..5a7ebda392ce4f
--- /dev/null
+++ b/lib/v2/nber/index.js
@@ -0,0 +1,48 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const path = require('path');
+const { art } = require('@/utils/render');
+const { parseDate } = require('@/utils/parse-date');
+
+async function getData(url) {
+ const response = await got(url).json();
+ return response.results;
+}
+
+module.exports = async (ctx) => {
+ const url = 'https://www.nber.org/api/v1/working_page_listing/contentType/working_paper/_/_/search';
+ const baseUrl = 'https://www.nber.org';
+ const config = require('@/config').value;
+ const data = await ctx.cache.tryGet(url, () => getData(url), config.cache.routeExpire, false);
+ const items = await Promise.all(
+ data
+ .filter((article) => ctx.path === '/papers' || article.newthisweek)
+ .map((article) => {
+ const link = `${baseUrl}${article.url}`;
+ return ctx.cache.tryGet(link, async () => {
+ const response = await got(link);
+ const $ = cheerio.load(response.data);
+ const downloadLink = $('meta[name="citation_pdf_url"]').attr('content');
+ const fullAbstract = $('.page-header__intro-inner').html();
+ return {
+ title: article.title,
+ author: $('meta[name="dcterms.creator"]').attr('content'),
+ pubDate: parseDate($('meta[name="citation_publication_date"]').attr('content'), 'YYYY/MM/DD'),
+ link,
+ doi: $('meta[name="citation_doi"]').attr('content'),
+ description: art(path.join(__dirname, 'template/description.art'), {
+ fullAbstract,
+ downloadLink,
+ }),
+ };
+ });
+ })
+ );
+
+ ctx.state.data = {
+ title: 'NBER Working Paper',
+ link: 'https://www.nber.org/papers',
+ item: items,
+ description: `National Bureau of Economic Research Working Papers articles`,
+ };
+};
diff --git a/lib/v2/nber/maintainer.js b/lib/v2/nber/maintainer.js
new file mode 100644
index 00000000000000..3d9a574641c17f
--- /dev/null
+++ b/lib/v2/nber/maintainer.js
@@ -0,0 +1,4 @@
+module.exports = {
+ '/articles': ['5upernova-heng'],
+ '/news': ['5upernova-heng'],
+};
diff --git a/lib/v2/nber/radar.js b/lib/v2/nber/radar.js
new file mode 100644
index 00000000000000..3aab15ed675eea
--- /dev/null
+++ b/lib/v2/nber/radar.js
@@ -0,0 +1,19 @@
+module.exports = {
+ 'nber.org': {
+ _name: 'National Bureau of Economic Research',
+ '.': [
+ {
+ title: 'New working paper',
+ docs: 'https://docs.rsshub.app/en/journal.html#national-bureau-of-economic-research',
+ source: ['/papers'],
+ target: '/nber/news',
+ },
+ {
+ title: 'All working paper',
+ docs: 'https://docs.rsshub.app/en/journal.html#national-bureau-of-economic-research',
+ source: ['/papers'],
+ target: '/nber/papers',
+ },
+ ],
+ },
+};
diff --git a/lib/v2/nber/router.js b/lib/v2/nber/router.js
new file mode 100644
index 00000000000000..e4dc695191999d
--- /dev/null
+++ b/lib/v2/nber/router.js
@@ -0,0 +1,4 @@
+module.exports = (router) => {
+ router.get('/papers', require('.'));
+ router.get('/news', require('.'));
+};
diff --git a/lib/v2/nber/template/description.art b/lib/v2/nber/template/description.art
new file mode 100644
index 00000000000000..c013cb155e4b5d
--- /dev/null
+++ b/lib/v2/nber/template/description.art
@@ -0,0 +1,6 @@
+{{ if fullAbstract }}
+{{@ fullAbstract }}
+{{ /if}}
+{{ if downloadLink }}
+Download PDF
+{{ /if }}
\ No newline at end of file