some code cleanup now that its working
This commit is contained in:
parent
6b96e22ebf
commit
93e589659d
|
@ -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,6 +146,8 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
|
|||
});
|
||||
} else { if( !GCD.dCO ) { logger.info(IC.idRSS)}}
|
||||
|
||||
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`
|
||||
|
@ -165,6 +172,7 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
|
|||
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 )}
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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(),
|
||||
|
@ -47,3 +32,5 @@ export const satoriOG = ({
|
|||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default satoriOG;
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue