Skip to content

Commit

Permalink
Add attribution footer link
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvNC committed Jan 22, 2024
1 parent 5dc9dbf commit 7502c36
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions src/util/yomitan/createEntryAttribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,41 @@
* @returns {import("yomichan-dict-builder/dist/types/yomitan/termbank").StructuredContent}
*/
function createEntryAttribution(entry) {
/**
* @type {import('yomichan-dict-builder/dist/types/yomitan/termbank').StructuredContent[]}
*/
const contentAttributionSCArray = [
{
tag: 'a',
href: `https://words.hk/zidin/v/${entry.id}`,
content: '粵典 words.hk',
},
];
if (entry.tags.length > 0) {
// Find reference tag if exists
const referenceTag = entry.tags.find((tag) => tag.name === 'ref');
if (referenceTag) {
let urlDomain = '';
try {
const url = new URL(referenceTag.value);
urlDomain = url.hostname;
} catch (error) {
console.error(`Invalid URL: ${referenceTag.value}`);
}

contentAttributionSCArray.unshift(
{
tag: 'a',
href: referenceTag.value,
content: `參考: ${urlDomain}`,
},
{
tag: 'span',
content: ' | ',
}
);
}
}
return {
tag: 'div',
data: {
Expand All @@ -16,13 +51,7 @@ function createEntryAttribution(entry) {
// The examples/definitions above have marginBottom set
marginTop: '-0.4em',
},
content: [
{
tag: 'a',
href: `https://words.hk/zidin/v/${entry.id}`,
content: '粵典 words.hk',
},
],
content: contentAttributionSCArray,
};
}

Expand Down

0 comments on commit 7502c36

Please sign in to comment.