joplin-plugin-pages-publisher
joplin-plugin-pages-publisher copied to clipboard
_assets folder missing
The _assets folder is not copied to output and hence never published. Using Plugin v1.7.0 with default theme and Joplin 2.8.5
U shoud use xx.github.io , the folder published, but the url is not right
I am also having this issue as well. When I reference assets it is missing. Not sure if I am referencing the wrong location somehow or if it's a bug. Resources directory is there, and I can reference those, but not others.
Hi @KolyaKorruptis and others,
After extensive testing and reviewing the PageRenderer.ts
code in the Joplin Page Publisher plugin, it's clear that the _assets
folder from the theme directory is not being copied over to the output directory as it should. This issue stems from how the copyAssets()
method is implemented.
Here's the critical part of the code:
```javascript
private async copyAssets() {
if (!this.site || !this.themeDir || !this.outputDir || !this.outputAssetsDir) {
throw new Error('pageRenderer is not initialized');
}
const { outputAssetsDir } = this;
await fs.copy(this.themeDir, this.outputDir, {
filter: (src, dest) =>
dest === this.outputDir ||
dest.startsWith(outputAssetsDir) ||
(src.endsWith('.json') && !src.endsWith('config.json')),
});
}
The current filter logic in the copyAssets()
method does not account for the fact that the paths for the theme's _assets
directory and the output _assets
directory are fundamentally different. This results in the _assets
folder not being copied as expected.
Theme _assets Path: ylc395.pagesPublisher/themes/themename/_assets
Output _assets Path: ylc395.pagesPublisher/output/_assets
Given these distinct paths, the plugin's logic does not align the theme's _assets directory with the output directory's _assets folder.
To resolve this issue, a modification to the copyAssets()
method is necessary. We need to explicitly include a step to copy the contents of the theme's _assets directory to the output directory's _assets
folder. This adjustment ensures that the intended assets are correctly included in the final output.
- For those facing this issue, a temporary workaround is to open Joplin, then Page Publisher, and then hit Generate. That will generate your site html.
- From there place your _assets directory in the output directory:
/ylc395.pagesPublisher/output/_assets
. - From there hit the publish button in Page Publisher. That then uploads your _assets to github. If you referenced it in your EJS files it will resolve correctly.
Hope this helps!
same problem.
In windows 11.
I found outputAssetsDir
is C:/Users/user/.config/joplin-desktop/plugin-data/ylc395.pagesPublisher/output/_assets
,
but in filter, the dest
is C:\Users\user\.config\joplin-desktop\plugin-data\ylc395.pagesPublisher\output\_assets
.
so dest.startsWith(outputAssetsDir)
is false.
I fix it using path
module`.
--- a/src/driver/generator/joplinPlugin/PageRenderer.ts
+++ b/src/driver/generator/joplinPlugin/PageRenderer.ts
@@ -36,6 +36,7 @@ import {
getOutputThemeAssetsDir,
getOutputNoJekyll,
} from './pathHelper';
+import path from 'path';
ejs.fileLoader = fs.readFileSync;
@@ -362,7 +363,7 @@ export class PageRenderer {
await fs.copy(this.themeDir, this.outputDir, {
filter: (src, dest) =>
dest === this.outputDir ||
- dest.startsWith(outputAssetsDir) ||
+ path.resolve(dest).startsWith(path.resolve(outputAssetsDir)) ||
(src.endsWith('.json') && !src.endsWith('config.json')),
});
}
I deployed your fix in my environment and confirm it works! Thank you so much! You're a genius @FreyZhang001 !
I fix it using
path
module`.--- a/src/driver/generator/joplinPlugin/PageRenderer.ts +++ b/src/driver/generator/joplinPlugin/PageRenderer.ts @@ -36,6 +36,7 @@ import { getOutputThemeAssetsDir, getOutputNoJekyll, } from './pathHelper'; +import path from 'path'; ejs.fileLoader = fs.readFileSync; @@ -362,7 +363,7 @@ export class PageRenderer { await fs.copy(this.themeDir, this.outputDir, { filter: (src, dest) => dest === this.outputDir || - dest.startsWith(outputAssetsDir) || + path.resolve(dest).startsWith(path.resolve(outputAssetsDir)) || (src.endsWith('.json') && !src.endsWith('config.json')), }); }
could you package a new plugin .jpl file?