Excluding Folders in Static

Hoping for a different answer or a workaround:

I would like to exclude folders from my static folders from being copied. Is there a good way to do this?

Specifically:
My static directories have “.git” subdirectories. (There is a complicated arrangement of submodules, so I can’t avoid this). I do not want the “.git” directory copied during the build process.

Post: Exclude a folder inside static implies this is not possible.
Although, Is it possible to ignore directories inside a staticDir? - #8 by w1res is less conclusive. (and IgnoreFiles for static folder · Issue #1559 · gohugoio/hugo · GitHub suggests it is being added).

If it isn’t possible…
Is there an easy way to add a post-build cleanup step that deletes all the “.git” folders from the build?

Thank you!

Mike

[[module.mounts]]
source = 'static'
target = 'static'
excludeFiles = '.git'

The include/exclude options were added in v0.89.0 (Nov 2021).

Awesome! This is what I need.

But… how does this interact with multiple static directories (if I add those lines to my config.toml, I don’t get the 2nd directory).

Context…

At the top of my config.toml, I have the lines:
staticDir = “static”
staticDir2 = “…/common/CS559-Lib”

I have to do this, because we use switching to switch the static directory based on the command line arguments. (a second toml file over-writes “staticDir” to point towards an alternate directory. We use this to generate both the assignment and the answer key for students).

It seems that with the module.mounts above, the 2nd staticDir is ignored.

Remove these, and replace them with mounts. But you need to use absolute paths.

[[module.mounts]]
source = 'static'
target = 'static'
excludeFiles = '.git'

[[module.mounts]]
source = '/home/user/common/CS559-Lib'  # or whatever
target = 'static'

Thank you! This is helpful. I wasn’t aware of mounts. (and I haven’t really learned about modules yet)

In reading up on this, there are two things that (I think) are incompatible with what I am doing:

  1. it would be really hard to do absolute paths (many people build these on different machines)
  2. I need to be able to over-ride the first directory “later” in the config file (technically, a second config file is read that over-writes the staticDir variable - we use this to switch configurations at the command line)

Basically, we do hugo to build the assignments and hugo --config=config.toml,config-solution.toml to generate the answer key (the “config-solution.toml” changes staticDir to include the answers, rather than the empty questions).

Module mounts seem better than the “staticDir” - but if I cannot workaround 1 and 2, it might be a non-starter.

More context:
I am using Hugo to generate weekly workbooks for an undergraduate computer graphics class. Each “workbook” is a mini website (built in Hugo), with some embedded pages with JavaScript programs on them (large numbers of static files as far as Hugo is concerned). Some of those JavaScript programs are the empty “starter code” for the student assignments. (others are demos we give the students)

What I have is a tangled mess where there is 1 GitHub Repository with 12 “workbooks”. Each workbook has 2 versions of a static directory with the programs that students write - one has the empty starter code, the other has the example solutions. Each workbook also includes (as static files) a bunch of JavaScript libraries required to run the code.

Some of those libraries are included in the overall repository as git submodules - which is why they have .git that gets copied over (the point of the question). Right now, I delete them manually.

I’ve edited my previous post. You do not need to use absolute paths; my testing was flawed.

config-cs559.toml

[[module.mounts]]
source = 'static'
target = 'static'
excludeFiles = '.git'

[[module.mounts]]
source = '../common/CS559-Lib'
target = 'static'
excludeFiles = '.git'

config-cs800.toml

[[module.mounts]]
source = 'static'
target = 'static'
excludeFiles = '.git'

[[module.mounts]]
source = '../common/CS800-Lib'
target = 'static'
excludeFiles = '.git'

Then run:

hugo --config config-cs559.toml OR
hugo --config config-cs800.toml

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.