I often find myself creating small sample sites when debugging a forum question. Most of them have the same basic setup, so figured I’d script it to save myself some time (relevant xkcd).
Sharing it on the off chance it’s useful for others.
Bash script
#!/bin/bash
site_name="$1"
log() {
message="$@"
echo "[$(date +'%a %Y-%m-%d %H:%M:%S %z')] $message"
}
usage() {
echo "Usage:"
echo " $0 <site_name>"
exit 1
}
if [[ -z "$site_name" ]]; then
usage
fi
log "Checking hugo version..."
hugo version
log "Creating site..."
hugo new site "$site_name"
if [[ $? -ne 0 ]]; then
log "Error creating site, exiting..."
exit 1
fi
cd "$site_name"
log "Creating homepage layout..."
cat << EOF > ./layouts/index.html
<h1>{{ .Title }}</h1>
{{ .Content }}
EOF
log "Creating homepage content..."
cat << EOF > ./content/_index.md
---
title: Home
---
Homepage content here.
EOF
log "Creating single layout..."
mkdir -p ./layouts/_default
cat << EOF > ./layouts/_default/single.html
<h1>{{ .Title }}</h1>
{{ .Content }}
EOF
log "Creating a few pages..."
for i in {1..5}
do
hugo new page${i}/index.md
done
log "Updating config file..."
cat << EOF >> ./config.toml
disableKinds = ["taxonomy", "taxonomyTerm"]
EOF
log "Generating site..."
hugo -D
Example usage
$ ./hugo_new_debug_site.bash
Usage:
./hugo_new_debug_site.bash <site_name>
$ ./hugo_new_debug_site.bash some-site
[Fri 2019-05-03 12:04:19 -0500] Checking hugo version...
Hugo Static Site Generator v0.55.5-A83256B9C/extended darwin/amd64 BuildDate: 2019-05-02T14:10:20Z
[Fri 2019-05-03 12:04:19 -0500] Creating site...
Congratulations! Your new Hugo site is created in /Users/zwbetz/Development/Sites/some-site.
Just a few more steps and you're ready to go:
1. Download a theme into the same-named folder.
Choose a theme from https://themes.gohugo.io/, or
create your own with the "hugo new theme <THEMENAME>" command.
2. Perhaps you want to add some content. You can add single files
with "hugo new <SECTIONNAME>/<FILENAME>.<FORMAT>".
3. Start the built-in live server via "hugo server".
Visit https://gohugo.io/ for quickstart guide and full documentation.
[Fri 2019-05-03 12:04:19 -0500] Creating homepage layout...
[Fri 2019-05-03 12:04:19 -0500] Creating homepage content...
[Fri 2019-05-03 12:04:19 -0500] Creating single layout...
[Fri 2019-05-03 12:04:19 -0500] Creating a few pages...
/Users/zwbetz/Development/Sites/some-site/content/page1/index.md created
/Users/zwbetz/Development/Sites/some-site/content/page2/index.md created
/Users/zwbetz/Development/Sites/some-site/content/page3/index.md created
/Users/zwbetz/Development/Sites/some-site/content/page4/index.md created
/Users/zwbetz/Development/Sites/some-site/content/page5/index.md created
[Fri 2019-05-03 12:04:20 -0500] Updating config file...
[Fri 2019-05-03 12:04:20 -0500] Generating site...
| EN
+------------------+----+
Pages | 7
Paginator pages | 0
Non-page files | 0
Static files | 0
Processed images | 0
Aliases | 0
Sitemaps | 1
Cleaned | 0
Total in 10 ms