nuxt-og-image 0.0.2 → 0.0.3

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/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "bridge": false
6
6
  },
7
7
  "configKey": "ogImage",
8
- "version": "0.0.2"
8
+ "version": "0.0.3"
9
9
  }
package/dist/module.mjs CHANGED
@@ -107,7 +107,7 @@ declare module 'nitropack' {
107
107
  name: "defineOgImage",
108
108
  from: resolve("./runtime/composables/defineOgImage")
109
109
  });
110
- addComponent({
110
+ await addComponent({
111
111
  name: "OgImage",
112
112
  filePath: resolve("./runtime/components/OgImage.vue"),
113
113
  island: true
@@ -134,7 +134,9 @@ declare module 'nitropack' {
134
134
  fileName,
135
135
  absoluteUrl,
136
136
  outputPath: `${nitro.options.output.dir}/public/${config.outputDir}/${fileName}`,
137
+ linkingHtml: ctx.fileName,
137
138
  route: ctx.route,
139
+ hasPayload: screenshotPath,
138
140
  routeRules: routeRules.ogImage || "",
139
141
  screenshotPath: screenshotPath || ctx.route
140
142
  };
@@ -164,21 +166,16 @@ declare module 'nitropack' {
164
166
  const browser = await createBrowser();
165
167
  nitro.logger.info(`Generating ${entries.length} og:image screenshots`);
166
168
  try {
167
- const imageGenPromises = entries.map(async (entry, index) => {
168
- return new Promise((resolve2) => {
169
- const start = Date.now();
170
- screenshot(browser, `${host}${entry.screenshotPath}`, config).then((imgBuffer) => {
171
- writeFile(entry.outputPath, imgBuffer).then(() => {
172
- const generateTimeMS = Date.now() - start;
173
- nitro.logger.log(chalk.gray(
174
- ` ${index === entries.length - 1 ? "\u2514\u2500" : "\u251C\u2500"} /${config.outputDir}/${entry.fileName} (${generateTimeMS}ms)`
175
- ));
176
- resolve2();
177
- });
178
- });
179
- });
180
- });
181
- await Promise.all(imageGenPromises);
169
+ for (const k in entries) {
170
+ const entry = entries[k];
171
+ const start = Date.now();
172
+ const imgBuffer = await screenshot(browser, `${host}${entry.screenshotPath}`, config);
173
+ await writeFile(entry.outputPath, imgBuffer);
174
+ const generateTimeMS = Date.now() - start;
175
+ nitro.logger.log(chalk.gray(
176
+ ` ${Number(k) === entries.length - 1 ? "\u2514\u2500" : "\u251C\u2500"} /${config.outputDir}/${entry.fileName} (${generateTimeMS}ms)`
177
+ ));
178
+ }
182
179
  } catch (e) {
183
180
  console.error(e);
184
181
  } finally {
@@ -189,12 +186,11 @@ declare module 'nitropack' {
189
186
  } finally {
190
187
  previewProcess.kill();
191
188
  }
192
- const htmlFiles = await fg(["**/*.html"], { cwd: nitro.options.output.dir });
193
- for (const htmlFile of htmlFiles) {
194
- const html = await readFile(`${nitro.options.output.dir}/${htmlFile}`, "utf-8");
189
+ for (const entry of entries.filter((e) => e.hasPayload)) {
190
+ const html = await readFile(`${nitro.options.output.dir}/public${entry.linkingHtml}`, "utf-8");
195
191
  const newHtml = html.replace(new RegExp(`<link id="${LinkPrerenderId}" rel="prerender" href="(.*?)">`), "").replace(new RegExp(`<script id="${PayloadScriptId}" type="application/json">(.*?)<\/script>`), "").replace("\n\n", "\n");
196
192
  if (html !== newHtml) {
197
- await writeFile(`${nitro.options.output.dir}/${htmlFile}`, newHtml, { encoding: "utf-8" });
193
+ await writeFile(`${nitro.options.output.dir}/public${entry.linkingHtml}`, newHtml, { encoding: "utf-8" });
198
194
  }
199
195
  }
200
196
  const ogImageFolders = await fg([`**/${HtmlRendererRoute}`], { cwd: nitro.options.output.dir, onlyDirectories: true });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-og-image",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "packageManager": "pnpm@7.8.0",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",