diff --git a/package-lock.json b/package-lock.json index e45c2f7b..6baa5369 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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" }, diff --git a/workers/dynamic-pages/utils/generators.js b/workers/dynamic-pages/utils/generators.js index e3e015a6..7c4a3ec6 100644 --- a/workers/dynamic-pages/utils/generators.js +++ b/workers/dynamic-pages/utils/generators.js @@ -6,6 +6,64 @@ import { ICON_MAP } from "./icons.js"; const warningBanner = ``; +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) => { ${ book["review"] - ? `${warningBanner}

My thoughts

${book["review"]}

` + ? `${warningBanner}

My thoughts

${md.render(book["review"])}

` : "" } ${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";