Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Asset folder not copied #23

Closed
0xsven opened this issue Nov 10, 2016 · 11 comments
Closed

Asset folder not copied #23

0xsven opened this issue Nov 10, 2016 · 11 comments

Comments

@0xsven
Copy link

0xsven commented Nov 10, 2016

Not sure if my config is wrong, but the assets folder is not copied to /static/assets/

I am using Kirby 2.4. Here is my config:


<?php
c::set([
	'staticbuilder'  => true,
]);

What am I doing wrong?

I have also tried a config like the following without success:

<?php
c::set([
	'staticbuilder'  => true,
	'staticbuilder.extension'  => '/index.html',
	'staticbuilder.withfiles'  => true,
	'staticbuilder.assets' => [
		'assets'
	]
]);
@fvsch
Copy link
Owner

fvsch commented Nov 13, 2016

Hi. A few questions:

  1. Which version of kirby-staticbuilder are you using? Ideally it should be 2.0.0 or 2.0.1.
  2. Was there any error message displayed? Can you turn on debug mode (c::set('debug', true) in your config.php) if it’s off, and try again?
  3. Is the assets folder listed in the "ASSETS" table in the http://yoursite/staticbuilder/ page?

By default the ASSETS table should look like this:

Directory or file   Copy target      Status
[dir] assets        static/assets    -
[dir] content       static/content   -
[dir] thumbs        static/thumbs    -

@0xsven
Copy link
Author

0xsven commented Nov 14, 2016

Hi :)

  1. I am using version: 2.0.0
  2. There was no error message displayed in the browser after building.
  3. Yes all three are displayed. After setting 'staticbuilder.assets' => ['assets'] there was only assets displayed.

@fvsch
Copy link
Owner

fvsch commented Nov 14, 2016

I can't reproduce on macOS or Windows. Is there anything special with your assets folder? A permissions issue maybe?

@0xsven
Copy link
Author

0xsven commented Nov 14, 2016

I have tried it with mamp on MacOs and inside a vagrant VM with ubuntu.

On my mac I set the folder permissions to 777.

Strange.

@fvsch
Copy link
Owner

fvsch commented Nov 14, 2016

Maybe a lead: do you know how big that folder is? How many files it has.

In particular, do you have .git or node_modules folders in your assets directories (or subdirectories)?

I haven’t stress-tested that method to be honest. I’m using the Kirby Toolkit Folder::copy method, and I’m not sure it can handle a heavy load.

If your HTML/JS code only consumes part of what is in assets, maybe only list those, e.g.

c::set('staticbuilder.assets' => [
    'assets/dist',
    'assets/fonts',
    'assets/images'
];

@0xsven
Copy link
Author

0xsven commented Nov 14, 2016

My assets folder has 42 files and a size of 2 MB. No node_modules and no .git. My content folder is bigger but even if I exclude it and only copy the assets folder it doesn't work. One test that didn't work was taking a subfolder 'assets/css' with three files in it.

Is it possible that I need to install Kirby Toolkit or something?

@fvsch
Copy link
Owner

fvsch commented Nov 14, 2016

Is it possible that I need to install Kirby Toolkit or something?

No, it’s a part of Kirby.

Can you maybe zip that folder and upload it here, if it’s not too confidential?

@eckhardEhm
Copy link

hey there, im involved in this.
we cannot share the assets but i managed to track down the problem:

the /content/error folders are not being generated, removing them from the /content directory makes the asset copy work.
I guess you can tackle it down from here sven.

It would be nice though if you would throw an exception for the folder copy with debug turned on.

Error content/error/error.en.txt static/error/index.html Not generated
Error content/error/error.de.txt static/de/error/index.html Not generated

@fvsch
Copy link
Owner

fvsch commented Nov 17, 2016

the /content/error folders are not being generated, removing them from the /content directory makes the asset copy work.

I'm not sure it's the folder copy failing here. It looks like it's a page generation that fails and halts the script, which I can't recover from. The folder copy is supposed to happen next, but if page generation halted the script then it does not go to that point.

Do you have more information on how the error page fails to build? Are you throwing an Exception, is it a PHP error, or do you call die() or exit() maybe?

It would be nice though if you would throw an exception for the folder copy with debug turned on.

I'm already displaying fatal errors, including Fatal Error: Uncaught expression, in:
https://github.com/fvsch/kirby-staticbuilder/blob/master/src/Builder.php#L559
Do you have an idea why it will not display anything in your case?

@0xsven
Copy link
Author

0xsven commented Nov 17, 2016

This makes sense! The error page I built was doing a redirect. This must have been stopped the generator.

<?php
    if ($page->redirect()) {
        go($page->redirect());
    }

In this case redirect was a value from the content. I used this to redirect to the start page.

@fvsch
Copy link
Owner

fvsch commented Nov 17, 2016

As documented in: https://github.com/fvsch/kirby-staticbuilder/blob/master/doc/static.md#http-redirections
If you use the go() function, or the underlying Kirby Toolkit method for HTTP redirects, this will break the static build because this function does a exit();, which stops the whole PHP script.

Note that you can exclude the error page if you don't use it and don't want to build it. Or maybe explicitly list the page types you want to build:

c::set('staticbuilder.filter', function($page) {
    // exclude pages that don't use one of the whitelisted templates
    if (!in_array($page->intendedTemplate(), ['page', 'post', 'blog', 'home'])) {
        return false;
    }
    // use the default logic for other pages (excludes empty folders, mostly)
    return Kirby\StaticBuilder\Builder::defaultFilter($page);
});

@fvsch fvsch closed this as completed Mar 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants