Skip to content

Commit

Permalink
ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ousttrue committed Feb 21, 2025
1 parent d7aeb51 commit e401e20
Show file tree
Hide file tree
Showing 5 changed files with 4,352 additions and 1,492 deletions.
20 changes: 20 additions & 0 deletions custom_svg_loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import fs from 'node:fs';
import path from 'node:path';

export default function loader(source) {

console.log('from-loader', this.context);

source = source.replace(/"([^"]+?\.(png|jpg))"/, (all, unquoted, ext) => {
const img_path = path.join(this.context, unquoted);
const img_content = fs.readFileSync(img_path);
if (img_content instanceof Buffer) {
return `"data:image/png;base64,${img_content.toString('base64')}"`;
}
else {
return all;
}
});

return source;
}
2 changes: 1 addition & 1 deletion custom_webpack.js → custom_webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function(context, options) {
type: 'asset/resource',
use: [
{
loader: path.resolve('custom_svg_loader.js'),
loader: path.resolve('custom_svg_loader.ts'),
options: {
/* ... */
},
Expand Down
2 changes: 1 addition & 1 deletion docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ const config: Config = {
} satisfies Preset.ThemeConfig,

plugins: [
path.resolve('./custom_webpack.js'),
path.resolve('./custom_webpack.ts'),
[
"@docusaurus/plugin-ideal-image",
{
Expand Down
Loading

0 comments on commit e401e20

Please sign in to comment.