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
··· 1 1 import { getSeries } from "@fujocoded/ao3.js" 2 + import DOM from "fauxdom" 2 3 3 4 export async function generateMetadata({ params, _searchParams }, _parent) { 4 5 // read route params ··· 16 17 const fandoms = series.works.map(w => w.fandoms).reduce((a,b) => { return a.concat(b) }).filter((f, i, arr) => arr.indexOf(f) === i) 17 18 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]) 18 19 const title = `${series.name} by ${authorString} - ${fandomString} (${series.workCount} works)` 19 - const description = `${series.description.replace("<br />", "\n").replace(/<[^>]>/g, "")}` 20 + const summaryDOM = new DOM(summary, {decodeEntities: true}); 21 + const description = summaryDOM.innerHTML.replace(/\<br(?: \/)?\>/g, "\n").replace( 22 + /(<([^>]+)>)/ig, 23 + "", 24 + ) 20 25 const addr = `series/${seriesId}` 21 26 22 27 return { 23 28 title: title, 24 29 description: description, 30 + metadataBase: new URL('https://'+process.env.DOMAIN), 25 31 openGraph: { 26 32 description: description 27 33 }
+7 -1
src/app/works/[workId]/chapters/[chapterId]/page.js
··· 1 1 import { getWork } from "@fujocoded/ao3.js" 2 + import DOM from "fauxdom" 2 3 3 4 export async function generateMetadata({ params, _searchParams }, _parent) { 4 5 // read route params ··· 17 18 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]) 18 19 const title = `${work.title} by ${authorString}, Chapter ${work.chapterInfo.index}${work.chapterInfo.name ? ": "+work.chapterInfo.name : ''} - ${fandomString}` 19 20 const summary = work.chapterInfo && work.chapterInfo.summary ? work.chapterInfo.summary : work.summary 20 - const description = `${summary.replace("<br />", "\n").replace(/<[^>]>/g, "")}` 21 + const summaryDOM = new DOM(summary, {decodeEntities: true}); 22 + const description = summaryDOM.innerHTML.replace(/\<br(?: \/)?\>/g, "\n").replace( 23 + /(<([^>]+)>)/ig, 24 + "", 25 + ) 21 26 const addr = `works/${workId}/chapters/${chapterId}` 22 27 23 28 return { 24 29 title: title, 25 30 description: description, 31 + metadataBase: new URL('https://'+process.env.DOMAIN), 26 32 openGraph: { 27 33 description: description 28 34 }
+7 -1
src/app/works/[workId]/page.js
··· 1 1 import { getWork } from "@fujocoded/ao3.js" 2 + import DOM from "fauxdom" 2 3 3 4 export async function generateMetadata({ params, _searchParams }, _parent) { 4 5 // read route params ··· 17 18 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]) 18 19 const title = `${work.title} by ${authorString} - ${fandomString}` 19 20 const summary = work.summary 20 - const description = `${summary.replace("<br />", "\n").replace(/<[^>]>/g, "")}` 21 + const summaryDOM = new DOM(summary, {decodeEntities: true}); 22 + const description = summaryDOM.innerHTML.replace(/\<br(?: \/)?\>/g, "\n").replace( 23 + /(<([^>]+)>)/ig, 24 + "", 25 + ) 21 26 const addr = `works/${workId}` 22 27 23 28 return { 24 29 title: title, 25 30 description: description, 31 + metadataBase: new URL('https://'+process.env.DOMAIN), 26 32 openGraph: { 27 33 description: description 28 34 }