Script to create new debug site

#1

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
6 Likes
#2

Cheers!

I’m gonna be pissed when this comes to bite us in the ass when no one shares repo links any longer as the #support helpers can just produce new hugo sites to test their five lines of code shared in a screenshot… :stuck_out_tongue_winking_eye:

2 Likes
#3

No kidding :stuck_out_tongue_winking_eye:. Will have to keep it on the down low

1 Like
#4

We may need a new support forum to support the supporting support script for supporters. :joy:

4 Likes
#5

May be the script should just git clone a debug website.

I usually just clone, modify and push to a new remote for new Hugo issues. Example: https://gitlab.com/hugo-mwe/hugodocs-issue-546

1 Like
#6

Anddd that’s a better idea lol

#7

I made a repo with a very small site to test themes in continuous integration tools a while ago; I guess this could be used for debugging purposes as well. It currently doesn’t completely fit the use case: because it is used to test themes, it doesn’t have its own layouts. Of course, I’m open to suggestions for improvements!

The repo is here: https://github.com/EmielH/hugo-theme-test

2 Likes
#8

Depends. I’m usually unable to provide the repo or the site. Only the public version of my site is visible, and I wouldn’t push to it unless everything is working. My repos are private, although I suppose I could fork them and post them. I’m gonna look at what zwbetz provided, and work up something that’s in between a useless sample and a full site. That is, after I clean all the cruft out of my existing site!

#9

Took the hint from @kaushalmodi and made it into a git repo.

https://starter-hugo-debug-site.netlify.com/

1 Like
#10

You can use the debugbar or my debugprint component in there :slight_smile:

Here’s my version of a similar site: https://hugo-sandbox.netlify.com/ (with pictures and bundles too).

1 Like
#11

Nice. I like that you give the key data type too (among other things, can tell that you put some work into this bad boi)