@altano/astro-opengraph 0.1.0-alpha.4 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/config-CzK0JuaO.js +45 -0
- package/dist/config-CzK0JuaO.js.map +1 -0
- package/dist/config.d.ts +7 -3
- package/dist/config.js +3 -8
- package/dist/endpoint.d.ts +24 -11
- package/dist/endpoint.js +62 -85
- package/dist/endpoint.js.map +1 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +41 -58
- package/dist/index.js.map +1 -0
- package/dist/toolbar/index.d.ts +6 -2
- package/dist/toolbar/index.js +359 -429
- package/dist/toolbar/index.js.map +1 -0
- package/dist/types-B1hoqgLx.d.ts +70 -0
- package/package.json +20 -17
- package/dist/chunk-DX3VCTOX.js +0 -49
- package/dist/image.d.ts +0 -7
- package/dist/integration.d.ts +0 -5
- package/dist/toolbar/components/CopyImageUrlButton.d.ts +0 -3
- package/dist/toolbar/components/Error.d.ts +0 -7
- package/dist/toolbar/components/ExternalLinkicon.d.ts +0 -7
- package/dist/toolbar/components/Image.d.ts +0 -6
- package/dist/toolbar/components/ImageSection.d.ts +0 -6
- package/dist/toolbar/components/ImageZoomToolbar.d.ts +0 -7
- package/dist/toolbar/components/LinkOrText.d.ts +0 -7
- package/dist/toolbar/components/MetaTags.d.ts +0 -3
- package/dist/toolbar/components/Summary.d.ts +0 -5
- package/dist/toolbar/components/ToolbarApp.d.ts +0 -3
- package/dist/toolbar/components/ToolbarAppWindow.d.ts +0 -3
- package/dist/toolbar/components/ToolbarSection.d.ts +0 -7
- package/dist/toolbar/components/ZoomButton.d.ts +0 -7
- package/dist/toolbar/components/ZoomLabel.d.ts +0 -4
- package/dist/toolbar/components/getRelativeUrl.d.ts +0 -2
- package/dist/toolbar/hooks/useHoverState.d.ts +0 -3
- package/dist/toolbar/hooks/useImageURL.d.ts +0 -3
- package/dist/toolbar/hooks/useMetaTagInfo.d.ts +0 -3
- package/dist/toolbar/styles.d.ts +0 -2
- package/dist/types.d.ts +0 -67
- package/dist/virtual-user-config.d.ts +0 -8
package/README.md
CHANGED
|
@@ -419,6 +419,15 @@ export const GET: APIRoute = makeOpengraphDevEndpoint({
|
|
|
419
419
|
});
|
|
420
420
|
```
|
|
421
421
|
|
|
422
|
+
You'll probably want to include a remote stylesheet that has your font face so that it renders correctly in HTML, since the integration's font configuration doesn't affect the HTML rendered version. For example, you might include this in your `./_opengraph.astro`:
|
|
423
|
+
|
|
424
|
+
```
|
|
425
|
+
<link
|
|
426
|
+
href=" https://cdn.jsdelivr.net/npm/@fontsource-variable/inter@5.2.5/index.min.css "
|
|
427
|
+
rel="stylesheet"
|
|
428
|
+
/>
|
|
429
|
+
```
|
|
430
|
+
|
|
422
431
|
# FAQ
|
|
423
432
|
|
|
424
433
|
## Question: How does this work?
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
|
|
3
|
+
//#region src/config.ts
|
|
4
|
+
async function deserializeVirtualConfig(configMaybeMocked) {
|
|
5
|
+
const config = typeof configMaybeMocked === "function" ? configMaybeMocked() : configMaybeMocked;
|
|
6
|
+
const fontsWithBuffers = await Promise.all(config.imageOptions.fonts.map(async (font) => {
|
|
7
|
+
const data = await readFile(font.path);
|
|
8
|
+
return {
|
|
9
|
+
...font,
|
|
10
|
+
data
|
|
11
|
+
};
|
|
12
|
+
}));
|
|
13
|
+
return {
|
|
14
|
+
...config,
|
|
15
|
+
imageOptions: {
|
|
16
|
+
...config.imageOptions,
|
|
17
|
+
fonts: fontsWithBuffers
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const imageOptionDefaults = {
|
|
22
|
+
width: 1200,
|
|
23
|
+
height: 630
|
|
24
|
+
};
|
|
25
|
+
const metaTagDefaults = { "og:image": `/opengraph.png` };
|
|
26
|
+
async function getResolvedConfig() {
|
|
27
|
+
const module = await import("virtual:astro-opengraph/user-config");
|
|
28
|
+
const lazyConfig = module.default;
|
|
29
|
+
const deserialized = await deserializeVirtualConfig(lazyConfig);
|
|
30
|
+
return {
|
|
31
|
+
...deserialized,
|
|
32
|
+
imageOptions: {
|
|
33
|
+
...imageOptionDefaults,
|
|
34
|
+
...deserialized.imageOptions
|
|
35
|
+
},
|
|
36
|
+
componentMetaTagFallbacks: {
|
|
37
|
+
...deserialized.componentMetaTagFallbacks,
|
|
38
|
+
...metaTagDefaults
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { deserializeVirtualConfig, getResolvedConfig };
|
|
45
|
+
//# sourceMappingURL=config-CzK0JuaO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-CzK0JuaO.js","names":["configMaybeMocked: OpengraphImageConfigSerializableMaybeMocked","fontsWithBuffers: FontWithBuffer[]","metaTagDefaults: MetaTagDefaults"],"sources":["../src/config.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\n\nimport type {\n FontWithBuffer,\n MetaTagDefaults,\n OpengraphImageConfigDeserialized,\n OpengraphImageConfigResolved,\n OpengraphImageConfigSerializableMaybeMocked,\n} from \"./types.js\";\n\nexport async function deserializeVirtualConfig(\n configMaybeMocked: OpengraphImageConfigSerializableMaybeMocked,\n): Promise<OpengraphImageConfigDeserialized> {\n const config =\n typeof configMaybeMocked === \"function\"\n ? configMaybeMocked() // We're running in vitest which is only capable of mocking functions\n : configMaybeMocked;\n const fontsWithBuffers: FontWithBuffer[] = await Promise.all(\n config.imageOptions.fonts.map(async (font) => {\n const data = await readFile(font.path);\n return {\n ...font,\n data: data,\n };\n }),\n );\n\n return {\n ...config,\n imageOptions: {\n ...config.imageOptions,\n fonts: fontsWithBuffers,\n },\n };\n}\n\nconst imageOptionDefaults = {\n width: 1200,\n height: 630,\n} as const;\n\nconst metaTagDefaults: MetaTagDefaults = {\n \"og:image\": `/opengraph.png`,\n};\n\nexport async function getResolvedConfig(): Promise<OpengraphImageConfigResolved> {\n // Grab the virtual module that holds the integration's user config\n const module = await import(\"virtual:astro-opengraph/user-config\");\n const lazyConfig = module.default;\n const deserialized = await deserializeVirtualConfig(lazyConfig);\n return {\n ...deserialized,\n imageOptions: {\n ...imageOptionDefaults,\n ...deserialized.imageOptions,\n },\n componentMetaTagFallbacks: {\n ...deserialized.componentMetaTagFallbacks,\n ...metaTagDefaults,\n },\n };\n}\n"],"mappings":";;;AAUA,eAAsB,yBACpBA,mBAC2C;CAC3C,MAAM,gBACG,sBAAsB,aACzB,mBAAmB,GACnB;CACN,MAAMC,mBAAqC,MAAM,QAAQ,IACvD,OAAO,aAAa,MAAM,IAAI,OAAO,SAAS;EAC5C,MAAM,OAAO,MAAM,SAAS,KAAK,KAAK;AACtC,SAAO;GACL,GAAG;GACG;EACP;CACF,EAAC,CACH;AAED,QAAO;EACL,GAAG;EACH,cAAc;GACZ,GAAG,OAAO;GACV,OAAO;EACR;CACF;AACF;AAED,MAAM,sBAAsB;CAC1B,OAAO;CACP,QAAQ;AACT;AAED,MAAMC,kBAAmC,EACvC,aAAa,gBACd;AAED,eAAsB,oBAA2D;CAE/E,MAAM,SAAS,MAAM,OAAO;CAC5B,MAAM,aAAa,OAAO;CAC1B,MAAM,eAAe,MAAM,yBAAyB,WAAW;AAC/D,QAAO;EACL,GAAG;EACH,cAAc;GACZ,GAAG;GACH,GAAG,aAAa;EACjB;EACD,2BAA2B;GACzB,GAAG,aAAa;GAChB,GAAG;EACJ;CACF;AACF"}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { OpengraphImageConfigDeserialized, OpengraphImageConfigResolved, OpengraphImageConfigSerializableMaybeMocked } from "./types-B1hoqgLx.js";
|
|
2
|
+
|
|
3
|
+
//#region src/config.d.ts
|
|
4
|
+
declare function deserializeVirtualConfig(configMaybeMocked: OpengraphImageConfigSerializableMaybeMocked): Promise<OpengraphImageConfigDeserialized>;
|
|
5
|
+
declare function getResolvedConfig(): Promise<OpengraphImageConfigResolved>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { deserializeVirtualConfig, getResolvedConfig };
|
|
4
8
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-DX3VCTOX.js";
|
|
5
|
-
export {
|
|
6
|
-
deserializeVirtualConfig,
|
|
7
|
-
getResolvedConfig
|
|
8
|
-
};
|
|
1
|
+
import { deserializeVirtualConfig, getResolvedConfig } from "./config-CzK0JuaO.js";
|
|
2
|
+
|
|
3
|
+
export { deserializeVirtualConfig, getResolvedConfig };
|
package/dist/endpoint.d.ts
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { ImageOptions } from "./types-B1hoqgLx.js";
|
|
2
|
+
import { APIRoute } from "astro";
|
|
3
|
+
|
|
4
|
+
//#region src/endpoint.d.ts
|
|
3
5
|
type Options = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
// We don't just type this as `AstroComponentFactory` because astro typing is
|
|
7
|
+
// hard to get right and simply importing a .astro file doesn't give you
|
|
8
|
+
// something typed as a factory.
|
|
9
|
+
template: unknown;
|
|
10
|
+
/**
|
|
11
|
+
* Custom "Content-Type" header, only used in SSR. Defaults to "image/png"
|
|
12
|
+
*/
|
|
13
|
+
contentType?: string;
|
|
14
|
+
imageOptionOverrides?: Partial<ImageOptions>;
|
|
10
15
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
declare function makeOpengraphDevEndpoint({
|
|
17
|
+
template,
|
|
18
|
+
contentType
|
|
19
|
+
}: Options): APIRoute;
|
|
20
|
+
declare function makeOpengraphEndpoint({
|
|
21
|
+
template,
|
|
22
|
+
imageOptionOverrides,
|
|
23
|
+
contentType
|
|
24
|
+
}: Options): APIRoute;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { makeOpengraphDevEndpoint, makeOpengraphEndpoint };
|
|
14
27
|
//# sourceMappingURL=endpoint.d.ts.map
|
package/dist/endpoint.js
CHANGED
|
@@ -1,96 +1,73 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getResolvedConfig
|
|
3
|
-
} from "./chunk-DX3VCTOX.js";
|
|
4
|
-
|
|
5
|
-
// src/endpoint.ts
|
|
1
|
+
import { getResolvedConfig } from "./config-CzK0JuaO.js";
|
|
6
2
|
import { experimental_AstroContainer } from "astro/container";
|
|
7
3
|
import { isAstroComponentFactory } from "astro/runtime/server/render/astro/factory.js";
|
|
8
|
-
|
|
9
|
-
// src/image.ts
|
|
10
4
|
import { getConfiguredImageService, imageConfig } from "astro:assets";
|
|
11
5
|
import satori from "satori";
|
|
12
|
-
import { html
|
|
6
|
+
import { html } from "satori-html";
|
|
13
7
|
import he from "he";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
8
|
+
|
|
9
|
+
//#region src/image.ts
|
|
10
|
+
/**
|
|
11
|
+
* Convert an html string to an image
|
|
12
|
+
*/
|
|
13
|
+
async function htmlToPNG(html$1, satoriOptions) {
|
|
14
|
+
const responseTextWithDecodedHtmlEntities = he.decode(html$1);
|
|
15
|
+
const vnode = html(responseTextWithDecodedHtmlEntities);
|
|
16
|
+
const svg = await satori(vnode, satoriOptions);
|
|
17
|
+
const fileBuffer = Buffer.from(svg, "utf-8");
|
|
18
|
+
const uint8Array = new Uint8Array(fileBuffer.buffer, fileBuffer.byteOffset, fileBuffer.byteLength);
|
|
19
|
+
return bufferToTransformedPNG(uint8Array);
|
|
25
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Convert a buffer to an image using the astro local image service
|
|
23
|
+
*/
|
|
26
24
|
async function bufferToTransformedPNG(imageBuffer) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
);
|
|
25
|
+
const imageService = await getConfiguredImageService();
|
|
26
|
+
return imageService.transform(imageBuffer, {
|
|
27
|
+
src: "",
|
|
28
|
+
format: "png"
|
|
29
|
+
}, imageConfig);
|
|
33
30
|
}
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
params,
|
|
53
|
-
locals,
|
|
54
|
-
props
|
|
55
|
-
});
|
|
56
|
-
return new Response(templateStr, {
|
|
57
|
-
headers: {
|
|
58
|
-
"Content-Type": contentType
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
};
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/endpoint.ts
|
|
34
|
+
function makeOpengraphDevEndpoint({ template, contentType = "text/html" }) {
|
|
35
|
+
return async ({ locals, params, props, request }) => {
|
|
36
|
+
const config = await getResolvedConfig();
|
|
37
|
+
if (config.command !== "dev") return new Response(null, { status: 404 });
|
|
38
|
+
if (!isAstroComponentFactory(template)) throw new Error(`Given is not an Astro template.`);
|
|
39
|
+
const container = await experimental_AstroContainer.create();
|
|
40
|
+
const templateStr = await container.renderToString(template, {
|
|
41
|
+
partial: false,
|
|
42
|
+
request,
|
|
43
|
+
params,
|
|
44
|
+
locals,
|
|
45
|
+
props
|
|
46
|
+
});
|
|
47
|
+
return new Response(templateStr, { headers: { "Content-Type": contentType } });
|
|
48
|
+
};
|
|
62
49
|
}
|
|
63
|
-
function makeOpengraphEndpoint({
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
...config.imageOptions,
|
|
83
|
-
...imageOptionOverrides
|
|
84
|
-
};
|
|
85
|
-
const png = await htmlToPNG(templateStr, imageOptions);
|
|
86
|
-
return new Response(png.data, {
|
|
87
|
-
headers: {
|
|
88
|
-
"Content-Type": contentType
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
};
|
|
50
|
+
function makeOpengraphEndpoint({ template, imageOptionOverrides, contentType = "image/png" }) {
|
|
51
|
+
return async ({ locals, params, props, request }) => {
|
|
52
|
+
if (!isAstroComponentFactory(template)) throw new Error(`Given is not an Astro template.`);
|
|
53
|
+
const container = await experimental_AstroContainer.create();
|
|
54
|
+
const templateStr = await container.renderToString(template, {
|
|
55
|
+
partial: false,
|
|
56
|
+
request,
|
|
57
|
+
params,
|
|
58
|
+
locals,
|
|
59
|
+
props
|
|
60
|
+
});
|
|
61
|
+
const config = await getResolvedConfig();
|
|
62
|
+
const imageOptions = {
|
|
63
|
+
...config.imageOptions,
|
|
64
|
+
...imageOptionOverrides
|
|
65
|
+
};
|
|
66
|
+
const png = await htmlToPNG(templateStr, imageOptions);
|
|
67
|
+
return new Response(png.data, { headers: { "Content-Type": contentType } });
|
|
68
|
+
};
|
|
92
69
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { makeOpengraphDevEndpoint, makeOpengraphEndpoint };
|
|
73
|
+
//# sourceMappingURL=endpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint.js","names":["html: string","satoriOptions: SatoriOptions","html","imageBuffer: Uint8Array"],"sources":["../src/image.ts","../src/endpoint.ts"],"sourcesContent":["import { getConfiguredImageService, imageConfig } from \"astro:assets\";\nimport satori, { type SatoriOptions } from \"satori\";\nimport { html as htmlToVNode } from \"satori-html\";\nimport he from \"he\";\n\nimport type { LocalImageService } from \"astro\";\n\n/**\n * Convert an html string to an image\n */\nexport async function htmlToPNG(\n html: string,\n satoriOptions: SatoriOptions,\n): Promise<ReturnType<LocalImageService[\"transform\"]>> {\n // html text => vnode\n const responseTextWithDecodedHtmlEntities = he.decode(html);\n const vnode = htmlToVNode(responseTextWithDecodedHtmlEntities);\n\n // vnode => svg\n const svg = await satori(vnode as React.ReactNode, satoriOptions);\n\n // svg => buffer\n const fileBuffer = Buffer.from(svg, \"utf-8\");\n const uint8Array = new Uint8Array(\n fileBuffer.buffer,\n fileBuffer.byteOffset,\n fileBuffer.byteLength,\n );\n\n // buffer => transformed png\n return bufferToTransformedPNG(uint8Array);\n}\n\n/**\n * Convert a buffer to an image using the astro local image service\n */\nasync function bufferToTransformedPNG(\n imageBuffer: Uint8Array,\n): ReturnType<LocalImageService[\"transform\"]> {\n const imageService = (await getConfiguredImageService()) as LocalImageService;\n\n return imageService.transform(\n imageBuffer,\n { src: \"\", format: \"png\" },\n imageConfig,\n );\n}\n","import type { APIRoute } from \"astro\";\nimport { experimental_AstroContainer } from \"astro/container\";\nimport { isAstroComponentFactory } from \"astro/runtime/server/render/astro/factory.js\";\nimport { getResolvedConfig } from \"./config.js\";\nimport type { ImageOptions } from \"./types.js\";\nimport { htmlToPNG } from \"./image.js\";\n\ntype Options = {\n // We don't just type this as `AstroComponentFactory` because astro typing is\n // hard to get right and simply importing a .astro file doesn't give you\n // something typed as a factory.\n template: unknown;\n /**\n * Custom \"Content-Type\" header, only used in SSR. Defaults to \"image/png\"\n */\n contentType?: string;\n imageOptionOverrides?: Partial<ImageOptions>;\n};\n\nexport function makeOpengraphDevEndpoint({\n template,\n contentType = \"text/html\",\n}: Options): APIRoute {\n return async ({ locals, params, props, request }) => {\n const config = await getResolvedConfig();\n if (config.command !== \"dev\") {\n return new Response(null, { status: 404 });\n }\n\n if (!isAstroComponentFactory(template)) {\n throw new Error(`Given is not an Astro template.`);\n }\n\n const container = await experimental_AstroContainer.create();\n const templateStr = await container.renderToString(template, {\n partial: false,\n request,\n params,\n locals,\n props,\n });\n\n return new Response(templateStr, {\n headers: {\n \"Content-Type\": contentType,\n },\n });\n };\n}\n\nexport function makeOpengraphEndpoint({\n template,\n imageOptionOverrides,\n contentType = \"image/png\",\n}: Options): APIRoute {\n return async ({ locals, params, props, request }) => {\n if (!isAstroComponentFactory(template)) {\n throw new Error(`Given is not an Astro template.`);\n }\n\n const container = await experimental_AstroContainer.create();\n const templateStr = await container.renderToString(template, {\n partial: false,\n request,\n params,\n locals,\n props,\n });\n\n const config = await getResolvedConfig();\n const imageOptions = {\n ...config.imageOptions,\n ...imageOptionOverrides,\n };\n const png = await htmlToPNG(templateStr, imageOptions);\n\n return new Response(png.data, {\n headers: {\n \"Content-Type\": contentType,\n },\n });\n };\n}\n"],"mappings":";;;;;;;;;;;;AAUA,eAAsB,UACpBA,QACAC,eACqD;CAErD,MAAM,sCAAsC,GAAG,OAAOC,OAAK;CAC3D,MAAM,QAAQ,KAAY,oCAAoC;CAG9D,MAAM,MAAM,MAAM,OAAO,OAA0B,cAAc;CAGjE,MAAM,aAAa,OAAO,KAAK,KAAK,QAAQ;CAC5C,MAAM,aAAa,IAAI,WACrB,WAAW,QACX,WAAW,YACX,WAAW;AAIb,QAAO,uBAAuB,WAAW;AAC1C;;;;AAKD,eAAe,uBACbC,aAC4C;CAC5C,MAAM,eAAgB,MAAM,2BAA2B;AAEvD,QAAO,aAAa,UAClB,aACA;EAAE,KAAK;EAAI,QAAQ;CAAO,GAC1B,YACD;AACF;;;;AC3BD,SAAgB,yBAAyB,EACvC,UACA,cAAc,aACN,EAAY;AACpB,QAAO,OAAO,EAAE,QAAQ,QAAQ,OAAO,SAAS,KAAK;EACnD,MAAM,SAAS,MAAM,mBAAmB;AACxC,MAAI,OAAO,YAAY,MACrB,QAAO,IAAI,SAAS,MAAM,EAAE,QAAQ,IAAK;AAG3C,OAAK,wBAAwB,SAAS,CACpC,OAAM,IAAI,OAAO;EAGnB,MAAM,YAAY,MAAM,4BAA4B,QAAQ;EAC5D,MAAM,cAAc,MAAM,UAAU,eAAe,UAAU;GAC3D,SAAS;GACT;GACA;GACA;GACA;EACD,EAAC;AAEF,SAAO,IAAI,SAAS,aAAa,EAC/B,SAAS,EACP,gBAAgB,YACjB,EACF;CACF;AACF;AAED,SAAgB,sBAAsB,EACpC,UACA,sBACA,cAAc,aACN,EAAY;AACpB,QAAO,OAAO,EAAE,QAAQ,QAAQ,OAAO,SAAS,KAAK;AACnD,OAAK,wBAAwB,SAAS,CACpC,OAAM,IAAI,OAAO;EAGnB,MAAM,YAAY,MAAM,4BAA4B,QAAQ;EAC5D,MAAM,cAAc,MAAM,UAAU,eAAe,UAAU;GAC3D,SAAS;GACT;GACA;GACA;GACA;EACD,EAAC;EAEF,MAAM,SAAS,MAAM,mBAAmB;EACxC,MAAM,eAAe;GACnB,GAAG,OAAO;GACV,GAAG;EACJ;EACD,MAAM,MAAM,MAAM,UAAU,aAAa,aAAa;AAEtD,SAAO,IAAI,SAAS,IAAI,MAAM,EAC5B,SAAS,EACP,gBAAgB,YACjB,EACF;CACF;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ComponentMetaTagFallbacks, ImageOptionsWithFontPaths, OpengraphImageConfig } from "./types-B1hoqgLx.js";
|
|
2
|
+
import { AstroIntegration } from "astro";
|
|
3
|
+
|
|
4
|
+
//#region src/integration.d.ts
|
|
5
|
+
declare const _default: (config: OpengraphImageConfig) => AstroIntegration;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { ComponentMetaTagFallbacks, ImageOptionsWithFontPaths, OpengraphImageConfig, _default as default };
|
|
3
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,65 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/virtual-user-config.ts
|
|
2
2
|
function resolveVirtualModuleId(id) {
|
|
3
|
-
|
|
3
|
+
return `\0${id}`;
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* Vite plugin that exposes OpengraphImage user config and project context via
|
|
7
|
+
* virtual modules.
|
|
8
|
+
*/
|
|
5
9
|
function vitePluginOpengraphImageUserConfig(config) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (id in modules) return resolveVirtualModuleId(id);
|
|
21
|
-
},
|
|
22
|
-
load(id) {
|
|
23
|
-
const resolution = resolutionMap[id];
|
|
24
|
-
if (resolution) return modules[resolution];
|
|
25
|
-
}
|
|
26
|
-
};
|
|
10
|
+
/** Map of virtual module names to their code contents as strings. */
|
|
11
|
+
const modules = { "virtual:astro-opengraph/user-config": `export default ${JSON.stringify(config)}` };
|
|
12
|
+
/** Mapping names prefixed with `\0` to their original form. */
|
|
13
|
+
const resolutionMap = Object.fromEntries(Object.keys(modules).map((key) => [resolveVirtualModuleId(key), key]));
|
|
14
|
+
return {
|
|
15
|
+
name: "vite-plugin-astro-opengraph-user-config",
|
|
16
|
+
resolveId(id) {
|
|
17
|
+
if (id in modules) return resolveVirtualModuleId(id);
|
|
18
|
+
},
|
|
19
|
+
load(id) {
|
|
20
|
+
const resolution = resolutionMap[id];
|
|
21
|
+
if (resolution) return modules[resolution];
|
|
22
|
+
}
|
|
23
|
+
};
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/integration.ts
|
|
30
28
|
var integration_default = (config) => ({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// retrieval in the middleware
|
|
47
|
-
plugins: [vitePluginOpengraphImageUserConfig(configSerializable)]
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
addDevToolbarApp({
|
|
51
|
-
id: "@altano/astro-opengraph",
|
|
52
|
-
name: "Open Graph",
|
|
53
|
-
// icon: "🌠",
|
|
54
|
-
icon: "image",
|
|
55
|
-
// We don't use `@altano/astro-opengraph/toolbar` because that won't
|
|
56
|
-
// resolve when serving the test fixture for e2e runs (`pnpm
|
|
57
|
-
// test:e2e:server`)
|
|
58
|
-
entrypoint: new URL("./toolbar/index.js", import.meta.url)
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
29
|
+
name: "@altano/astro-opengraph",
|
|
30
|
+
hooks: { async "astro:config:setup"({ updateConfig, command, addDevToolbarApp }) {
|
|
31
|
+
const imageOptions = await config.getImageOptions();
|
|
32
|
+
const configSerializable = {
|
|
33
|
+
imageOptions,
|
|
34
|
+
command
|
|
35
|
+
};
|
|
36
|
+
updateConfig({ vite: { plugins: [vitePluginOpengraphImageUserConfig(configSerializable)] } });
|
|
37
|
+
addDevToolbarApp({
|
|
38
|
+
id: "@altano/astro-opengraph",
|
|
39
|
+
name: "Open Graph",
|
|
40
|
+
icon: "image",
|
|
41
|
+
entrypoint: new URL("./toolbar/index.js", import.meta.url)
|
|
42
|
+
});
|
|
43
|
+
} }
|
|
62
44
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
};
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { integration_default as default };
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["id: T","config: OpengraphImageConfigSerializable","config: OpengraphImageConfig","configSerializable: OpengraphImageConfigSerializable"],"sources":["../src/virtual-user-config.ts","../src/integration.ts"],"sourcesContent":["import type { ViteUserConfig } from \"astro\";\n\nimport type { OpengraphImageConfigSerializable } from \"./types.js\";\n\nfunction resolveVirtualModuleId<T extends string>(id: T): `\\0${T}` {\n return `\\0${id}`;\n}\n\n/**\n * Vite plugin that exposes OpengraphImage user config and project context via\n * virtual modules.\n */\nexport function vitePluginOpengraphImageUserConfig(\n config: OpengraphImageConfigSerializable,\n): NonNullable<ViteUserConfig[\"plugins\"]>[number] {\n /** Map of virtual module names to their code contents as strings. */\n const modules = {\n \"virtual:astro-opengraph/user-config\": `export default ${JSON.stringify(\n config,\n )}`,\n } satisfies Record<string, string>;\n\n /** Mapping names prefixed with `\\0` to their original form. */\n const resolutionMap = Object.fromEntries(\n (Object.keys(modules) as (keyof typeof modules)[]).map((key) => [\n resolveVirtualModuleId(key),\n key,\n ]),\n );\n\n return {\n name: \"vite-plugin-astro-opengraph-user-config\",\n resolveId(id): string | void {\n if (id in modules) return resolveVirtualModuleId(id);\n },\n load(id): string | void {\n const resolution = resolutionMap[id];\n if (resolution) return modules[resolution];\n },\n };\n}\n","import type { AstroIntegration } from \"astro\";\nimport type {\n OpengraphImageConfig,\n OpengraphImageConfigSerializable,\n} from \"./types.js\";\nimport { vitePluginOpengraphImageUserConfig } from \"./virtual-user-config.js\";\n\nexport default (config: OpengraphImageConfig): AstroIntegration => ({\n name: \"@altano/astro-opengraph\",\n hooks: {\n async \"astro:config:setup\"({\n updateConfig,\n command,\n addDevToolbarApp,\n }): Promise<void> {\n const imageOptions = await config.getImageOptions();\n const configSerializable: OpengraphImageConfigSerializable = {\n imageOptions,\n command,\n };\n updateConfig({\n vite: {\n // Shove the serializable config into the virtual module for later\n // retrieval in the middleware\n plugins: [vitePluginOpengraphImageUserConfig(configSerializable)],\n },\n });\n addDevToolbarApp({\n id: \"@altano/astro-opengraph\",\n name: \"Open Graph\",\n // icon: \"🌠\",\n icon: \"image\",\n // We don't use `@altano/astro-opengraph/toolbar` because that won't\n // resolve when serving the test fixture for e2e runs (`pnpm\n // test:e2e:server`)\n entrypoint: new URL(\"./toolbar/index.js\", import.meta.url),\n });\n },\n },\n});\n"],"mappings":";AAIA,SAAS,uBAAyCA,IAAiB;AACjE,SAAQ,IAAI,GAAG;AAChB;;;;;AAMD,SAAgB,mCACdC,QACgD;;CAEhD,MAAM,UAAU,EACd,wCAAwC,iBAAiB,KAAK,UAC5D,OACD,CAAC,EACH;;CAGD,MAAM,gBAAgB,OAAO,YAC3B,AAAC,OAAO,KAAK,QAAQ,CAA8B,IAAI,CAAC,QAAQ,CAC9D,uBAAuB,IAAI,EAC3B,GACD,EAAC,CACH;AAED,QAAO;EACL,MAAM;EACN,UAAU,IAAmB;AAC3B,OAAI,MAAM,QAAS,QAAO,uBAAuB,GAAG;EACrD;EACD,KAAK,IAAmB;GACtB,MAAM,aAAa,cAAc;AACjC,OAAI,WAAY,QAAO,QAAQ;EAChC;CACF;AACF;;;;ACjCD,0BAAe,CAACC,YAAoD;CAClE,MAAM;CACN,OAAO,EACL,MAAM,qBAAqB,EACzB,cACA,SACA,kBACD,EAAiB;EAChB,MAAM,eAAe,MAAM,OAAO,iBAAiB;EACnD,MAAMC,qBAAuD;GAC3D;GACA;EACD;AACD,eAAa,EACX,MAAM,EAGJ,SAAS,CAAC,mCAAmC,mBAAmB,AAAC,EAClE,EACF,EAAC;AACF,mBAAiB;GACf,IAAI;GACJ,MAAM;GAEN,MAAM;GAIN,YAAY,IAAI,IAAI,sBAAsB,OAAO,KAAK;EACvD,EAAC;CACH,EACF;AACF"}
|
package/dist/toolbar/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { DevToolbarApp } from "astro";
|
|
2
|
+
|
|
3
|
+
//#region src/toolbar/index.d.ts
|
|
4
|
+
declare const app: DevToolbarApp;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { app as default };
|
|
3
7
|
//# sourceMappingURL=index.d.ts.map
|