christophengelmayer Posted January 17, 2020 Share Posted January 17, 2020 Hi everyone, Introducing my first module https://github.com/christophengelmayer/StaticWire It's a simple way to convert your ProcessWire site to static HTML files via CLI or the admin interface. Useful in CI/CD scripts or to use ProcessWire as a simple static site generator. 17 Link to comment Share on other sites More sharing options...
christophengelmayer Posted January 17, 2020 Author Share Posted January 17, 2020 https://modules.processwire.com/modules/static-wire/ 1 1 Link to comment Share on other sites More sharing options...
matjazp Posted January 17, 2020 Share Posted January 17, 2020 Thanks for the module! After installing it, I get this warning when editing a page: 1× 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 More sharing options...
d'Hinnisdaël Posted January 17, 2020 Share Posted January 17, 2020 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 More sharing options...
christophengelmayer Posted January 17, 2020 Author Share Posted January 17, 2020 28 minutes ago, matjazp said: Thanks for the module! After installing it, I get this warning when editing a page: 1× 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 More sharing options...
christophengelmayer Posted January 17, 2020 Author Share Posted January 17, 2020 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 More sharing options...
matjazp Posted January 18, 2020 Share Posted January 18, 2020 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 More sharing options...
matjazp Posted January 18, 2020 Share Posted January 18, 2020 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. Link to comment Share on other sites More sharing options...
christophengelmayer Posted January 18, 2020 Author Share Posted January 18, 2020 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. 1 Link to comment Share on other sites More sharing options...
matjazp Posted January 18, 2020 Share Posted January 18, 2020 I changed namespace to ProcessWire and the error while editing a template is gone. The problem with page->render is still there, of course. Link to comment Share on other sites More sharing options...
teppo Posted January 18, 2020 Share Posted January 18, 2020 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. 2 Link to comment Share on other sites More sharing options...
wbmnfktr Posted January 18, 2020 Share Posted January 18, 2020 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? Link to comment Share on other sites More sharing options...
matjazp Posted January 18, 2020 Share Posted January 18, 2020 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. 1 Link to comment Share on other sites More sharing options...
christophengelmayer Posted January 18, 2020 Author Share Posted January 18, 2020 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 More sharing options...
dragan Posted January 18, 2020 Share Posted January 18, 2020 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 More sharing options...
matjazp Posted January 22, 2020 Share Posted January 22, 2020 On 1/17/2020 at 9:07 PM, matjazp said: After installing it, I get this warning when editing a page: 1× 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). Link to comment Share on other sites More sharing options...
christophengelmayer Posted January 22, 2020 Author Share Posted January 22, 2020 @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. Link to comment Share on other sites More sharing options...
matjazp Posted January 22, 2020 Share Posted January 22, 2020 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. Link to comment Share on other sites More sharing options...
matjazp Posted January 24, 2020 Share Posted January 24, 2020 @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 More sharing options...
christophengelmayer Posted January 27, 2020 Author Share Posted January 27, 2020 Just pushed version 0.0.5 to GitHub. I changed the namespace to "ProcessWire". @matjazp Thanks for the hint. Link to comment Share on other sites More sharing options...
pmichaelis Posted February 22, 2021 Share Posted February 22, 2021 Hi, i wanted to test the module. Is there still a namespacing issue? Error: Class 'ProcessWire\HtmlExporter' not found in /home/vagrant/web/pw-static/web/site/modules/StaticWire/StaticWire.module.php on line 41 thanks for help Link to comment Share on other sites More sharing options...
christophengelmayer Posted May 18, 2021 Author Share Posted May 18, 2021 @pmichaelis I just released version 0.0.6 which fixes the "Class not found" issue. https://github.com/christophengelmayer/StaticWire 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now