Jump to content
christophengelmayer

StaticWire - Covert pages to static HTML

Recommended Posts

Thanks for the module!

After installing it, I get this warning when editing a page:

PHP Warning: class_parents(): Class ProcessWire\StaticWire does not exist and could not be loaded in C:\inetpub\wwwroot\wire\core\Functions.php:955
 
The odd thing is that it happens only on one template and I can't figure it out what could be wrong with that particular template... 

Share this post


Link to post
Share on other sites

Very nice! Love the idea. I'd like to try this out, but I think this will only make sense for production environments if the static copy is completely self-contained, i.e. including paginated pages, assets, etc. You could probably easily do that using wget and some command line magic. Your module would then make the whole process configurable and user-friendly, e.g. to run it via cron, via hook after page save, etc.

Example gist: Download an entire website with wget, along with assets

Share this post


Link to post
Share on other sites
28 minutes ago, matjazp said:

Thanks for the module!

After installing it, I get this warning when editing a page:


PHP Warning: class_parents(): Class ProcessWire\StaticWire does not exist and could not be loaded in C:\inetpub\wwwroot\wire\core\Functions.php:955
 
The odd thing is that it happens only on one template and I can't figure it out what could be wrong with that particular template... 

It happens when editing the page, not exporting?

Can you post the template code, looks like some Namespace issue.

Share this post


Link to post
Share on other sites
20 minutes ago, d'Hinnisdaël said:

Very nice! Love the idea. I'd like to try this out, but I think this will only make sense for production environments if the static copy is completely self-contained, i.e. including paginated pages, assets, etc. You could probably easily do that using wget and some command line magic. Your module would then make the whole process configurable and user-friendly, e.g. to run it via cron, via hook after page save, etc.

Example gist: Download an entire website with wget, along with assets

Thank you.

It definitely makes sense for a production environment where, for example, processwire runs on its own (hidden or whitelisted) domain.

I‘m also thinking about using it as a backup tool or just a local tool for editing content and exporting static sites.

I‘ve used wget to create static sites before but it always involves a lot of manual editing to correct urls and asset paths.

So I came up with the idea to use PW to directly render pages to html.

Currently I‘m thinking about a solution to also render paginated pages.

Share this post


Link to post
Share on other sites
10 hours ago, christophengelmayer said:

It happens when editing the page, not exporting?

Yes.

10 hours ago, christophengelmayer said:

Can you post the template code, looks like some Namespace issue.

<?php namespace ProcessWire;

echo "basic-page template";

That's it! It must be something on my installation...

On the other hand i just found out that if you use functions in a template, like this:

function foo() { }

and the try to generate, you get:

Quote

ERROR: Cannot redeclare ProcessWire\foo() (previously declared in C:\inetpub\wwwroot\site\templates\basic-page.php:5) on line: 5 in C:\inetpub\wwwroot\site\templates\basic-page.php

This is not a problem with your module but rather with page->render() method... 

Share this post


Link to post
Share on other sites

I just cloned my basic-page template and now the error is gone... Oh my, have no idea what could be wrong with my template.

Share this post


Link to post
Share on other sites

I just relased an update (0.0.5) which maybe fixes this issue.

The problem was, that the module also tried to export the admin pages. This is now prevented.

I tested it with the demo site packages (beginner, blank, classic, default, languages, regular) and it worked on all of them.

  • Like 1

Share this post


Link to post
Share on other sites

I changed namespace to ProcessWire and the error while editing a template is gone. The problem with page->render is still there, of course.

Share this post


Link to post
Share on other sites
6 hours ago, matjazp said:

This is not a problem with your module but rather with page->render() method... 

I wouldn't really call this a problem, though 🙂

Page::render() is not an isolated process, and this is by design. If you define functions in template files – or files you potentially include multiple times – you should always wrap them in "if (!function_exists('your-function') { ... }". Or, alternatively, split them into a separate file that gets included only once per execution with include_once or require_once.

  • Like 1

Share this post


Link to post
Share on other sites

Sad to say but I have not that much time to test this the next few days... so I have to ask:

How nice does StaticWire play with ProCache?
Will I export the ProCached-version of my pages - including compiled CSS and JS, minified HTML?

Share this post


Link to post
Share on other sites
1 hour ago, teppo said:

Or, alternatively, split them into a separate file that gets included only once per execution with include_once or require_once.

 @teppo, that's what I do on my production sites. But on test environment, I try a lot of things and so there are some "test functions" just lying around... That's why I said that this is not a problem of the module (or the author of the module). But yes, the word "problem" is not quite adequate, thank you for the clarification.

  • Like 1

Share this post


Link to post
Share on other sites
59 minutes ago, wbmnfktr said:

How nice does StaticWire play with ProCache?

If you use ProCache you don't need StaticWire (imho).

StaticWire is built for a different usecase.

59 minutes ago, wbmnfktr said:

Will I export the ProCached-version of my pages - including compiled CSS and JS, minified HTML?

The Plugin (currently) does not export any assets.
It basically iterates over all pages, calls the render() function and stores the output in an index.html file in a folder that matches the pages URL.
You have to take care of the needed assets by yourself.

Share this post


Link to post
Share on other sites

I just installed the module (though it's still at version 4, according to module info) and after trying to run it, I just get:

The process returned no content.

ProcessWire: 3.0.148
PHP: 7.3.13
Webserver: Apache/2.4.35 (Win64) OpenSSL/1.1.1b (Laragon)
MySQL: 5.7.24

Could this be a Windows issue? Do I have to enable special PHP extensions first?

Nothing in Apache or PHP error logs.

The strangest thing is: The page title says "Form Builder". (?)

OK, after unpublishing the Form Builder page, I get a static version alright.

I was a bit puzzled though that each parent page is actually a folder in the static version.

Going to play around a bit more. Thanks for sharing this module!

Share this post


Link to post
Share on other sites
On 1/17/2020 at 9:07 PM, matjazp said:

After installing it, I get this warning when editing a page:


PHP Warning: class_parents(): Class ProcessWire\StaticWire does not exist and could not be loaded in C:\inetpub\wwwroot\wire\core\Functions.php:955
 
The odd thing is that it happens only on one template and I can't figure it out what could be wrong with that particular template... 

I found out that this warning pops up if you edit a field admin_theme (and I have admin_theme field on that template).  

admin_theme_error.png

Share this post


Link to post
Share on other sites

@matjazp I'm not familiar with fields of type "Module Reference". Which FieldType do they use?

Could you describe how to create a template that reproduce this issue.
Or can you share the site package for this project.

I'd like to look into this issue.

Share this post


Link to post
Share on other sites

Just edit your profile, it has system field admin_theme, and the error is there... It really bothers me as I don't know what could be wrong.

 

image.png

Share this post


Link to post
Share on other sites

@christophengelmayerThis was a bug in PW core, but it's fixed in 3.0.150.

But Ryan recommends: "it's good to have a module in the ProcessWire namespace, since module names must already be unique." So, I currently see no benefit having your own namespace and recommend you change it to ProcessWire (or have no namespace if you want your module to be compatible with PW 2).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...