Relative path for --contentDir with --source

The --contentDir <path> option gives CLI users a way to specify an alternative content directory for building or serving Hugo. The docs don’t indicate which directory this path is relative to, so if you also use the --source <path> option, it’s ambiguous whether the content directory will be:

  1. present working directory + relative content path, or
  2. source path + relative content path.

Let it be known that Hugo uses (2) content path = source path + relative content path.

For example, take this website with two theme modules and a small data subset for development.

~/website$ ls    # example hugo project directory
data-all          # all content
data-dev          # subset of data-all for fast build times
freemium          # theme module
premium           # theme module
package.json      # contains build scripts that run hugo

You might have build scripts that are called from the modules’ parent.

~/website$ hugo --source=freemium --contentDir=data-dev    # incorrect (1)
~/website$ hugo --source=freemium --contentDir=../data-dev # correct (2)

I’m leaving this here to help others who might have adverse experiences as a result of this ambiguity.

1 Like