HUGO

How to build only certain tags?

Is there any way to build your site while ignoring all pages that have a certain tag in the front matter? (Or conversely, build ONLY pages with a certain tag)?

The use case I am going for is I separate websites for A), my personal blog, B) my professional facing blog, and C) both put together.

You cannot prevent a page from being built based on the presence or absence of a taxonomy term.

You could, however, configure your list pages to include or exclude content with specific taxonomy terms, triggered by an environment variable defined when you run hugo. For example:

$ TAG=personal hugo

Then, access this value from a template with getenv:

{{ $tag := getenv "TAG" }}
{{ $pages := slice }}

{{ if $tag }}
  {{ $pages = where .Site.RegularPages "Params.tags" "intersect" (slice $tag) }}
{{ else }}
  {{ $pages = .Site.RegularPages }}
{{ end }}

{{ range $pages }}
  <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
  <p>{{ .Summary }}</p>
{{ end }}

I think it would be easier to either (a) separate your sites, or (b) separate the content by directory and exlude one of the directories when you deploy.