Skip to content

Commit b5362a6

Browse files
committed
feat: add image loader plugin to docusaurus
1 parent 50391e1 commit b5362a6

File tree

4 files changed

+157
-4
lines changed

4 files changed

+157
-4
lines changed

docusaurus.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ async function createConfig() {
5353
baseUrl: '/',
5454

5555
plugins: [
56+
function generateImagesPlugin(context) {
57+
return {
58+
name: 'generate-images-plugin',
59+
async loadContent() {
60+
const { imageLoader } = await import('./imageLoader.js');
61+
await imageLoader(context.siteDir);
62+
},
63+
};
64+
},
5665
demoLoaderPlugin,
5766
[
5867
'@dipakparmar/docusaurus-plugin-umami',

imageLoader.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const fs = require('fs');
22
const imageJs = require('image-js');
33
const { fetchURL } = require('image-js');
4+
require('ts-node/register');
45
const {
56
defaultImages,
67
defaultMasks,
78
} = require('./src/demo/contexts/demo/defaultImages');
89

910
async function imageLoader(siteDir) {
1011
const imageData = [];
11-
const path = './static/';
1212
for (let imageDataUrl of defaultImages) {
1313
const image = await fetchURL(imageDataUrl.value);
1414
const imageTitle = imageDataUrl.value.slice(
@@ -45,13 +45,11 @@ async function imageLoader(siteDir) {
4545
}
4646

4747
// Use absolute path
48-
const outputPath = siteDir.concat('static/imageData.json');
48+
const outputPath = siteDir.concat('/static/imageData.json');
4949
fs.writeFileSync(outputPath, JSON.stringify(imageData, null, 2));
5050

5151
console.log('Image data saved to:', outputPath);
5252
return imageData;
5353
}
5454

55-
imageLoader('/Users/maxim/git/zakodium/image-js-docs/');
56-
5755
module.exports = { imageLoader };

package-lock.json

Lines changed: 145 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"eslint-config-zakodium": "^16.0.0",
5050
"prettier": "^3.6.2",
5151
"raw-loader": "^4.0.2",
52+
"ts-node": "^10.9.2",
5253
"typescript": "^5.9.2"
5354
},
5455
"browserslist": {

0 commit comments

Comments
 (0)