-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: agirls routes * refactor: combine duplicated code ---------
- Loading branch information
1 parent
cc7ea6a
commit d513d6b
Showing
5 changed files
with
81 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
const baseUrl = 'https://agirls.aotter.net'; | ||
|
||
const parseArticle = async (item, referer, cookieJar) => { | ||
const detailResponse = await got({ | ||
url: item.link, | ||
headers: { | ||
Referer: referer, | ||
}, | ||
cookieJar, | ||
}); | ||
const content = cheerio.load(detailResponse.data); | ||
|
||
item.category = [ | ||
...new Set( | ||
content('.ag-article__tag') | ||
.toArray() | ||
.map((e) => content(e).text().trim().replace('#', '')) | ||
), | ||
]; | ||
const ldJson = JSON.parse(content('script[type="application/ld+json"]').text()); | ||
|
||
item.description = content('.ag-article__content').html(); | ||
item.pubDate = parseDate(ldJson['@graph'][0].datePublished); // 2023-07-05T12:11:36+08:00 | ||
item.updated = parseDate(ldJson['@graph'][0].dateModified); // 2023-07-05T12:11:36+08:00 | ||
item.author = ldJson['@graph'][0].author.map((a) => a.name).join(', '); | ||
|
||
return item; | ||
}; | ||
|
||
module.exports = { | ||
baseUrl, | ||
parseArticle, | ||
}; |