问题描述
我已经研究了几天,遗憾的是我无法找到正确的搜索字词或我缺乏技能的正确答案。
我正在将 ListServ 转换为 Discourse。我正在将 RSS 提要转换为 JSON。 源数据示例:
{
"title": "tech: 18F presentation","id": 2,"body": "Sadly,my biggest concern is whether it will run on Linux or Windows. And I guess if they’ll thrown even more java at it.","date": "Fri,28 May 2021 20:50:04 +0000","author": "john_doe"
},{
"title": "Re: tech: 18F presentation","id": 3,"body": "throw more java,indeed. What a moon shot.","author": "john_doe2"
},"id": 4,"body": "Please stop saying moonshot,its not dodgecoin","author": "jane_doe"
},
我的数据结构需要如下所示:
{
"topics": [
{
"id": 1,"title": "tech: 18F presentation","pinned": false,"posts": [
{
"title": "Re: tech: 18F presentation","author": "john_doe2"
},{
"title": "Re: tech: 18F presentation",]
}
]
}
我需要将每个带有“Re:”的标题插入到原始标题中。示例)任何回复,“Re tech:18F 演示文稿”需要插入帖子:[] 的标题:“tech:18F 演示文稿”(没有 Re:)。
我尝试将回复分成自己的 json 并将其推送到 post 数组中,但我不知道如何匹配适当的标题。
let data = [];
const original_post = [];
const reply_to_post = [];
const discourse_JSON = [];
$("item").map(function (i,article) {
const title = $(article).find("title")[0].children[0].data;
const description = $(article).find("description")[0].children[0].data;
const user_email = $(article).find("author")[0].children[0].data.match("<([^>]+)>")[1];
const link = $(article).find("link")[0].children[0].data;
const guid = $(article).find("guid")[0].children[0].data;
const date = $(article).find("pubDate")[0].children[0].data;
const name = user_email.substring(0,user_email.indexOf('@')).split("_")[0] + ' ' + user_email.substring(0,user_email.indexOf('@')).split("_")[1];
const username = user_email.substring(0,user_email.indexOf('@'))
if (
!title.toLowerCase().includes("vacancy") &&
!title.toLowerCase().includes("opportunity") &&
!title.toLowerCase().includes("retirement") &&
!title.toLowerCase().includes("position") &&
!title.toLowerCase().includes("job posting") &&
!description.toLowerCase().includes("vacancy announcement") &&
!description.toLowerCase().includes("vacancy posting") &&
!description.toLowerCase().includes("vacancies")
) {
data.push({
"title": title,"id": i,"body": description,"date": date,"author": username
}
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)