fix: markdown parsing
This commit is contained in:
parent
0bbff10d8b
commit
74d3fe1b44
2 changed files with 68 additions and 68 deletions
18
package-lock.json
generated
18
package-lock.json
generated
|
@ -722,9 +722,9 @@
|
|||
"peer": true
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "22.8.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.6.tgz",
|
||||
"integrity": "sha512-tosuJYKrIqjQIlVCM4PEGxOmyg3FCPa/fViuJChnGeEIhjA46oy8FMVoF9su1/v8PNs2a8Q0iFNyOx0uOF91nw==",
|
||||
"version": "22.8.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.7.tgz",
|
||||
"integrity": "sha512-LidcG+2UeYIWcMuMUpBKOnryBWG/rnmOHQR5apjn8myTQcx3rinFRn7DcIFhMnS0PPFSC6OafdIKEad0lj6U0Q==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~6.19.8"
|
||||
|
@ -1163,9 +1163,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/caniuse-lite": {
|
||||
"version": "1.0.30001676",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001676.tgz",
|
||||
"integrity": "sha512-Qz6zwGCiPghQXGJvgQAem79esjitvJ+CxSbSQkW9H/UX5hg8XM88d4lp2W+MEQ81j+Hip58Il+jGVdazk1z9cw==",
|
||||
"version": "1.0.30001677",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001677.tgz",
|
||||
"integrity": "sha512-fmfjsOlJUpMWu+mAAtZZZHz7UEwsUxIIvu1TJfO1HqFQvB/B+ii0xr9B5HpbZY/mC4XZ8SvjHJqtAY6pDPQEog==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
|
@ -1788,9 +1788,9 @@
|
|||
"license": "MIT"
|
||||
},
|
||||
"node_modules/electron-to-chromium": {
|
||||
"version": "1.5.50",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.50.tgz",
|
||||
"integrity": "sha512-eMVObiUQ2LdgeO1F/ySTXsvqvxb6ZH2zPGaMYsWzRDdOddUa77tdmI0ltg+L16UpbWdhPmuF3wIQYyQq65WfZw==",
|
||||
"version": "1.5.51",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.51.tgz",
|
||||
"integrity": "sha512-kKeWV57KSS8jH4alKt/jKnvHPmJgBxXzGUSbMd4eQF+iOsVPl7bz2KUmu6eo80eMP8wVioTfTyTzdMgM15WXNg==",
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
|
|
|
@ -6,6 +6,64 @@ import { ICON_MAP } from "./icons.js";
|
|||
|
||||
const warningBanner = `<div class="banner warning"><p>${ICON_MAP["alertTriangle"]}There are probably spoilers after this banner — this is a warning about them.</p></div>`;
|
||||
|
||||
export const generateMetadata = (data, type, globals) => {
|
||||
let title = globals["site_name"];
|
||||
let description = data["description"] || globals["site_description"];
|
||||
const canonicalUrl = data["url"]
|
||||
? `${globals["url"]}${data["url"]}`
|
||||
: globals["url"];
|
||||
const ogImage = `${globals["cdn_url"]}${(data["backdrop"] ? data["backdrop"] : data["image"]) || globals["avatar"]}?class=w800`;
|
||||
|
||||
description = convert(
|
||||
truncateHtml(md.render(description), 100, {
|
||||
byWords: true,
|
||||
ellipsis: "...",
|
||||
}),
|
||||
{
|
||||
wordwrap: false,
|
||||
selectors: [
|
||||
{ selector: "a", options: { ignoreHref: true } },
|
||||
{ selector: "h1", options: { uppercase: false } },
|
||||
{ selector: "h2", options: { uppercase: false } },
|
||||
{ selector: "h3", options: { uppercase: false } },
|
||||
{ selector: "*", format: "block" },
|
||||
],
|
||||
}
|
||||
)
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
|
||||
switch (type) {
|
||||
case "artist":
|
||||
title = `Artists / ${data["name"]} / ${globals["site_name"]}`;
|
||||
break;
|
||||
case "genre":
|
||||
title = `Genre / ${data["name"]} / ${globals["site_name"]}`;
|
||||
break;
|
||||
case "book":
|
||||
title = `Books / ${data["title"]} by ${data["author"]} / ${globals["site_name"]}`;
|
||||
break;
|
||||
case "movie":
|
||||
title = `Movies / ${data["title"]} (${data["year"]}) / ${globals["site_name"]}`;
|
||||
break;
|
||||
case "show":
|
||||
title = `Shows / ${data["title"]} / ${globals["site_name"]}`;
|
||||
break;
|
||||
default:
|
||||
title = `${data["title"] || globals["site_name"]}`;
|
||||
}
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
"og:title": title,
|
||||
"og:description": description,
|
||||
"og:image": ogImage,
|
||||
"og:url": canonicalUrl,
|
||||
canonical: canonicalUrl,
|
||||
};
|
||||
};
|
||||
|
||||
const generateAssociatedMediaHTML = (data, isGenre = false) => {
|
||||
const sections = [
|
||||
{
|
||||
|
@ -299,7 +357,7 @@ export const generateBookHTML = (book, globals) => {
|
|||
</div>
|
||||
${
|
||||
book["review"]
|
||||
? `${warningBanner}<h2>My thoughts</h2><p>${book["review"]}</p>`
|
||||
? `${warningBanner}<h2>My thoughts</h2><p>${md.render(book["review"])}</p>`
|
||||
: ""
|
||||
}
|
||||
${generateAssociatedMediaHTML(book)}
|
||||
|
@ -346,64 +404,6 @@ export const generateGenreHTML = (genre) => {
|
|||
`;
|
||||
};
|
||||
|
||||
export const generateMetadata = (data, type, globals) => {
|
||||
let title = globals["site_name"];
|
||||
let description = data["description"] || globals["site_description"];
|
||||
const canonicalUrl = data["url"]
|
||||
? `${globals["url"]}${data["url"]}`
|
||||
: globals["url"];
|
||||
const ogImage = `${globals["cdn_url"]}${(data["backdrop"] ? data["backdrop"] : data["image"]) || globals["avatar"]}?class=w800`;
|
||||
|
||||
description = convert(
|
||||
truncateHtml(md.render(description), 100, {
|
||||
byWords: true,
|
||||
ellipsis: "...",
|
||||
}),
|
||||
{
|
||||
wordwrap: false,
|
||||
selectors: [
|
||||
{ selector: "a", options: { ignoreHref: true } },
|
||||
{ selector: "h1", options: { uppercase: false } },
|
||||
{ selector: "h2", options: { uppercase: false } },
|
||||
{ selector: "h3", options: { uppercase: false } },
|
||||
{ selector: "*", format: "block" },
|
||||
],
|
||||
}
|
||||
)
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
|
||||
switch (type) {
|
||||
case "artist":
|
||||
title = `Artists / ${data["name"]} / ${globals["site_name"]}`;
|
||||
break;
|
||||
case "genre":
|
||||
title = `Genre / ${data["name"]} / ${globals["site_name"]}`;
|
||||
break;
|
||||
case "book":
|
||||
title = `Books / ${data["title"]} by ${data["author"]} / ${globals["site_name"]}`;
|
||||
break;
|
||||
case "movie":
|
||||
title = `Movies / ${data["title"]} (${data["year"]}) / ${globals["site_name"]}`;
|
||||
break;
|
||||
case "show":
|
||||
title = `Shows / ${data["title"]} / ${globals["site_name"]}`;
|
||||
break;
|
||||
default:
|
||||
title = `${data["title"] || globals["site_name"]}`;
|
||||
}
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
"og:title": title,
|
||||
"og:description": description,
|
||||
"og:image": ogImage,
|
||||
"og:url": canonicalUrl,
|
||||
canonical: canonicalUrl,
|
||||
};
|
||||
};
|
||||
|
||||
export const generateWatchingHTML = (media, globals, type) => {
|
||||
const isShow = type === "show";
|
||||
const label = isShow ? "show" : "movie";
|
||||
|
|
Reference in a new issue