Build only specific content sections


#1

I have a single repo which serves contents for two websites, both of which use different content sections. However, I just noticed that Hugo build all the sections for each website because my sitemap.xml is populated with all the sections.
Instead of modifying the sitemap.xml itself, I’d like to tell Hugo somehow not to touch some specific sections through the config. Is it possible to do so?

I don’t want to have to change the pagination code throughout the theme for this as well.


#2

Separate your content into 2 dirs, then for each site:

hugo --contentDir dirA
hugo --contentDir dirB

#3

Seems to be good as a workaround, but still, I’d prefer not to move around the files. Something which would disable specific sections would be better.


#4

Another possibility is to use ignoreFiles in your config file, e.g., here’s part of my config.yaml:

ignoreFiles:
  - UNPUBLISHED

Note:

  • ignoreFiles is only relevant to the content directory (but it would be great if it worked everywhere, e.g., in the static directory)
  • each string in an ignoreFiles list is a regular expression (RE) looking for a match in the path, e.g. many of my bundles include a path like articles/bundlename/UNPUBLISHED/oldscreenshot.png
  • if the RE is all lower case, it matches case insensitively (I think)
  • if the RE contains an upper-case character, it matches case sensitively (I think)

If your content directory includes directories named articles1 and articles2, you could put, e.g., articles1 in your ignoreFiles list and see if that does the trick. You’ll need to make sure there is no path that you want published that includes the RE articles1. You can play around with surrounding that with path delimiters, e.g. /articles1/ but you might need to escape the slashes, e.g. \/articles1\/. I’m still learning about REs in Hugo so I’m not sure if the slash character / has a special meaning in Hugo REs. So far I just deal with stuff that I want ignored by using upper-case (and I don’t use upper-case for anything I want published).

Let us know how you solve this problem. I want to ignore a lot of files in my Hugo site root directory and currently do some convoluted things to do that.


#5

Thanks, this is exactly what I was looking for!


#6

I’m glad that helped. BTW if anyone wants to do what I do and use upper-case characters in files and directories that you put in your ignoreFiles list, you may need to set disablePathToLower to true in your config file, e.g., here’s what I have in my config.yaml:

disablePathToLower: true

I say “may need to” because I don’t know what order Hugo does things in, e.g. does it first lower-case everything (in the default case of disablePathToLower: false) and then ignoreFiles or vice versa. There’s so much I don’t know about Hugo :frowning_face:.