some code cleanup now that its working

This commit is contained in:
Adam Matthiesen 2024-01-30 04:54:01 -08:00
parent 6b96e22ebf
commit 93e589659d
10 changed files with 56 additions and 56 deletions

View File

@ -53,7 +53,11 @@ const IC = {
/** INTERNAL STRING */
id404: "404 Injection Disabled",
/** INTERNAL STRING */
idRSS: "RSS Injection Disabled"
idRSS: "RSS Injection Disabled",
/** INTERNAL STRING */
satori_e: "Injecting Satori-OpenGraph Generator",
/** INTERNAL STRING */
satori_d: "Satori Injection disabled"
}
/** CONTENT API ENVIRONMENT VARIABLES */
@ -91,7 +95,8 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
RTXT: GhostConfig.robotstxt,
gSite: GhostConfig.ghostURL,
dRSS: GhostConfig.disableRSS,
d404: GhostConfig.disable404
d404: GhostConfig.disable404,
dOG: GhostConfig.disableSatoriOG
}
// Check For ENV Variables
@ -141,30 +146,33 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
});
} else { if( !GCD.dCO ) { logger.info(IC.idRSS)}}
injectRoute({
pattern: '/open-graph/[slug].png',
entrypoint: `${IC.PKG}/open-graph/[slug].png.ts`
});
injectRoute({
pattern: '/open-graph/index.png',
entrypoint: `${IC.PKG}/open-graph/index.png.ts`
});
injectRoute({
pattern: '/open-graph/authors.png',
entrypoint: `${IC.PKG}/open-graph/authors.png.ts`
});
injectRoute({
pattern: '/open-graph/author/[slug].png',
entrypoint: `${IC.PKG}/open-graph/author/[slug].png.ts`
});
injectRoute({
pattern: '/open-graph/tags.png',
entrypoint: `${IC.PKG}/open-graph/tags.png.ts`
});
injectRoute({
pattern: '/open-graph/tag/[slug].png',
entrypoint: `${IC.PKG}/open-graph/tag/[slug].png.ts`
});
if ( !GCD.dOG ) {
if( !GCD.dCO ) { logger.info( IC.satori_e )}
injectRoute({
pattern: '/open-graph/[slug].png',
entrypoint: `${IC.PKG}/open-graph/[slug].png.ts`
});
injectRoute({
pattern: '/open-graph/index.png',
entrypoint: `${IC.PKG}/open-graph/index.png.ts`
});
injectRoute({
pattern: '/open-graph/authors.png',
entrypoint: `${IC.PKG}/open-graph/authors.png.ts`
});
injectRoute({
pattern: '/open-graph/author/[slug].png',
entrypoint: `${IC.PKG}/open-graph/author/[slug].png.ts`
});
injectRoute({
pattern: '/open-graph/tags.png',
entrypoint: `${IC.PKG}/open-graph/tags.png.ts`
});
injectRoute({
pattern: '/open-graph/tag/[slug].png',
entrypoint: `${IC.PKG}/open-graph/tag/[slug].png.ts`
});
} else { if( !GCD.dCO ) { logger.info( IC.satori_d )}}
// THEME ROUTES
if( !GCD.dCO ) { logger.info( IC.ITR )}

View File

@ -54,11 +54,12 @@
"./rss.xml.ts": "./src/default-routes/rss.xml.ts",
"./config": "./src/integrations/virtual-config.ts",
"./types": "./types.ts",
"./open-graph/[slug].png.ts": "./src/default-routes/open-graph/[slug].png.ts",
"./satoriOG": "./src/integrations/satori.ts",
"./open-graph/index.png.ts": "./src/default-routes/open-graph/index.png.ts",
"./open-graph/authors.png.ts": "./src/default-routes/open-graph/authors.png.ts",
"./open-graph/author/[slug].png.ts": "./src/default-routes/open-graph/author/[slug].png.ts",
"./open-graph/tags.png.ts": "./src/default-routes/open-graph/tags.png.ts",
"./open-graph/[slug].png.ts": "./src/default-routes/open-graph/[slug].png.ts",
"./open-graph/author/[slug].png.ts": "./src/default-routes/open-graph/author/[slug].png.ts",
"./open-graph/tag/[slug].png.ts": "./src/default-routes/open-graph/tag/[slug].png.ts"
},
"scripts": {

View File

@ -1,5 +1,5 @@
import type { APIRoute, GetStaticPaths, GetStaticPathsItem, InferGetStaticPropsType } from "astro";
import { satoriOG } from "../../integrations/satori.js";
import satoriOG from "../../integrations/satori.js";
import { html } from "satori-html";
import { invariant, getAllPosts, getAllPages, getSettings } from "../../api/index.js";

View File

@ -1,5 +1,5 @@
import type { APIRoute, GetStaticPaths, GetStaticPathsItem, InferGetStaticParamsType, InferGetStaticPropsType } from "astro";
import { satoriOG } from "../../../integrations/satori.js";
import type { APIRoute, GetStaticPaths, GetStaticPathsItem, InferGetStaticPropsType } from "astro";
import satoriOG from "../../../integrations/satori.js";
import { html } from "satori-html";
import { invariant, getAllPosts, getSettings, getAllAuthors } from "../../../api/index.js";

View File

@ -1,5 +1,5 @@
import type { APIRoute, GetStaticPaths, GetStaticPathsItem, InferGetStaticPropsType } from "astro";
import { satoriOG } from "../../integrations/satori.js";
import satoriOG from "../../integrations/satori.js";
import { html } from "satori-html";
import { invariant, getAllPosts, getAllPages, getSettings } from "../../api/index.js";

View File

@ -1,5 +1,5 @@
import type { APIRoute, GetStaticPaths, GetStaticPathsItem, InferGetStaticPropsType } from "astro";
import { satoriOG } from "../../integrations/satori.js";
import satoriOG from "../../integrations/satori.js";
import { html } from "satori-html";
import { invariant, getAllPosts, getAllPages, getSettings } from "../../api/index.js";

View File

@ -1,5 +1,5 @@
import type { APIRoute, GetStaticPaths, GetStaticPathsItem, InferGetStaticPropsType } from "astro";
import { satoriOG } from "../../../integrations/satori.js";
import satoriOG from "../../../integrations/satori.js";
import { html } from "satori-html";
import { invariant, getAllPosts, getSettings, getAllTags } from "../../../api/index.js";

View File

@ -1,5 +1,5 @@
import type { APIRoute, GetStaticPaths, GetStaticPathsItem, InferGetStaticPropsType } from "astro";
import { satoriOG } from "../../integrations/satori.js";
import satoriOG from "../../integrations/satori.js";
import { html } from "satori-html";
import { invariant, getAllPosts, getAllPages, getSettings } from "../../api/index.js";

View File

@ -1,25 +1,13 @@
import { Resvg } from "@resvg/resvg-js";
import satori from "satori";
import type {
SatoriAstroOGOptions,
ToSvgOptions,
ToImageOptions,
ToResponseOptions,
} from "../../types.js";
import type { SatoriAstroOGOptions, ToSvgOptions, ToImageOptions, ToResponseOptions } from "../../types.js";
export const satoriOG = ({
width,
height,
template,
}: SatoriAstroOGOptions) => {
const satoriOG = ({ width, height, template }: SatoriAstroOGOptions) => {
return {
async toSvg(options: ToSvgOptions) {
return await satori(template, { width, height, ...options });
},
async toImage({
satori: satoriOptions,
resvg: _resvgOptions,
}: ToImageOptions) {
async toImage({ satori: satoriOptions, resvg: _resvgOptions }: ToImageOptions) {
const resvgOptions =
typeof _resvgOptions === "function"
? _resvgOptions({ width, height })
@ -28,15 +16,12 @@ export const satoriOG = ({
return new Resvg(await this.toSvg(satoriOptions), {
fitTo: { mode: "width", value: width },
...resvgOptions,
})
.render()
.asPng();
}).render().asPng();
},
async toResponse({ response: init, ...rest }: ToResponseOptions) {
const image = await this.toImage(rest);
return new Response(image, {
...init,
return new Response(image, {...init,
headers: {
"Content-Type": "image/png",
"Content-Length": image.length.toString(),
@ -46,4 +31,6 @@ export const satoriOG = ({
});
},
};
};
};
export default satoriOG;

View File

@ -15,6 +15,10 @@ export const UserConfigSchema = z.object({
ghostURL: z.string().url().optional(),
/** OPTIONAL - Allows the user to disable the `/rss.xml` injection */
disableRSS: z.boolean().default(false),
/** OPTIONAL - Allows the user to disable the `/open-graph/*` route injection
* @ This feature uses `satori` to generate OpenGraph Images
*/
disableSatoriOG: z.boolean().default(false),
/** OPTIONAL - Allows the user to disable the `/404` injection */
disable404: z.boolean().default(false),
/** OPTIONAL - Disable Route Injector