Specify the Hugo Source Directory Path - Command Option (hugo server --source)

If you specify the Hugo command option “–source” and set it as a command alias (alias), you can run the command from anywhere.

Specify the Source Directory Path

When running the hugo command, you can start it by specifying the source directory path with the -s (--source) option.

Example: Start the Hugo server using the source code in ~/mysite

$ hugo server -s ~/mysite

Example: Create a new article in ~/mysite

$ hugo new sample.md -s ~/mysite

Setting a Command Alias

In the example above, the source directory was specified after the command with the -s ~/mysite option, but Hugo also works if it is specified before the command.

Using this, if you set a command alias (alias) like the following, it is convenient because you can run the command immediately from any directory. ~/.bash_profile

alias hugo-mysite=hugo -s ~/mysite

For example, you can use it as follows.

$ hugo-mysite new sample.md  # Create a post
$ hugo-mysite server         # Start the Hugo server
$ hugo-mysite                # Build the site (output to ~/mysite/public)