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

Migrate to Hugo #23

Merged
merged 10 commits into from
Mar 8, 2025
Merged

Migrate to Hugo #23

merged 10 commits into from
Mar 8, 2025

Conversation

dscho
Copy link
Member

@dscho dscho commented Mar 8, 2025

Rather than trying to continue running something home-grown, let's switch to a proper static site generator.

This partially addresses some concerns I raised after integrating the wiki pages and the problems we ran into when the workflow to update the HTML pages failed in a PR by a contributor: While it still does not offer convenient before/after views, it at least allows to preview the changes in a fork, just like this here PR can be previewed at https://dscho.github.io/gitgitgadget.github.io/

So why even bother with a powerful site generator like Hugo for something as small as GitGitGadget's home page? Well, here are a couple of reasons:

  • As you can see https://dscho.github.io/gitgitgadget.github.io/architecture, it re-adds the syntax highlighting in code blocks that were lost in the transition away from the wiki.
  • It will make auto-generating a navigation bar (or a central index page) much easier.
  • It will make it easier to maintain a unified look-and-feel, e.g. when adding something like an "Edit on GitHub" button.
  • It should make it somewhat easier to make the site responsive because of a much more standard way to build the site.
  • The migration of the wiki pages was meant as a blueprint I could follow in Git for Windows, where I want to stop wasting my time battling spam and vandalism, and any subsequent work over here that can help with that can increase the synergy between both projects.

dscho added 10 commits March 8, 2025 10:58
As I found out the hard way, it is quite the challenge to keep the HTML
pages up to date when the source of truth is in newly-added Markdown
files.

The simple reason for this is that generated files should not need to be
committed. Instead, I would like to use Hugo (https://gohugo.io/) to
render the HTML pages on the fly while deploying to GitHub Pages.

Side note: The paved path on GitHub is to use Jekyll, see
https://docs.github.com/en/pages/setting-up-a-github-pages-site-with-jekyll/about-github-pages-and-jekyll

However, I found out that Jekyll is really, really slow (probably
because Ruby is really, really slow) and I do not want to waste
resources like that. If the migration of https://git-scm.com/ to a
static site generator is any indicator, we are talking about 2-3 orders
of magnitude here, so it's really no laughing matter.

Unfortunately, since GitHub sees unfit to support a better paved path,
this means that we will have to cobble together advice from
https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#creating-a-custom-github-actions-workflow-to-publish-your-site
and from https://gohugo.io/host-and-deploy/host-on-github-pages/ to use
this, but the good news is that I went through all of those steps in the
migration of https://git-scm.com/ and can put that experience to good
use here, too.

So here is the first step: drop the automation that tries to support the
original way to build GitGitGadget's home page.

Signed-off-by: Johannes Schindelin <[email protected]>
Right now, GitGitGadget's HTML pages are built using `grunt`, and the
result is then committed and uploaded to GitHub Pages.

However, a much more natural development experience can be achieved by
using Hugo (https://gohugo.io/) instead.

In preparation for migrating to Hugo, let's drop all `grunt`-based
stuff.

Signed-off-by: Johannes Schindelin <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
Hugo has a bit of an opinionated directory layout, at least on its paved
path.

Signed-off-by: Johannes Schindelin <[email protected]>
While at it, convert it to Markdown.

Signed-off-by: Johannes Schindelin <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
They have a slightly different style, in particular the banner.

Signed-off-by: Johannes Schindelin <[email protected]>
This finishes the transition to a Hugo-backed site.

Signed-off-by: Johannes Schindelin <[email protected]>
@dscho dscho self-assigned this Mar 8, 2025
@dscho
Copy link
Member Author

dscho commented Mar 8, 2025

For the record, I present the before/after views here: e463157

EDIT: Here is the table (without the nice Swipe/Onion Skin views, though, for that, you need to navigate to above-mentioned commit):

Before After
architecture (before) architecture (after)
index (before) index (after)
reply-to-this (before) reply-to-this (after)

@dscho dscho merged commit 51f928c into gitgitgadget:main Mar 8, 2025
1 check passed
@dscho dscho deleted the hugo branch March 8, 2025 13:47
@dscho
Copy link
Member Author

dscho commented Mar 8, 2025

For the record, I used Playwright to generate these screenshots, using this take-screenshot.js script:

import { chromium } from 'playwright'

(async () => {
  const [ url, path ] = process.argv.slice(2)
  if (!url) throw new Error(`Need a URL!`)
  if (!path) throw new Error('Need a path to save to!')

  // Or 'firefox' or 'webkit'.
  const browser = await chromium.launch()
  // use this in GitHub Actions to avoid having to download the headless browser;
  // you still have to run `npm install -g playwright` first, of course:
  // const browser = await chromium.launch({ channel: 'chrome' })
  const page = await browser.newPage()
  await page.goto(url)
  await page.screenshot({ path, fullPage: true })
  await browser.close()
})().catch(e => { throw e })

in a loop:

for page in index architecture reply-to-this
do
  node ../take-screenshot.js https://gitgitgadget.github.io/$page.html $page.png
done

in a worktree that was newly created via git worktree add --orphan screenshots, then committing the images, then running the loop again with the base URL set to file:///path/to/public/, then committing again and then I published the commit via git push origin HEAD:refs/screenshots/pr-23

This should all be easy to automate, in case we want to have this for future PRs.

One way to automate this would be via a new GitHub workflow that

  • triggers on workflow_dispatch
  • takes the PR number as input (and potentially a list of pages, but it could determine them from the PR diff by default)
  • pushes to refs/screenshots/pr-<number>-<timestamp> to avoid naming clashes
  • downloads the PR build's pages artifact and uses that to compare against the current version at https://gitgitgadget.github.io/

This would of course then also be neat to have in Git for Windows, once https://github.com/git-for-windows/git-for-windows.github.io is converted to Hugo, and it would obviously also be neat to have in https://github.com/git/git-scm.com/, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant