redirecter for ao3 that adds opengraph metadata

move stuff to opengraph-image.jsx files

Changed files
+133 -7
src
app
generator
series
works
[workId]
+1 -1
src/app/generator/page.js
··· 63 63 const fn = async () => { 64 64 if (!addr) return; 65 65 const params = new URLSearchParams(props) 66 - const image = await fetch(`/${addr}/preview?${params.toString()}`) 66 + const image = await fetch(`/${addr}/opengraph-image?${params.toString()}`) 67 67 if (image.status !== 200) return; 68 68 const imageBlob = await image.blob() 69 69 const reader = new FileReader()
+43
src/app/series/[seriesId]/opengraph-image.jsx
··· 1 + import { getSeries } from "@fujocoded/ao3.js" 2 + import sanitizeData from "@/lib/sanitizeData.js" 3 + import OGImage from "@/lib/ogimage.js" 4 + import baseFonts from "@/lib/baseFonts.js" 5 + import titleFonts from "@/lib/titleFonts.js" 6 + 7 + export const size = { 8 + width: 1600, 9 + height: 900, 10 + } 11 + export const alt = 'fixAO3' 12 + 13 + export const contentType = 'image/webp' 14 + 15 + export default async function Image({params}) { 16 + const { seriesId } = await params 17 + const props = new URLSearchParams({ 18 + theme: 'ao3', 19 + baseFont: 'bricolagegrotesque', 20 + titleFont: 'stacksansnotch', 21 + category: true, 22 + rating: true, 23 + warnings: false, 24 + charTags: false, 25 + relTags: false, 26 + freeTags: false, 27 + summary: true, 28 + wordcount: true, 29 + chapters: true, 30 + postedAt: true, 31 + updatedAt: false, 32 + summaryType: 'basic', 33 + customSummary: '' 34 + }) 35 + const addr = `series/${seriesId}` 36 + const data = await getSeries({seriesId: seriesId}) 37 + const imageParams = await sanitizeData({type: 'series', data: data, props: props}) 38 + const theme = imageParams.theme 39 + const baseFont = baseFonts[imageParams.baseFont].displayName 40 + const titleFont = titleFonts[imageParams.titleFont].displayName 41 + const opts = imageParams.opts 42 + return OGImage({theme: theme, baseFont: baseFont, titleFont: titleFont, image: imageParams, addr: addr, opts: opts}) 43 + }
+1 -2
src/app/series/[seriesId]/page.js
··· 23 23 title: title, 24 24 description: description, 25 25 openGraph: { 26 - description: description, 27 - images: [`/${addr}/preview`] 26 + description: description 28 27 } 29 28 } 30 29 }
+43
src/app/works/[workId]/chapters/[chapterId]/opengraph-image.jsx
··· 1 + import { getWork } from "@fujocoded/ao3.js" 2 + import sanitizeData from "@/lib/sanitizeData.js" 3 + import OGImage from "@/lib/ogimage.js" 4 + import baseFonts from "@/lib/baseFonts.js" 5 + import titleFonts from "@/lib/titleFonts.js" 6 + 7 + export const size = { 8 + width: 1600, 9 + height: 900, 10 + } 11 + export const alt = 'fixAO3' 12 + 13 + export const contentType = 'image/webp' 14 + 15 + export default async function Image({params}) { 16 + const { workId, chapterId } = await params 17 + const props = new URLSearchParams({ 18 + theme: 'ao3', 19 + baseFont: 'bricolagegrotesque', 20 + titleFont: 'stacksansnotch', 21 + category: true, 22 + rating: true, 23 + warnings: false, 24 + charTags: false, 25 + relTags: false, 26 + freeTags: false, 27 + summary: true, 28 + wordcount: true, 29 + chapters: true, 30 + postedAt: true, 31 + updatedAt: false, 32 + summaryType: 'basic', 33 + customSummary: '' 34 + }) 35 + const addr = `works/${workId}/chapters/${chapterId}` 36 + const data = await getWork({workId: workId, chapterId: chapterId}) 37 + const imageParams = await sanitizeData({type: 'work', data: data, props: props}) 38 + const theme = imageParams.theme 39 + const baseFont = baseFonts[imageParams.baseFont].displayName 40 + const titleFont = titleFonts[imageParams.titleFont].displayName 41 + const opts = imageParams.opts 42 + return OGImage({theme: theme, baseFont: baseFont, titleFont: titleFont, image: imageParams, addr: addr, opts: opts}) 43 + }
+1 -2
src/app/works/[workId]/chapters/[chapterId]/page.js
··· 24 24 title: title, 25 25 description: description, 26 26 openGraph: { 27 - description: description, 28 - images: [`/${addr}/preview`] 27 + description: description 29 28 } 30 29 } 31 30 }
+43
src/app/works/[workId]/opengraph-image.jsx
··· 1 + import { getWork } from "@fujocoded/ao3.js" 2 + import sanitizeData from "@/lib/sanitizeData.js" 3 + import OGImage from "@/lib/ogimage.js" 4 + import baseFonts from "@/lib/baseFonts.js" 5 + import titleFonts from "@/lib/titleFonts.js" 6 + 7 + export const size = { 8 + width: 1600, 9 + height: 900, 10 + } 11 + export const alt = 'fixAO3' 12 + 13 + export const contentType = 'image/webp' 14 + 15 + export default async function Image({params}) { 16 + const { workId } = await params 17 + const props = new URLSearchParams({ 18 + theme: 'ao3', 19 + baseFont: 'bricolagegrotesque', 20 + titleFont: 'stacksansnotch', 21 + category: true, 22 + rating: true, 23 + warnings: false, 24 + charTags: false, 25 + relTags: false, 26 + freeTags: false, 27 + summary: true, 28 + wordcount: true, 29 + chapters: true, 30 + postedAt: true, 31 + updatedAt: false, 32 + summaryType: 'basic', 33 + customSummary: '' 34 + }) 35 + const addr = `works/${workId}` 36 + const data = await getWork({workId: workId}) 37 + const imageParams = await sanitizeData({type: 'work', data: data, props: props}) 38 + const theme = imageParams.theme 39 + const baseFont = baseFonts[imageParams.baseFont].displayName 40 + const titleFont = titleFonts[imageParams.titleFont].displayName 41 + const opts = imageParams.opts 42 + return OGImage({theme: theme, baseFont: baseFont, titleFont: titleFont, image: imageParams, addr: addr, opts: opts}) 43 + }
+1 -2
src/app/works/[workId]/page.js
··· 24 24 title: title, 25 25 description: description, 26 26 openGraph: { 27 - description: description, 28 - images: [`/${addr}/preview`] 27 + description: description 29 28 } 30 29 } 31 30 }