You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
blogcontent/blog/content/posts/page-source-link.md

2.9 KiB

title date tags
Page Source Link 2022-05-30T21:22:04-07:00 [meta]

I just added a page-source link to my blog setup.

You can see how it was done in the commit that introduced this blog post (just click the "Page Source" link that should be present in the header for this article!):

  • Hugo supports setting site-wide variables in config files, and suppors accessing information about the file that generated a give post with the File object. By setting a site-wide variable that points at the base of my Git repo in my self-hosted Gitea instance, both of these pieces of information can be used at build-time to generate a page-specific URL to inject into the built page.
  • I had to copy-in and overwrite the layouts/_default/single.html file from the theme I'm using (Ananke), because the aforementioned information is only available at build-time. If I'd have tried to inject this information by editing the page at view-time (with a Javascript file, as I've done elsewhere with simpler styling changes), the information wouldn't have been available.
    • OK, technically I could probably have inserted both of those information pieces into the page in hidden elements, and then used Javascript to retrieve them and construct the URL, but why not do it directly at build-time?
    • The lines you're interested in are lines 50-52 of the file (at the time of first-commit - man, it's awkward that I can't add a link to a commit that hasn't been created yet, huh!?) - everything else is just a copy-paste of the existing layout from Ananke.
  • The {{with}} function is a pretty neat way to do "check if X exists, and use it in-scope if so; else, skip the scope below".
  • Note that I am not linking directly to the root of the repo in page_source_base (https://gitea.scubbo.org/scubbo/blogContent/src/branch/main/blog/), but to a subfolder (blog/) within it. This is because I have my Hugo source in a subfolder within the repo, so that other configuration files (Dockerfile, CI/CD configuration, .gitignore, etc.) can live in the root and the source can be kept clean and separate.

Keen readers will notice I haven't discussed the Gitea instance before. I've significantly revamped my setup recently, with Git hosting, CI/CD pipeline with Drone, and deployment to a Kubernetes cluster, all self-hosted. I've been putting off a sequel to [the "self-hosting blog" post]({{< ref "/posts/self-hosting-blog" >}}) describing the process, but it's probably past-due by now!