MunifTanjim / minimo

Minimo - Minimalist theme for Hugo
https://minimo.netlify.app
MIT License
545 stars 220 forks source link

Using mounts module breaks the theme #290

Open lobopraveen opened 4 years ago

lobopraveen commented 4 years ago

Steps to reproduce

  1. Clone this repo git clone https://github.com/MunifTanjim/minimo.git
  2. cd minimo/exampleSite
  3. Edit the config file to point the theme to minimo theme and add mounts module as shown below
    
    theme = "../../../minimo"

[module] [[module.mounts]] source = "public" target = "static"


4. Create public directory `mkdir public`
5. `hugo server` renders the site properly; however, if you just build the site using `hugo`, all the files under `public/assets/` are zero byte files. Somehow the files are getting copied over from the theme's static directory to the publish directory (public) as zero byte files. 

Hugo Static Site Generator v0.74.3/extended linux/amd64

Just to make sure that this not an issue with Hugo and the mounts module usage as shown above, I grabbed [the second theme](https://github.com/jakewies/hugo-theme-codex) from Hugo themes collection and added the mounts module exactly as shown above and the theme's CSS and JS files were copied properly. I'm thinking this could be something to do with the minimo theme. 
MunifTanjim commented 4 years ago

Can't reproduce 🤔 Which hugo version are you using? @lobopraveen

lobopraveen commented 4 years ago

I tried the same steps now and it worked. So to recreate what I was trying to do, I created the public directory before step 4 and I'm able to reproduce the issue. I will update the steps.

lobopraveen commented 4 years ago

While trying to recreate I tried again with hugo-theme-codex theme. It works even when I follow the exact same steps .

I ran into something strange. In hugo-theme-codex, after followed the steps, I just deleted the about css files under public/css and ran hugo command, it recreated the file but it was a zero byte file. I reran hugo command and the file went from zero byte to the correct file with 4.7kB. I randomly started deleting the css and js file and running hugo without any change and the result was not consistent. Some times the file would reappear as zero byte and then proper size and sometimes it would just take couple of more retries of hugo command. Sometimes it would come right back on first try.

I think this is because of the circular dependency! Hugo command creates the site files and puts them in the public directory amd the static directory gets copied to the public directory as well. Now that the public directory is also mounted as the static, I'm guessing that it creates some kind of circular dependency or infinite loop and the result random.

The surprising thing is that the behavior in minimo theme is consistent. It just creates zero byte files and doesn't flip back even when I run the hugo command back to back a dozen times.

I just assumed that

  1. Hugo will first mount/download public directory as static
  2. build and copy the site content to the public directory and at that time the static content (from the mounts module) gets overwritten because static content came from the public directory

You may close this if you don't see any issue in your theme. It probably needs an answer from the Hugo developers.