joplin-plugin-pages-publisher icon indicating copy to clipboard operation
joplin-plugin-pages-publisher copied to clipboard

_assets folder missing

Open KolyaKorruptis opened this issue 2 years ago • 7 comments

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

KolyaKorruptis avatar Apr 29 '22 23:04 KolyaKorruptis

U shoud use xx.github.io , the folder published, but the url is not right

andyhuai avatar Jul 25 '22 12:07 andyhuai

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.

djangelic avatar Sep 05 '23 00:09 djangelic

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.

  1. 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.
  2. From there place your _assets directory in the output directory: /ylc395.pagesPublisher/output/_assets .
  3. 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!

djangelic avatar Nov 23 '23 04:11 djangelic

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.

korbinZhang avatar Jan 06 '24 13:01 korbinZhang

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')),
     });
   }

korbinZhang avatar Jan 06 '24 14:01 korbinZhang

I deployed your fix in my environment and confirm it works! Thank you so much! You're a genius @FreyZhang001 !

djangelic avatar Jan 09 '24 16:01 djangelic

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?

fintechworker avatar Feb 20 '24 06:02 fintechworker