Skip to content

Commit

Permalink
Merge pull request #17 from MarvNC/add-breadcrumbs-list
Browse files Browse the repository at this point in the history
Add Breadcrumbs List
  • Loading branch information
MarvNC authored Jul 7, 2024
2 parents eb5acf1 + 561bac3 commit 2ec5f33
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"japanese-furigana-normalize": "^1.0.5",
"prisma": "^5.9.1",
"yargs": "^17.7.2",
"yomichan-dict-builder": "^2.5.0"
"yomichan-dict-builder": "^2.6.0"
},
"devDependencies": {
"@types/cli-progress": "^3.11.5",
Expand Down
2 changes: 1 addition & 1 deletion src/yomitan/createDetailedDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function createDetailedDefinition(
): DetailedDefinition {
const scList: StructuredContentNode = [];
// Parent tag/bracket stuff
addParentInfo(article, scList, bracketContent);
addParentInfo(article, scList, bracketContent, pixivLight);
// Summary
if (article.summary) {
scList.push(
Expand Down
57 changes: 51 additions & 6 deletions src/yomitan/detailedDefinition/addParentInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export function addParentInfo(
article: PixivArticle,
scList: StructuredContentNode[],
bracketContent: string,
pixivLight: boolean,
) {
if (bracketContent) {
scList.push({
Expand All @@ -21,7 +22,49 @@ export function addParentInfo(
});
}

if (article.parent) {
if (article.header) {
const headerArray = JSON.parse(article.header) as string[];
if (!Array.isArray(headerArray)) {
throw new Error('header should be an array');
}
if (headerArray.length <= 2) {
return;
}
// Remove last element (current article)
headerArray.pop();
const parent = headerArray.pop();
if (!parent) {
return;
}
headerArray.reverse();
const parentLink: StructuredContentNode = {
tag: 'a',
content: `←${parent}`,
href: `?query=${parent}`,
};
const contentListInsideDetails: StructuredContentNode[] = [
{
tag: 'summary',
content: parentLink,
},
];
if (headerArray.length > 1) {
// Create ul list of breadcrumbs within details block
contentListInsideDetails.push({
tag: 'ul',
content: headerArray.map((header) => ({
tag: 'li',
content: {
tag: 'a',
content: header,
href: `?query=${header}`,
},
})),
data: {
pixiv: 'series',
},
});
}
scList.push({
tag: 'div',
data: {
Expand All @@ -30,11 +73,13 @@ export function addParentInfo(
style: {
fontWeight: 'bold',
},
content: {
tag: 'a',
content: `←${article.parent}`,
href: `?query=${article.parent}`,
},
// If lightweight mode, just show parent link, otherwise show list of breadcrumbs
content: pixivLight
? parentLink
: {
tag: 'details',
content: contentListInsideDetails,
},
});
}
}

0 comments on commit 2ec5f33

Please sign in to comment.