Skip to content

Commit b822fed

Browse files
authored
Auto-generate the hugoautogen workspace via a postinstall hook (#474)
1 parent c4b169e commit b822fed

4 files changed

Lines changed: 25 additions & 16 deletions

File tree

.github/workflows/links.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
cache: npm
2828
cache-dependency-path: package.json
2929

30-
- run: npm run install:all
30+
- run: npm install --omit=optional
3131

3232
- name: Install lychee
3333
env:

README.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,23 @@ your environment in our
6161
guide.
6262

6363
Once you've made your working copy of the site repo, from the repo root folder,
64-
first install the npm dependencies, including the Bootstrap and Font Awesome
65-
assets that the theme sources as npm packages:
64+
install the npm dependencies, including the Bootstrap and Font Awesome assets
65+
that the theme sources as npm packages:
6666

6767
```bash
68-
npm run install:all
68+
npm install
6969
```
7070

71+
Because this site fetches Hugo itself from npm and discovers the theme's npm
72+
assets through Hugo modules, a `postinstall` hook runs `hugo mod npm pack` and a
73+
second install, so this single `npm install` sets everything up. Because that
74+
runs a Hugo module command, `npm install` requires the `go` command; see
75+
[Troubleshooting](#troubleshooting) if it fails.
76+
7177
Then run:
7278

7379
```bash
74-
hugo server
80+
hugo serve
7581
```
7682

7783
## Running a container locally
@@ -121,17 +127,18 @@ Make sure your installed go version is `1.18` or higher.
121127

122128
Clone the latest version of the docsy theme into the parent folder of your
123129
project. The newly created repo should now reside in a sibling folder of your
124-
site's root folder.
130+
site's root folder. Replace _`VERSION`_ with the version you want to use, for
131+
example `v0.16.0`:
125132

126133
```shell
127134
cd root-of-your-site
128-
git clone --branch v0.12.0 https://github.com/google/docsy.git ../docsy
135+
git clone --branch VERSION https://github.com/google/docsy.git ../docsy
129136
```
130137

131138
Now run:
132139

133140
```shell
134-
HUGO_MODULE_WORKSPACE=docsy.work hugo server --ignoreVendorPaths "**"
141+
HUGO_MODULE_WORKSPACE=docsy.work hugo serve --ignoreVendorPaths "**"
135142
```
136143

137144
or, when using npm, prepend `local` to the script you want to invoke, e.g.:
@@ -164,7 +171,7 @@ characters '//' so that this line takes effect.
164171
As you run the website locally, you may run into the following error:
165172

166173
```console
167-
$ hugo server
174+
$ hugo serve
168175
WARN 2023/06/27 16:59:06 Module "project" is not compatible with this Hugo version; run "hugo mod graph" for more information.
169176
Start building sites …
170177
hugo v0.101.0-466fa43c16709b4483689930a4f9ac8add5c9f66+extended windows/amd64 BuildDate=2022-06-16T07:09:16Z VendorInfo=gohugoio
@@ -180,7 +187,7 @@ of the user guide for instructions on how to install Hugo.
180187
Or you may be confronted with the following error:
181188

182189
```console
183-
$ hugo server
190+
$ hugo serve
184191

185192
INFO 2021/01/21 21:07:55 Using config file:
186193
Building sites … INFO 2021/01/21 21:07:55 syncing static files to /
@@ -196,13 +203,15 @@ of the user guide for instructions on how to install Hugo.
196203
Or you may encounter the following error:
197204

198205
```console
199-
$ hugo server
206+
$ hugo serve
200207

201208
Error: failed to download modules: binary with name "go" not found
202209
```
203210

204211
This error occurs if the `go` programming language is not available on your
205-
system. See this
212+
system. Because `npm install` runs `hugo mod npm pack` (via a `postinstall`
213+
hook), this can also surface during installation, not only when serving. See
214+
this
206215
[section](https://www.docsy.dev/docs/get-started/docsy-as-module/installation-prerequisites/#install-go-language)
207216
of the user guide for instructions on how to install `go`.
208217

netlify.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# (https://gohugo.io/hosting-and-deployment/hosting-on-netlify/#configure-hugo-version-in-netlify)
33

44
[build]
5-
command = "npm run install:all && npm run build:preview"
5+
command = "npm run build:preview"
66
publish = "public"
77

88
[build.environment]
99
GO_VERSION = "1.22.2"
1010

1111
[context.production]
12-
command = "npm run install:all && npm run build:production"
12+
command = "npm run build:production"

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
"fix:format:diff": "npm run fix:format",
3636
"fix:format": "npm run _check:format -- --write",
3737
"fix": "npm run fix:format",
38-
"install:all": "echo 'INFO: first install is for hugo from hugo-extended' && npm install && hugo mod npm pack && npm install",
3938
"local": "npm run _local -- npm run",
4039
"make:public": "git init -b main public",
4140
"post_hugo": "npm run _fix:permissions",
41+
"postinstall": "npm run update:docsy:pack",
4242
"postupdate:docsy:main": "npm run _update:docsy:post",
4343
"postupdate:docsy:mod": "npm run _update:docsy:post",
4444
"precheck:links:internal": "npm run build",
@@ -51,7 +51,7 @@
5151
"test": "npm run test-and-fix",
5252
"update:docsy:main": "hugo mod get -u github.com/google/docsy/theme@main",
5353
"update:docsy:mod": "hugo mod get -u github.com/google/docsy/theme",
54-
"update:docsy:pack": "hugo mod npm pack && npm install",
54+
"update:docsy:pack": "hugo mod npm pack && npm install --ignore-scripts",
5555
"update:hugo": "npm install --save-dev --save-exact hugo-extended@latest",
5656
"update:main": "npm run update:packages && npm run update:docsy:main",
5757
"update:packages:not-hugo": "npm run update:packages -- -x hugo-extended",

0 commit comments

Comments
 (0)