fix(route): touhougarakuta (#9297)

* Fixes DIYgod/RSSHub#9271

* Sovel DeepScan reported issues

* fix logic issue

Co-authored-by: vcup <vcup@gmail.com>
This commit is contained in:
vcup
2022-03-11 19:21:55 +08:00
committed by GitHub
co-authored by vcup
parent b7df26724e
commit 65f6086bc8
2 changed files with 26 additions and 12 deletions
+4 -2
View File
@@ -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;
+22 -10
View File
@@ -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) + `<img src="${article.indexCover.cover.sourceUrl}">` + index(article, language);
const indexNovel = (article, language) => ogpImage(article) + article.index.about + authors(article.index.authors) + `<img src="${article.indexCover.cover.sourceUrl}">` + 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) + '<hr/>' + (leading ? leading : '');
for (const block of article.interviewContents.block) {
result += `<h2 style="text-align: center;">${block.head}</h2>` + block.content;
let result = ogpImage(article) + linkToIndex(article, language) + '<hr/>' + (leading ? leading : '');
for (const block of article.interviewContents.block) {
result += `<h2 style="text-align: center;">${block.head}</h2>` + 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) + '<hr/>' + article.contents.texts;
/**
* 生成超链接,并将 edit 替换为对应语言
* 生成超链接,并将 edit 替换为对应语言; 从 article.index.item 会有带 edit 的 url 进来
*/
const href = (text, url, language) => `<a href="${url.replace(/\/\/edit/, `//${language}`)}">${text}</a>`;
const href = (text, url, language) => `<a href="${url.replace(/\/\/edit/, `//${language === 'ja' ? '' : language}`)}">${text}</a>`;
/**
* 处理 authors
@@ -75,8 +84,11 @@ const ogpImage = (article) => `<img src="${article.ogpSettings.ogp.image.sourceU
* 处理 linkToIndex
*/
const linkToIndex = (article, language) => {
const index = article.linkToIndex.linktoindex;
return index ? `<p>Index:${href(index.title, index.url, language)}</p>` : '';
if (article.hasOwnProperty('linkToIndex') && article.linkToIndex.linktoindex !== null) {
const index = article.linkToIndex.linktoindex;
return `<p>Index:${href(index.title, index.url, language)}</p>`;
}
return '';
};
/**