From 65f6086bc87f09fc1561c67fdafb4b03dc656102 Mon Sep 17 00:00:00 2001 From: vcup Date: Fri, 11 Mar 2022 19:21:55 +0800 Subject: [PATCH] fix(route): touhougarakuta (#9297) * Fixes DIYgod/RSSHub#9271 * Sovel DeepScan reported issues * fix logic issue Co-authored-by: vcup --- lib/routes/touhougarakuta/index.js | 6 +++-- lib/routes/touhougarakuta/json2html.js | 32 ++++++++++++++++++-------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/routes/touhougarakuta/index.js b/lib/routes/touhougarakuta/index.js index c5c240bf8..e895490c3 100644 --- a/lib/routes/touhougarakuta/index.js +++ b/lib/routes/touhougarakuta/index.js @@ -16,7 +16,7 @@ module.exports = async (ctx) => { const response = await got({ method: 'get', - url: `${baseUrl}/page-data/${type}/page-data.json`, + url: `${baseUrl}/page-data/${type === 'interviews' ? 'tags/interviews' : type}/page-data.json`, }); ctx.state.data = { @@ -33,6 +33,7 @@ module.exports = async (ctx) => { try { switch (article.type) { case 'index_interview': + case 'column': result.description = j2h.indexInterview(article, language); break; case 'index_comic': @@ -42,6 +43,7 @@ module.exports = async (ctx) => { result.description = j2h.indexNovel(article, language); break; case 'interview': + case 'report': result.description = j2h.interview(article, language); break; case 'novel': @@ -54,7 +56,7 @@ module.exports = async (ctx) => { result.description = j2h.uncategorized(article); } } catch (error) { - error.message += ` (at article ${i}: ${article.title})`; + error.message += `(at article ${i}: ${article.title})`; throw error; } return result; diff --git a/lib/routes/touhougarakuta/json2html.js b/lib/routes/touhougarakuta/json2html.js index 0654522cd..ff99bc449 100644 --- a/lib/routes/touhougarakuta/json2html.js +++ b/lib/routes/touhougarakuta/json2html.js @@ -1,17 +1,26 @@ -const indexInterview = (article, language) => ogpImage(article) + article.index.about + index(article, language); +const indexInterview = (article, language) => { + if (article.hasOwnProperty('index')) { + return ogpImage(article) + article.ogpSettings.ogp.description + index(article, language); + } + return ogpImage(article); +}; const indexComic = (article, language) => ogpImage(article) + article.index.about + authors(article.index.authors) + `` + index(article, language); const indexNovel = (article, language) => ogpImage(article) + article.index.about + authors(article.index.authors) + `` + index(article, language); const interview = (article, language) => { - const leading = article.interviewContents.leading; + if (article.hasOwnProperty('interviewContents')) { + const leading = article.interviewContents.leading; - let result = ogpImage(article) + linkToIndex(article, language) + '
' + (leading ? leading : ''); - for (const block of article.interviewContents.block) { - result += `

${block.head}

` + block.content; + let result = ogpImage(article) + linkToIndex(article, language) + '
' + (leading ? leading : ''); + for (const block of article.interviewContents.block) { + result += `

${block.head}

` + block.content; + } + return result; } - return result; + + return ogpImage(article) + linkToIndex(article, language); }; const novel = (article, language) => @@ -38,9 +47,9 @@ const comic = (article, language) => { const uncategorized = (article, language) => ogpImage(article) + linkToIndex(article, language) + '
' + article.contents.texts; /** - * 生成超链接,并将 edit 替换为对应语言 + * 生成超链接,并将 edit 替换为对应语言; 从 article.index.item 会有带 edit 的 url 进来 */ -const href = (text, url, language) => `${text}`; +const href = (text, url, language) => `${text}`; /** * 处理 authors @@ -75,8 +84,11 @@ const ogpImage = (article) => `