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

Static site generation #48

Merged
merged 14 commits into from
Apr 17, 2024
Merged

Static site generation #48

merged 14 commits into from
Apr 17, 2024

Conversation

adamziel
Copy link
Owner

@adamziel adamziel commented Apr 17, 2024

Supports rendering the documentation site as a set of static HTML, JS, CSS, etc files.

How does it work?

  1. The JavaScript crawler requests /logout/ to, well, log out.
  2. The /sitemap/ endpoint returns a list of all Posts with post_type=page and their URLs
  3. A JavaScript crawler requests each of those pages and writes the rendered HTML to the out directory
  4. All full-qualified site URLs are replaced with an absolute path
  5. The JavaScript crawler sends a request to /zip-wp-files/ to create wp.zip with wp-includes and wp-content inside (without PHP files)
  6. The JavaScript crawler unzips wp.zip in the out directory, shipping the missing static assets

Yeah, it's weird process – that's because of wp-now's limitations.

wp-now workarounds

I had to use a few workarounds that would be better addressed in wp-now:

  • wp-now only runs a single PHP process which means PHP cannot issue a HTTP request to itself.
  • wp-now enforces a mode it deems the most appropriate and doesn't allow me to explicitly say --mode=server. However, I would just like to use it as a plain PHP server here.
  • wp-now does not support explicitly mounting specific directories. I needed to copy wp-content and wp-includes to ../out and couldn't do it because ../out isn't available in VFS. I ended up generating a zip file and unzip it with JavaScript. wp-now could either mount the entire host filesystem and expose all the directories or support a --mount=/host/path:/vfs/path flag.
  • wp-now doesn't support custom mu-plugins so I had to add a writeFile step to my Blueprint.
  • wp-now in wp-content mode expects a theme to be in place and won't apply the default WordPress theme. I had to use the installTheme step to install twentytwentyfour. The assumption seems to be that my wp-content directory is complete and contains all it needs, but I'm shipping just a subset of the files in this repo. Instead of mounting wp-content, wp-now could perhaps mount specific plugins and directories found inside wp-content.
  • wp-now forcefully logs the user in so I had to add a /logout/ endpoint and request it before starting the static site generation process.
  • wp-now doesn't kill its child processes so I had to include ps aux | grep wp-now | awk '{print $2}' | xargs kill -9 in the start-site.sh bash script.
  • wp-now creates some new files (e.g. Blueprint-installed theme) in my filessytem so I have to run git stash -u every time a site is launched. I'd either create ALL the files in the filesystem, including sqlite-database-integration, OR no files at all and keep all the changes in VFS.
  • wp-now does not activate plugins or themes via activatePlugin and activateTheme step.
  • Occasionally wp-now stops responding to requests and just hangs. There are no CLI errors visible.

These would all make good issues

cc @sejas @wojtekn

@adamziel adamziel added the enhancement New feature or request label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant