@soonit/rspress-plugin-og 0.0.2 → 0.0.5
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/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import { t as Options } from "./types-
|
|
2
|
-
import
|
|
3
|
-
import { PageIndexInfo } from "@rspress/core";
|
|
1
|
+
import { t as Options } from "./types-R_GC9oNb.mjs";
|
|
2
|
+
import { RspressPlugin } from "@rspress/core";
|
|
4
3
|
|
|
5
4
|
//#region src/index.d.ts
|
|
6
|
-
declare function export_default(userOptions: Options):
|
|
7
|
-
name: string;
|
|
8
|
-
config(config: _rspress_core0.UserConfig): _rspress_core0.UserConfig;
|
|
9
|
-
extendPageData: (pageData: PageIndexInfo) => void;
|
|
10
|
-
afterBuild(config: _rspress_core0.UserConfig): Promise<void>;
|
|
11
|
-
};
|
|
5
|
+
declare function export_default(userOptions: Options): RspressPlugin;
|
|
12
6
|
//#endregion
|
|
13
7
|
export { export_default as default };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { dirname, join, relative } from "node:path";
|
|
2
|
+
import { performance } from "node:perf_hooks";
|
|
2
3
|
import node_process, { cwd } from "node:process";
|
|
3
|
-
import { Buffer } from "node:buffer";
|
|
4
4
|
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
5
|
-
import
|
|
5
|
+
import { writeFile } from "node:fs/promises";
|
|
6
|
+
import { Resvg } from "@resvg/resvg-js";
|
|
6
7
|
import node_os from "node:os";
|
|
7
8
|
import node_tty from "node:tty";
|
|
8
9
|
import { joinURL } from "ufo";
|
|
@@ -119,8 +120,13 @@ async function generateOgImage({ title }, output, options) {
|
|
|
119
120
|
line2: lines[1] ? escapeHtml(lines[1]) : "",
|
|
120
121
|
line3: lines[2] ? escapeHtml(lines[2]) : ""
|
|
121
122
|
};
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
await writeFile(output, new Resvg(ogTemplate.replace(/\{\{([^}]+)\}\}/g, (_, name) => data[name] || ""), {
|
|
124
|
+
fitTo: {
|
|
125
|
+
mode: "width",
|
|
126
|
+
value: 1200
|
|
127
|
+
},
|
|
128
|
+
...options.resvgOptions
|
|
129
|
+
}).render().asPng());
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
//#endregion
|
|
@@ -377,15 +383,17 @@ let src_logger = createLogger();
|
|
|
377
383
|
|
|
378
384
|
//#endregion
|
|
379
385
|
//#region src/options.ts
|
|
380
|
-
function resolveOptions(userOptions) {
|
|
381
|
-
|
|
386
|
+
async function resolveOptions(userOptions) {
|
|
387
|
+
const options = {
|
|
382
388
|
domain: "",
|
|
383
389
|
outDir: "og",
|
|
384
390
|
ogTemplate: "og-template.svg",
|
|
385
391
|
maxTitleSizePerLine: 30,
|
|
386
|
-
|
|
392
|
+
resvgOptions: void 0,
|
|
387
393
|
...userOptions
|
|
388
394
|
};
|
|
395
|
+
if (typeof options.resvgOptions === "function") options.resvgOptions = await options.resvgOptions();
|
|
396
|
+
return options;
|
|
389
397
|
}
|
|
390
398
|
|
|
391
399
|
//#endregion
|
|
@@ -393,7 +401,7 @@ function resolveOptions(userOptions) {
|
|
|
393
401
|
const NAME = "rspress-plugin-og";
|
|
394
402
|
const LOG_PREFIX = `[${NAME}]`;
|
|
395
403
|
function src_default(userOptions) {
|
|
396
|
-
|
|
404
|
+
let options;
|
|
397
405
|
const images = /* @__PURE__ */ new Map();
|
|
398
406
|
const headCreators = [
|
|
399
407
|
(url) => createTwitterImageHead(url),
|
|
@@ -405,7 +413,8 @@ function src_default(userOptions) {
|
|
|
405
413
|
];
|
|
406
414
|
return {
|
|
407
415
|
name: NAME,
|
|
408
|
-
config(config) {
|
|
416
|
+
async config(config) {
|
|
417
|
+
options = await resolveOptions(userOptions);
|
|
409
418
|
config.head = [...config.head || [], ...headCreators.map((creator) => (route) => {
|
|
410
419
|
const imageInfo = images.get(route.routePath);
|
|
411
420
|
if (!imageInfo) return;
|
|
@@ -428,10 +437,12 @@ function src_default(userOptions) {
|
|
|
428
437
|
async afterBuild(config) {
|
|
429
438
|
const outputFolder = join(cwd(), config.outDir ?? "doc_build", options.outDir);
|
|
430
439
|
src_logger.info(`${LOG_PREFIX} Generating OG images to ${relative(cwd(), outputFolder)} ...`);
|
|
440
|
+
const start = performance.now();
|
|
431
441
|
await Promise.all(Array.from(images.entries()).map(([_, { title, imageName }]) => {
|
|
432
442
|
return generateOgImage({ title }, join(outputFolder, imageName), options);
|
|
433
443
|
}));
|
|
434
|
-
|
|
444
|
+
const duration = (performance.now() - start) / 1e3;
|
|
445
|
+
src_logger.success(`${LOG_PREFIX} ${images.size} OG images generated in ${duration.toFixed(2)}s.`);
|
|
435
446
|
}
|
|
436
447
|
};
|
|
437
448
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ResvgRenderOptions } from "@resvg/resvg-js";
|
|
2
2
|
|
|
3
3
|
//#region ../core/src/types.d.ts
|
|
4
4
|
interface Options {
|
|
@@ -26,13 +26,13 @@ interface Options {
|
|
|
26
26
|
*/
|
|
27
27
|
ogTemplate?: string;
|
|
28
28
|
/**
|
|
29
|
-
* Options
|
|
30
|
-
*
|
|
31
|
-
* @default {}
|
|
29
|
+
* Options for resvg rendering
|
|
32
30
|
*/
|
|
33
|
-
|
|
31
|
+
resvgOptions?: ResvgRenderOptions | (() => Promise<ResvgRenderOptions>);
|
|
32
|
+
}
|
|
33
|
+
interface ResolvedOptions extends Required<Omit<Options, 'resvgOptions'>> {
|
|
34
|
+
resvgOptions?: ResvgRenderOptions;
|
|
34
35
|
}
|
|
35
|
-
interface ResolvedOptions extends Required<Options> {}
|
|
36
36
|
//#endregion
|
|
37
37
|
//#region src/types.d.ts
|
|
38
38
|
interface Options$1 extends Options {}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as ResolvedOptions, t as Options } from "./types-
|
|
1
|
+
import { n as ResolvedOptions, t as Options } from "./types-R_GC9oNb.mjs";
|
|
2
2
|
export { Options, ResolvedOptions };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonit/rspress-plugin-og",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"description": "Automatically generate Open Graph images for your Rspress pages.",
|
|
6
6
|
"author": "Estéban Soubiran <esteban@soubiran.dev>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -11,9 +11,6 @@
|
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/Barbapapazes/vitepress-plugin-og"
|
|
13
13
|
},
|
|
14
|
-
"publishConfig": {
|
|
15
|
-
"access": "public"
|
|
16
|
-
},
|
|
17
14
|
"bugs": "https://github.com/Barbapapazes/vitepress-plugin-og/issues",
|
|
18
15
|
"exports": {
|
|
19
16
|
".": {
|
|
@@ -38,7 +35,7 @@
|
|
|
38
35
|
"@rspress/core": "^2.0.0-rc.1 || ^2.0.0"
|
|
39
36
|
},
|
|
40
37
|
"dependencies": {
|
|
41
|
-
"
|
|
38
|
+
"@resvg/resvg-js": "^2.6.2",
|
|
42
39
|
"ufo": "^1.6.1"
|
|
43
40
|
},
|
|
44
41
|
"devDependencies": {
|