How to specify the version of third parties library?

Hi, I want to specify the version of third-party library in Hugo module, for example,

[[module.imports]]
path = "github.com/razonyang/hugo-mod-icons"

[[module.imports]]
path = "github.com/FortAwesome/Font-Awesome"
[[module.imports.mounts]]
source = "svgs/brands"
target = "assets/icons/font-awesome-brands"
[[module.imports.mounts]]
source = "svgs/regular"
target = "assets/icons/font-awesome-regular"
[[module.imports.mounts]]
source = "svgs/solid"
target = "assets/icons/font-awesome-solid"

I want to specify the versions like NPM does: ^5.0.0 || ^6.0.0, since the module doesn’t work with 4.
And then throw an error if users install the wrong version.

This will download the latest 6.x version github.com/FortAwesome/Font-Awesome/v6.

@divinerites logged this a while ago…

https://github.com/FortAwesome/Font-Awesome/issues/17342

2 Likes

Maybe there’s another way, but you can work around the Font Awesome tagging issue by forking.

1) Visit https://github.com/FortAwesome/Font-Awesome/fork.

image1

2) Press the Fork button.

image2

3) Press the Create fork button.

4) Clone the new repository, something like:

cd $HOME/code
git clone https://github.com/jmooring/Font-Awesome
cd Font-Awesome

5) When you cd into the directory, you will be on the 6.x branch.

image3

6) Initialize as a Go module, ending with /v6, something like:

go mod init  github.com/jmooring/Font-Awesome/v6

7) Commit the change, tag, and push back to your fork:

git add go.mod
git commit -m "Initialize Go module"
git tag v6.2.1
git push
git push --tags

8) In your Hugo site configuration, import the new module (note the /v6 at the end), something like:

[[module.imports]]
path = "github.com/jmooring/Font-Awesome/v6"

9) If you have been testing, clear the caches:

# The command below is irreversible! Make sure you don't delete /tmp.
sudo rm -rf /tmp/hugo-cache
go clean -modcache

10) Build your site and examine the go.mod file. It should look something like:

module mysite

go 1.19

require (
	github.com/jmooring/Font-Awesome/v6 v6.2.1 // indirect
	github.com/razonyang/hugo-mod-icons v0.1.0 // indirect
)

I’ll leave the github.com/jmooring/Font-Awesome repository in place for a couple of days if you want to test with it, but I’m deleting it on 14 December 2022.

3 Likes

Thanks, but it may be hard to maintain and keep the fork up to date in this way.

First, it really doesn’t change that often. They are just icons.

Second, GitHub makes it simple with the Sync fork button on your forked repo:

image

1 Like

Thanks, it seems the better way so far. I think the re tag task can be done automatically via GitHub Actions (schedule), so that it won’t become a problem.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.