Is it possible to ignore directories inside a staticDir?

Is it possible to ignore a directory inside staticDir?

I have a bootstrap theme that is built using gulp. It generates a dist folder containing a few subfolders: dist/css, dist/fonts, dist/img, dist/video, dist/js.

I only need the dist/css dist/fonts and dist/js, so I added those to hugo as staticDirs. The problem is that all the files are added to the website root, so the relative links get messed up.

If I was able to add the dist directory to the staticDir, then it would maintain the folder heirarchy and everything would work. The problem is that it also adds the theme’s video and image files, which I do not want. Is there any way to make them get ignored?

Another solution I’ve thought about is editing the theme’s files to fix the links, but that leaves a high likelihood of making a mistake. It also makes updating the theme much more difficult.

Lastly, I’ve also though about modifying the gulpfile to create a second folder just for the files I want to use in hugo, but I’m not that experienced with gulp and don’t think I could modify it properly (especially with all the fancy file watching, cleaning, etc. that the gulpfile is doing).

One idea: When you copy that dir over using gulp, instead of copying the full dist dir, copy on the subdirs you want

Thanks for the suggestion. That’s what I meant in the last paragraph, but the way the gupfile is structured makes it difficult (and I’m still new with gulp). I’d rather do it through hugo if at all possible so that way I won’t have to be modifying the theme’s files.

I’ll use your suggestion as a backup plan!

I see. Well, I’m not familiar with gulp, but this could easily be done with a bash script too. For example after the dist dir is copied over, run:

rm -r static/dist/img
rm -r static/dist/video

Try ignorefiles = [ "/dist/video/.*", "dist/img/.*" ] in the config. This parameter goes before any TOML tables.

ref: https://gohugo.io/getting-started/configuration/#ignore-files-when-rendering

1 Like

Thanks for the suggestion but it didn’t work. I tried a bunch of different strings and couldn’t get it to work.

I even tried using the example from the documentation ignoreFiles = [ "\\.foo$", "\\.boo$" ] but I replaced foo with mp4 and the file was still being copied over.

Hugo ignores files when rendering! Nothing to do with gulp.

gulp generates the static assets I need for my webpages into its own special directory structure that the theme developer chose. I’m attempting to point hugo’s staticDir to those assets, without copying unnecessary files (e.g., sample videos and sample images). If I pick and choose only the folders I want, then hugo flattens them into the sites root directory and all the relative links get broken.

From the answers I’m getting it seems that hugo is unable to do this at this point in time. My backup plan is to edit the bootstrap themes files to fix the relative links, but that was something I was hoping to avoid.

I did some searching on the hugo github repo, and it seems like this is an issue that someone has already created a pull request for.

ignoreFiles is only relevant to the content directory. I posted about that here:

It would be useful if Hugo had other ignore variables like:

  • ignoreStaticFiles
  • ignoreLayoutFiles
  • ignoreConfigFiles
  • ignoreAssetFiles

The most useful would be ignoreStaticFiles since all those files get automatically copied to the publishDir.

1 Like