some code cleanup now that its working
This commit is contained in:
parent
6b96e22ebf
commit
93e589659d
|
@ -53,7 +53,11 @@ const IC = {
|
||||||
/** INTERNAL STRING */
|
/** INTERNAL STRING */
|
||||||
id404: "404 Injection Disabled",
|
id404: "404 Injection Disabled",
|
||||||
/** INTERNAL STRING */
|
/** 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 */
|
/** CONTENT API ENVIRONMENT VARIABLES */
|
||||||
|
@ -91,7 +95,8 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
|
||||||
RTXT: GhostConfig.robotstxt,
|
RTXT: GhostConfig.robotstxt,
|
||||||
gSite: GhostConfig.ghostURL,
|
gSite: GhostConfig.ghostURL,
|
||||||
dRSS: GhostConfig.disableRSS,
|
dRSS: GhostConfig.disableRSS,
|
||||||
d404: GhostConfig.disable404
|
d404: GhostConfig.disable404,
|
||||||
|
dOG: GhostConfig.disableSatoriOG
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check For ENV Variables
|
// Check For ENV Variables
|
||||||
|
@ -141,30 +146,33 @@ export default function GhostCMS(options: UserConfig): AstroIntegration {
|
||||||
});
|
});
|
||||||
} else { if( !GCD.dCO ) { logger.info(IC.idRSS)}}
|
} else { if( !GCD.dCO ) { logger.info(IC.idRSS)}}
|
||||||
|
|
||||||
injectRoute({
|
if ( !GCD.dOG ) {
|
||||||
pattern: '/open-graph/[slug].png',
|
if( !GCD.dCO ) { logger.info( IC.satori_e )}
|
||||||
entrypoint: `${IC.PKG}/open-graph/[slug].png.ts`
|
injectRoute({
|
||||||
});
|
pattern: '/open-graph/[slug].png',
|
||||||
injectRoute({
|
entrypoint: `${IC.PKG}/open-graph/[slug].png.ts`
|
||||||
pattern: '/open-graph/index.png',
|
});
|
||||||
entrypoint: `${IC.PKG}/open-graph/index.png.ts`
|
injectRoute({
|
||||||
});
|
pattern: '/open-graph/index.png',
|
||||||
injectRoute({
|
entrypoint: `${IC.PKG}/open-graph/index.png.ts`
|
||||||
pattern: '/open-graph/authors.png',
|
});
|
||||||
entrypoint: `${IC.PKG}/open-graph/authors.png.ts`
|
injectRoute({
|
||||||
});
|
pattern: '/open-graph/authors.png',
|
||||||
injectRoute({
|
entrypoint: `${IC.PKG}/open-graph/authors.png.ts`
|
||||||
pattern: '/open-graph/author/[slug].png',
|
});
|
||||||
entrypoint: `${IC.PKG}/open-graph/author/[slug].png.ts`
|
injectRoute({
|
||||||
});
|
pattern: '/open-graph/author/[slug].png',
|
||||||
injectRoute({
|
entrypoint: `${IC.PKG}/open-graph/author/[slug].png.ts`
|
||||||
pattern: '/open-graph/tags.png',
|
});
|
||||||
entrypoint: `${IC.PKG}/open-graph/tags.png.ts`
|
injectRoute({
|
||||||
});
|
pattern: '/open-graph/tags.png',
|
||||||
injectRoute({
|
entrypoint: `${IC.PKG}/open-graph/tags.png.ts`
|
||||||
pattern: '/open-graph/tag/[slug].png',
|
});
|
||||||
entrypoint: `${IC.PKG}/open-graph/tag/[slug].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
|
// THEME ROUTES
|
||||||
if( !GCD.dCO ) { logger.info( IC.ITR )}
|
if( !GCD.dCO ) { logger.info( IC.ITR )}
|
||||||
|
|
|
@ -54,11 +54,12 @@
|
||||||
"./rss.xml.ts": "./src/default-routes/rss.xml.ts",
|
"./rss.xml.ts": "./src/default-routes/rss.xml.ts",
|
||||||
"./config": "./src/integrations/virtual-config.ts",
|
"./config": "./src/integrations/virtual-config.ts",
|
||||||
"./types": "./types.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/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/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/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"
|
"./open-graph/tag/[slug].png.ts": "./src/default-routes/open-graph/tag/[slug].png.ts"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import type { APIRoute, GetStaticPaths, GetStaticPathsItem, InferGetStaticPropsType } from "astro";
|
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 { html } from "satori-html";
|
||||||
import { invariant, getAllPosts, getAllPages, getSettings } from "../../api/index.js";
|
import { invariant, getAllPosts, getAllPages, getSettings } from "../../api/index.js";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import type { APIRoute, GetStaticPaths, GetStaticPathsItem, InferGetStaticParamsType, InferGetStaticPropsType } from "astro";
|
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 { html } from "satori-html";
|
||||||
import { invariant, getAllPosts, getSettings, getAllAuthors } from "../../../api/index.js";
|
import { invariant, getAllPosts, getSettings, getAllAuthors } from "../../../api/index.js";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import type { APIRoute, GetStaticPaths, GetStaticPathsItem, InferGetStaticPropsType } from "astro";
|
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 { html } from "satori-html";
|
||||||
import { invariant, getAllPosts, getAllPages, getSettings } from "../../api/index.js";
|
import { invariant, getAllPosts, getAllPages, getSettings } from "../../api/index.js";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import type { APIRoute, GetStaticPaths, GetStaticPathsItem, InferGetStaticPropsType } from "astro";
|
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 { html } from "satori-html";
|
||||||
import { invariant, getAllPosts, getAllPages, getSettings } from "../../api/index.js";
|
import { invariant, getAllPosts, getAllPages, getSettings } from "../../api/index.js";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import type { APIRoute, GetStaticPaths, GetStaticPathsItem, InferGetStaticPropsType } from "astro";
|
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 { html } from "satori-html";
|
||||||
import { invariant, getAllPosts, getSettings, getAllTags } from "../../../api/index.js";
|
import { invariant, getAllPosts, getSettings, getAllTags } from "../../../api/index.js";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import type { APIRoute, GetStaticPaths, GetStaticPathsItem, InferGetStaticPropsType } from "astro";
|
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 { html } from "satori-html";
|
||||||
import { invariant, getAllPosts, getAllPages, getSettings } from "../../api/index.js";
|
import { invariant, getAllPosts, getAllPages, getSettings } from "../../api/index.js";
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,13 @@
|
||||||
import { Resvg } from "@resvg/resvg-js";
|
import { Resvg } from "@resvg/resvg-js";
|
||||||
import satori from "satori";
|
import satori from "satori";
|
||||||
import type {
|
import type { SatoriAstroOGOptions, ToSvgOptions, ToImageOptions, ToResponseOptions } from "../../types.js";
|
||||||
SatoriAstroOGOptions,
|
|
||||||
ToSvgOptions,
|
|
||||||
ToImageOptions,
|
|
||||||
ToResponseOptions,
|
|
||||||
} from "../../types.js";
|
|
||||||
|
|
||||||
export const satoriOG = ({
|
const satoriOG = ({ width, height, template }: SatoriAstroOGOptions) => {
|
||||||
width,
|
|
||||||
height,
|
|
||||||
template,
|
|
||||||
}: SatoriAstroOGOptions) => {
|
|
||||||
return {
|
return {
|
||||||
async toSvg(options: ToSvgOptions) {
|
async toSvg(options: ToSvgOptions) {
|
||||||
return await satori(template, { width, height, ...options });
|
return await satori(template, { width, height, ...options });
|
||||||
},
|
},
|
||||||
async toImage({
|
async toImage({ satori: satoriOptions, resvg: _resvgOptions }: ToImageOptions) {
|
||||||
satori: satoriOptions,
|
|
||||||
resvg: _resvgOptions,
|
|
||||||
}: ToImageOptions) {
|
|
||||||
const resvgOptions =
|
const resvgOptions =
|
||||||
typeof _resvgOptions === "function"
|
typeof _resvgOptions === "function"
|
||||||
? _resvgOptions({ width, height })
|
? _resvgOptions({ width, height })
|
||||||
|
@ -28,15 +16,12 @@ export const satoriOG = ({
|
||||||
return new Resvg(await this.toSvg(satoriOptions), {
|
return new Resvg(await this.toSvg(satoriOptions), {
|
||||||
fitTo: { mode: "width", value: width },
|
fitTo: { mode: "width", value: width },
|
||||||
...resvgOptions,
|
...resvgOptions,
|
||||||
})
|
}).render().asPng();
|
||||||
.render()
|
|
||||||
.asPng();
|
|
||||||
},
|
},
|
||||||
async toResponse({ response: init, ...rest }: ToResponseOptions) {
|
async toResponse({ response: init, ...rest }: ToResponseOptions) {
|
||||||
const image = await this.toImage(rest);
|
const image = await this.toImage(rest);
|
||||||
|
|
||||||
return new Response(image, {
|
return new Response(image, {...init,
|
||||||
...init,
|
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "image/png",
|
"Content-Type": "image/png",
|
||||||
"Content-Length": image.length.toString(),
|
"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(),
|
ghostURL: z.string().url().optional(),
|
||||||
/** OPTIONAL - Allows the user to disable the `/rss.xml` injection */
|
/** OPTIONAL - Allows the user to disable the `/rss.xml` injection */
|
||||||
disableRSS: z.boolean().default(false),
|
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 */
|
/** OPTIONAL - Allows the user to disable the `/404` injection */
|
||||||
disable404: z.boolean().default(false),
|
disable404: z.boolean().default(false),
|
||||||
/** OPTIONAL - Disable Route Injector
|
/** OPTIONAL - Disable Route Injector
|
||||||
|
|
Loading…
Reference in New Issue