Jump to content

StaticWire - Covert pages to static HTML


christophengelmayer
 Share

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... 
Link to comment
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

Link to comment
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.

Link to comment
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.

Link to comment
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... 

Link to comment
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
Link to comment
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
Link to comment
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.

Link to comment
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!

Link to comment
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

Link to comment
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).

Link to comment
Share on other sites

  • 1 year later...
  • 2 months later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...