HUGO

Prevent a page be rendered

Assuming I have a property like .Site.domain.

Now assuming I have several pages, like:

  1. page1/index.md:
    ---
    domains: [ a.com, b.com ]
    ---
    # page1.
    
  2. page2/index.md:
    ---
    domains: [ a.com ]
    ---
    # page2.
    
  3. page3/index.md:
    ---
    domains: [ b.com ]
    ---
    # page3.
    

If I call now hugo I want that if just all pages are rendered where .Site.domain=a.com and in another call .Site.domain=b.com.

How to do that in the sitemap is clear to me, but how to fully prevent hugo from creating the related pageX/index.html?

You can set Build Options in your frontmatter

Thanks @pamubay,

I’ve read this article already, but still have issues to apply this to my described problem. In my case the page should not define if it is rendered. I need to define from another global point if a page that meets a requirement is rendered or not.

Can you outline an example for that?

Unfortunately, that’s not possible in Hugo.

You can include/exclude by filename.

content/
├── post
│   ├── post-1.a.md
│   ├── post-2.b.md
│   ├── post-3.a.md
│   ├── post-4.b.md
│   └── post-5.c.md
└── _index.md

Build the site, ignoring content with .a. in the filename:

HUGO_IGNOREFILES=[\\.a\\.] hugo --cleanDestinationDir

Build the site, ignoring content with .b. in the filename:

HUGO_IGNOREFILES=[\\.b\\.] hugo --cleanDestinationDir

Build the site, ignoring content with either .a. or .b. in the filename:

HUGO_IGNOREFILES=[\\.a\\.,\\.b\\.] hugo --cleanDestinationDir

To avoid creating URLs such as /post/post-1.a/ you will want to configure a permalink pattern for each content type. Something like

[permalinks]
post = "/:sections/:slug"

Finally, setting the configuration value HUGO_IGNOREFILES on the command line does not define the configuration value; it changes the existing value. Or to put it another way, you cannot change the ignoreFiles configuration option from the command line unless you first define it in the configuration file.

ignoreFiles = []

Remember, with the TOML syntax this must appear before tables and arrays of tables.

One more thing: the --cleanDestinationDir option does not work unless you have a static directory. This is a known issue:

What you can do is to put build options in the cascade section of your home page – and only target the pages you want to “not render”: