Skip to content

Commit

Permalink
Edits due to rebundling
Browse files Browse the repository at this point in the history
  • Loading branch information
brycewray committed Oct 6, 2023
1 parent c2f7957 commit 5d71fe2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ imgs:
- 2022-07-23-sample-title-with-gradient_1024x512.jpg
---

{{% disclaimer %}}

You can think of this as hard-won wisdom.

If you're planning to build a website with the [Hugo](https://gohugo.io) [static site generator](https://github.com/myles/awesome-static-generators) (SSG) --- **or** if you already have one but you don't yet have a lot of content files --- save yourself a lot of trouble and use *[page bundles](https://gohugo.io/content-management/page-bundles/)*.
Expand Down Expand Up @@ -170,6 +168,3 @@ So, children, the moral of this story is:
Otherwise, someday, you'll wish you had. Don't wait until you have hundreds of pages, or more, that you have to retro-fit into this method.

Or, to be even shorter: **don't** be like me.

**Update from the future**: I later [abandoned](/posts/2023/07/big-unbundle/) this approach, **although** while conceding that it may still be the wiser course for many other Hugo users.
{.box}
5 changes: 5 additions & 0 deletions content/posts/2023/07/big-unbundle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ imgs:
- iA-Writer_dock-menu-all-index_1288x2624.png
---

{{% disclaimer %}}

A year ago, I [urged](/posts/2022/07/bundling-up-rebuilding-my-hugo-site/) fellow Hugo users to organize their websites by using [page bundles](https://gohugo.io/content-management/page-bundles/). While it still may be a good idea for many others, it's ceased to be the best course for me, so this site is now unbundled once again. In the end, it was a battle of comfort-and-convenience *versus* "best practices."

Comfort-and-convenience kicked butt and took names.
Expand Down Expand Up @@ -62,3 +64,6 @@ Now, to be sure, I could also see them listed in this more helpful and informati
Is that a petty reason even to *think* about doing such an about-face, much less actually to go through with it? Perhaps. But minor irritations of this nature, repeated day after day for months at a time, annoy me mightily; so there's that.

Besides, I also find it more intuitive and, yes, more comfortable to manage an unbundled site's overall file-storage arrangement, regardless of any other factors that may merit consideration. It's the way I managed the site project for the overwhelming majority of its history before now. Despite my age, I typically am *not* someone who resists change, at least if I can understand a good reason for the change --- but I *do* frequently object to change-for-the-**sake**-of-change, and this seemed to have become one of those cases.

**Update from the future**: I later [went back to a bundled setup](/posts/2023/10/big-rebundle/).
{.box}
17 changes: 6 additions & 11 deletions content/posts/2023/07/hugo-pipes-cloudinary-follow-up/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ So, once again, boys and girls, it's code time.[^defaults] I'll present the thre

[^defaults]: Thanks to [Sujal Gurung](https://github.com/dinesh-58) for the excellent suggestion that I use Hugo's [`default` function](https://gohugo.io/functions/default/) for cleaner code than what I originally had here! Somehow, I'd missed reading about that one all this time.

**Important**: The earlier post's code was based on storing the images in a [*bundled*](https://gohugo.io/content-management/page-bundles/) project --- *i.e.*, wherein each image is stored in the same folder as the `index.md` file for the post which calls the image --- but I've [since](/posts/2023/07/big-unbundle/) reverted to the *unbundled* arrangement I'd used for most of the site's history until [last year](/posts/2022/07/bundling-up-rebuilding-my-hugo-site/). As a result, the code below works with images which are [*global resources*](https://gohugo.io/hugo-pipes/introduction/) stored in the Hugo project's top-level `assets/` folder (specifically, `assets/images/`).
{.box}

```go-html-template{filename="render-image.html" bigdiv=true}
{{/*
For some additional background on this file, see:
Expand All @@ -166,10 +163,9 @@ So, once again, boys and girls, it's code time.[^defaults] I'll present the thre
{{- $filter := "box" -}}
{{- $divClass := print "relative bg-center bigImgDiv imgB-" $imgBd5 "-" $holder -}}
{{- $imgClass := "w-full h-auto shadow animate-fade" -}}
{{- $rscToMatch := print "images/" $src -}}
{{- if resources.GetMatch $rscToMatch -}}
{{ with resources.GetMatch $rscToMatch }}
{{- if .Page.Resources.GetMatch $src -}}
{{ with .Page.Resources.GetMatch $src }}
{{- $imgRsc := . -}}
{{- $width := $imgRsc.Width -}}
{{- $height := $imgRsc.Height -}}
Expand Down Expand Up @@ -250,10 +246,9 @@ So, once again, boys and girls, it's code time.[^defaults] I'll present the thre
{{- $imgClass = "img-phn ctrImg animate-fade shadow" -}}
{{- end -}}
{{- $dataSzes := "(min-width: 1024px) 100vw, 50vw" -}}
{{- $rscToMatch := print "images/" $src -}}
{{- if resources.GetMatch $rscToMatch -}}
{{ with resources.GetMatch $rscToMatch }}
{{- if .Page.Resources.GetMatch $src -}}
{{ with .Page.Resources.GetMatch $src }}
{{- $imgRsc := . -}}
{{- $width := $imgRsc.Width -}}
{{- $height := $imgRsc.Height -}}
Expand Down Expand Up @@ -312,8 +307,8 @@ So, once again, boys and girls, it's code time.[^defaults] I'll present the thre
{{- $src := . -}}
{{- $rscToMatch := print "images/" $src -}}
{{- $imgBd5 := md5 . -}}
{{- if resources.GetMatch $rscToMatch -}}
{{- $imgRsc := resources.GetMatch $rscToMatch -}}
{{- if $.Page.Resources.GetMatch $src -}}
{{- $imgRsc := $.Page.Resources.GetMatch $src -}}
{{- $BkgdStyleEnd := print "; background-size: cover; background-repeat: no-repeat; aspect-ratio: " $imgRsc.Width " / " $imgRsc.Height ";" -}}
{{- $GIP_colors := $imgRsc.Colors -}}
{{- if (lt ($GIP_colors | len) 2) -}}
Expand Down
4 changes: 1 addition & 3 deletions content/posts/2023/07/hugo-pipes-cloudinary/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ imgs:
- my-pet-cat_3264x2448.jpg
---

**Update, 2023-07-18**: As I will explain in a [subsequent post](/posts/2023/07/big-unbundle/), I've reverted to using [*global* resources rather than page resources](https://gohugo.io/hugo-pipes/introduction/) --- *i.e.*, all local images are now stored in the site project's `assets/images/` directory --- so a look at the [site repository](https://github.com/brycewray/hugo-site) won't show a setup that conforms to the approach I describe in this post.\
\
Also, while that approach **does** work, it apparently increases the build time for a Hugo project, especially given the sometimes underpowered servers used by some hosting vendors' free tiers. Therefore, if you adopt it for your own project, you may want to limit your fetching of remote images, thus keeping build times from becoming excessive **or** try the alternative I describe in a [follow-up](/posts/2023/07/hugo-pipes-cloudinary-follow-up/) to this post.\
**Update, 2023-07-18**: While the approach described in this post **does** work, it apparently increases the build time for a Hugo project, especially given the sometimes underpowered servers used by some hosting vendors' free tiers. Therefore, if you adopt it for your own project, you may want to limit your fetching of remote images, thus keeping build times from becoming excessive **or** try the alternative I describe in a [follow-up](/posts/2023/07/hugo-pipes-cloudinary-follow-up/) to this post.\
\
Finally, I have corrected the content of the final code block so that it corresponds to the local-first premise explained within; unfortunately, it didn't in the initial versions of this post.
{.box}
Expand Down

0 comments on commit 5d71fe2

Please sign in to comment.