Created
November 5, 2022 12:41
-
-
Save prnake/34406fb5d6b53a17c694b9101d157daf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const Parser = require('rss-parser'); | |
const translate = require('translation-google'); | |
module.exports = async (ctx) => { | |
const parser = new Parser(); | |
const baseUrl = 'https://export.arxiv.org/rss/cs'; | |
const feed = await parser.parseURL(baseUrl); | |
const tempItem = []; | |
feed.items.length = 100; | |
feed.items.forEach((item) => { | |
tempItem.push(item.title); | |
}); | |
await translate(tempItem.join("\n") | |
, { to:'zh-cn'}).then((res) => { | |
const itemTitles = res.text.split("\n"); | |
feed.items.forEach((item, index) => { | |
feed.items[index].title = itemTitles[index]; | |
}); | |
}).catch((err) => { | |
console.log(err); | |
}); | |
for(let i = 0 ; i < feed.items.length ; i++) { | |
await translate(feed.items[i].content.replaceAll('\n','').replaceAll('<p>','').replaceAll('</p>','') | |
, { to:'zh-cn'}).then((res) => { | |
feed.items[i].content = res.text; | |
}).catch((err) => { | |
console.log(err); | |
}); | |
} | |
ctx.state.data = { | |
title: feed.title, | |
link: baseUrl, | |
description: feed.description, | |
item: feed.items, | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment