redirecter for ao3 that adds opengraph metadata

fix wrong base for images

Changed files
+21 -3
src
app
series
[seriesId]
works
[workId]
chapters
[chapterId]
+7 -1
src/app/series/[seriesId]/page.js
···
import { getSeries } from "@fujocoded/ao3.js"
+
import DOM from "fauxdom"
export async function generateMetadata({ params, _searchParams }, _parent) {
// read route params
···
const fandoms = series.works.map(w => w.fandoms).reduce((a,b) => { return a.concat(b) }).filter((f, i, arr) => arr.indexOf(f) === i)
const fandomString = fandoms.length > 4 ? fandoms.slice(0, 4).join(", ")+" (+"+(fandoms.length - 4)+")" : (fandoms.length > 1 ? fandoms.slice(0, -1).join(", ")+" & "+fandoms.slice(-1)[0] : fandoms[0])
const title = `${series.name} by ${authorString} - ${fandomString} (${series.workCount} works)`
-
const description = `${series.description.replace("<br />", "\n").replace(/<[^>]>/g, "")}`
+
const summaryDOM = new DOM(summary, {decodeEntities: true});
+
const description = summaryDOM.innerHTML.replace(/\<br(?: \/)?\>/g, "\n").replace(
+
/(<([^>]+)>)/ig,
+
"",
+
)
const addr = `series/${seriesId}`
return {
title: title,
description: description,
+
metadataBase: new URL('https://'+process.env.DOMAIN),
openGraph: {
description: description
}
+7 -1
src/app/works/[workId]/chapters/[chapterId]/page.js
···
import { getWork } from "@fujocoded/ao3.js"
+
import DOM from "fauxdom"
export async function generateMetadata({ params, _searchParams }, _parent) {
// read route params
···
const fandomString = fandoms.length > 4 ? fandoms.slice(0, 4).join(", ")+" (+"+(fandoms.length - 4)+")" : (fandoms.length > 1 ? fandoms.slice(0, -1).join(", ")+" & "+fandoms.slice(-1)[0] : fandoms[0])
const title = `${work.title} by ${authorString}, Chapter ${work.chapterInfo.index}${work.chapterInfo.name ? ": "+work.chapterInfo.name : ''} - ${fandomString}`
const summary = work.chapterInfo && work.chapterInfo.summary ? work.chapterInfo.summary : work.summary
-
const description = `${summary.replace("<br />", "\n").replace(/<[^>]>/g, "")}`
+
const summaryDOM = new DOM(summary, {decodeEntities: true});
+
const description = summaryDOM.innerHTML.replace(/\<br(?: \/)?\>/g, "\n").replace(
+
/(<([^>]+)>)/ig,
+
"",
+
)
const addr = `works/${workId}/chapters/${chapterId}`
return {
title: title,
description: description,
+
metadataBase: new URL('https://'+process.env.DOMAIN),
openGraph: {
description: description
}
+7 -1
src/app/works/[workId]/page.js
···
import { getWork } from "@fujocoded/ao3.js"
+
import DOM from "fauxdom"
export async function generateMetadata({ params, _searchParams }, _parent) {
// read route params
···
const fandomString = fandoms.length > 4 ? fandoms.slice(0, 4).join(", ")+" (+"+(fandoms.length - 4)+")" : (fandoms.length > 1 ? fandoms.slice(0, -1).join(", ")+" & "+fandoms.slice(-1)[0] : fandoms[0])
const title = `${work.title} by ${authorString} - ${fandomString}`
const summary = work.summary
-
const description = `${summary.replace("<br />", "\n").replace(/<[^>]>/g, "")}`
+
const summaryDOM = new DOM(summary, {decodeEntities: true});
+
const description = summaryDOM.innerHTML.replace(/\<br(?: \/)?\>/g, "\n").replace(
+
/(<([^>]+)>)/ig,
+
"",
+
)
const addr = `works/${workId}`
return {
title: title,
description: description,
+
metadataBase: new URL('https://'+process.env.DOMAIN),
openGraph: {
description: description
}