Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_assets folder missing #13

Open
KolyaKorruptis opened this issue Apr 29, 2022 · 7 comments
Open

_assets folder missing #13

KolyaKorruptis opened this issue Apr 29, 2022 · 7 comments

Comments

@KolyaKorruptis
Copy link

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

@andyhuai
Copy link

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

@djangelic
Copy link

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
Copy link

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!

@korbinZhang
Copy link

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
Copy link

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

@djangelic
Copy link

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

@fintechworker
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants