mirror of
https://github.com/wavetermdev/docusaurus-og.git
synced 2026-08-05 13:46:35 -07:00
Add status logging
Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com>
This commit is contained in:
@@ -5,6 +5,8 @@ const tslib_1 = require("tslib");
|
||||
const fs = tslib_1.__importStar(require("fs"));
|
||||
const path = tslib_1.__importStar(require("path"));
|
||||
const document_1 = require("./document");
|
||||
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
||||
const progress = tslib_1.__importStar(require("./progress"));
|
||||
class BlogPlugin {
|
||||
context;
|
||||
options;
|
||||
@@ -83,11 +85,17 @@ class BlogPlugin {
|
||||
}
|
||||
};
|
||||
generate = async () => {
|
||||
logger_1.default.info(`Generating og images for ${this.pages.length} blog pages`);
|
||||
const bar = progress.defaultBar();
|
||||
bar.start(this.pages.length, 0, { prefix: 'rendering images', suffix: '-' });
|
||||
for (const page of this.pages) {
|
||||
const document = new document_1.Document(this.getHtmlPath(page.permalink));
|
||||
bar.update({ suffix: page.permalink });
|
||||
await document.load();
|
||||
if (!document.loaded)
|
||||
if (!document.loaded) {
|
||||
bar.increment();
|
||||
continue;
|
||||
}
|
||||
const image = await this.imageRenderer({
|
||||
...page,
|
||||
document,
|
||||
@@ -95,12 +103,16 @@ class BlogPlugin {
|
||||
}, this.context);
|
||||
if (!image) {
|
||||
await document.write();
|
||||
bar.increment();
|
||||
continue;
|
||||
}
|
||||
const generated = await this.imageGenerator.generate(...image);
|
||||
await document.setImage(generated.url);
|
||||
await document.write();
|
||||
bar.increment();
|
||||
}
|
||||
bar.stop();
|
||||
logger_1.default.success('Generated og images for blog pages');
|
||||
};
|
||||
getHtmlPath = (permalink, baseUrl) => path.join(this.context.outDir, permalink, 'index.html');
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ exports.DocsPlugin = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const path = tslib_1.__importStar(require("path"));
|
||||
const document_1 = require("./document");
|
||||
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
||||
const progress = tslib_1.__importStar(require("./progress"));
|
||||
class DocsPlugin {
|
||||
context;
|
||||
options;
|
||||
@@ -44,8 +46,12 @@ class DocsPlugin {
|
||||
})));
|
||||
};
|
||||
generate = async () => {
|
||||
logger_1.default.info(`Generating og images for ${this.docs.length} docs pages`);
|
||||
const bar = progress.defaultBar();
|
||||
bar.start(this.docs.length, 0, { prefix: 'rendering images', suffix: '-' });
|
||||
for (const doc of this.docs) {
|
||||
const document = new document_1.Document(this.getHtmlPath(doc));
|
||||
bar.update({ suffix: doc.metadata.permalink });
|
||||
await document.load();
|
||||
const image = await this.imageRenderer({
|
||||
...doc,
|
||||
@@ -54,12 +60,16 @@ class DocsPlugin {
|
||||
}, this.context);
|
||||
if (!image) {
|
||||
await document.write();
|
||||
bar.increment();
|
||||
continue;
|
||||
}
|
||||
const generated = await this.imageGenerator.generate(...image);
|
||||
await document.setImage(generated.url);
|
||||
await document.write();
|
||||
bar.increment();
|
||||
}
|
||||
bar.stop();
|
||||
logger_1.default.success('Generated og images for docs pages');
|
||||
};
|
||||
getHtmlPath = (doc) =>
|
||||
// slug is used here instead of permalink because permalink already contains version and locale paths of websiteOutDir
|
||||
|
||||
@@ -4,6 +4,8 @@ exports.PagesPlugin = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const path = tslib_1.__importStar(require("path"));
|
||||
const document_1 = require("./document");
|
||||
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
||||
const progress = tslib_1.__importStar(require("./progress"));
|
||||
class PagesPlugin {
|
||||
context;
|
||||
options;
|
||||
@@ -50,11 +52,17 @@ class PagesPlugin {
|
||||
}
|
||||
};
|
||||
generate = async () => {
|
||||
logger_1.default.info(`Generating og images for ${this.pages.length} pages`);
|
||||
const bar = progress.defaultBar();
|
||||
bar.start(this.pages.length, 0, { prefix: 'rendering images', suffix: '-' });
|
||||
for (const page of this.pages) {
|
||||
const document = new document_1.Document(this.getHtmlPath(page.metadata.permalink));
|
||||
bar.update({ suffix: page.metadata.permalink });
|
||||
await document.load();
|
||||
if (!document.loaded)
|
||||
if (!document.loaded) {
|
||||
bar.increment();
|
||||
continue;
|
||||
}
|
||||
const image = await this.imageRenderer({
|
||||
...page,
|
||||
document,
|
||||
@@ -62,12 +70,16 @@ class PagesPlugin {
|
||||
}, this.context);
|
||||
if (!image) {
|
||||
await document.write();
|
||||
bar.increment();
|
||||
continue;
|
||||
}
|
||||
const generated = await this.imageGenerator.generate(...image);
|
||||
await document.setImage(generated.url);
|
||||
await document.write();
|
||||
bar.increment();
|
||||
}
|
||||
bar.stop();
|
||||
logger_1.default.success('Generated og images for pages');
|
||||
};
|
||||
getHtmlPath = (permalink) => path.join(this.context.outDir, permalink, 'index.html');
|
||||
}
|
||||
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
import cliProgress from 'cli-progress';
|
||||
export declare function defaultBar(): cliProgress.SingleBar;
|
||||
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.defaultBar = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const cli_progress_1 = tslib_1.__importDefault(require("cli-progress"));
|
||||
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
||||
const figures_1 = tslib_1.__importDefault(require("figures"));
|
||||
function defaultBar() {
|
||||
return new cli_progress_1.default.SingleBar({
|
||||
format: chalk_1.default.green(figures_1.default.bullet) + chalk_1.default.green(' og images ') + '{bar}' + chalk_1.default.white(' {prefix} ({percentage}%) ') + chalk_1.default.grey('{value}/{total}\n') + chalk_1.default.grey('{suffix}'),
|
||||
barCompleteChar: chalk_1.default.green('█'),
|
||||
barIncompleteChar: chalk_1.default.white('█'),
|
||||
hideCursor: true
|
||||
});
|
||||
}
|
||||
exports.defaultBar = defaultBar;
|
||||
;
|
||||
Reference in New Issue
Block a user