Background image in home section not visible after deploying

My website is based on Hugo Academic theme.
I added a background image to my website by following the instructions here and it worked perfectly in localhost. However when I generated the public folder after running hugo and uploading them to Netlify, in my hosted website I can’t see the background image in my home section. However I am able to see background images in other sections where I added them. I have appended the following to my custom.css file -

.home-section:nth-of-type(4) {
  background-image: url('../img/color-pattern.svg');
  /* background-repeat:no-repeat; */
}

.home-section:nth-of-type(6) {
  background-image: url('../img/traces.svg');
  /* background-repeat:no-repeat; */
}
/* to make "white bg" transparent */
.home-section {
  background-color: transparent;
  z-index: 1;
}

#watermark{
	/*background-image:url('http://physics.ucr.edu/~flip/images/BG_Bundle2.jpg');*/
	background-size: 700px 350px;
	background-repeat:no-repeat;
	background-position:left top;
	margin: 0;
	padding: 0;
	position: absolute;
	top: 30px;
	left: 0px;
  pointer-events: none;
	/*z-index: 0;*/
	height: 100%;
	width: 100%;
	text-align: right;
	opacity: 0.1;
}

Any idea why is the background image in home section is showing in localhost but not on hosted website in netlify?

Since you’re deploying your site to netlify, your theme needs to be added as a git submodule. Else, netlify doesn’t “know” about your theme, since it isn’t cloned along with your site repo.

So, remove the contents of your theme folder, then from the root of your site do:

git submodule add https://github.com/gcushen/hugo-academic.git themes/academic

Later on, when you want to update the theme, do:

git submodule update --remote --merge

CC @neutreno

@zwbetz I am not sure if I understand that. The thing is in the documentation it says that once you are happy with how your site looks (localhost) and you want to deploy it you have two options i.e using continuous integration with Git or run hugo -> get a public folder and upload the contents of the public folder to Netlify. I did the second one because of certain things beyond the scope of discussion here. In that case do you want me to add the contents of theme inside public folder and then upload the new public folder to Netlify? I fail to see how this will work, maybe I am missing something?

I see. I didn’t realize one could manually upload files to netlify. The way I’m familiar with: one connects their repo to netlify then it’s cloned and built. So since you’re doing the manual copy method, disregard.


For myself and others curious, netlify manual deploy docs.

Am curious, for your manual deploy, do you run this command:

netlify deploy

Or something else?

I actually just use the GUI. From my dashboard I goto Deploys and at the bottom you can see a place to upload your public folder and a list of previous deployments as follows -


Now i haven’t tried uploading the whole folder. Presently I just upload public. I am not sure of uploading the whole thing would make any difference. Docs about deployment.

Your current process should work fine as-is. I’m not sure what Hugo version Netlify uses by default (I think an old one, like version 0.17), so try explicitly setting it:

Settings > Build & Deploy > Continuous Deployment > Build environment variables, then:

Key: HUGO_VERSION
Value: 0.53

Also see https://www.netlify.com/blog/2017/04/11/netlify-plus-hugo-0.20-and-beyond/

I hate to say this but I don’t have any settings like that. There is no Build environment variables for my dashboard.

Hmm, on 2nd thought, that makes sense. Sorry, it’s late for me. (Specifying Hugo version would only be for continuous deployment, but that’s irrelevant since you’re just uploading the generated files).

So I tried cloning and building your site, but I get these errors:

Building sites … WARNING: make non-relative ref/relref page reference(s) in page "/post/managing-content.md" absolute, e.g. {{< ref "/blog/my-post.md" >}}
WARNING: make non-relative ref/relref page reference(s) in page "/post/getting-started.md" absolute, e.g. {{< ref "/blog/my-post.md" >}}
WARNING: make non-relative ref/relref page reference(s) in page "/post/writing-markdown-latex.md" absolute, e.g. {{< ref "/blog/my-post.md" >}}
WARNING: make non-relative ref/relref page reference(s) in page "/post/migrate-from-jekyll.md" absolute, e.g. {{< ref "/blog/my-post.md" >}}
ERROR 2019/01/07 22:49:12 Please complete the installation of Academic by following the steps at https://sourcethemes.com/academic/docs/install/
ERROR 2019/01/07 22:49:12 render of "page" failed: "/Users/zwbetz/Development/Sites/FlipWebsite2017/layouts/teaching/class.html:5:5": execute of template failed: template: teaching/class.html:5:5: executing "teaching/class.html" at <partial "header_imag...>: error calling partial: Partial "header_image.html" not found
ERROR 2019/01/07 22:49:12 render of "page" failed: "/Users/zwbetz/Development/Sites/FlipWebsite2017/layouts/teaching/class.html:5:5": execute of template failed: template: teaching/class.html:5:5: executing "teaching/class.html" at <partial "header_imag...>: error calling partial: Partial "header_image.html" not found
ERROR 2019/01/07 22:49:12 render of "section" failed: "/Users/zwbetz/Development/Sites/FlipWebsite2017/layouts/section/teaching.html:4:3": execute of template failed: template: section/teaching.html:4:3: executing "section/teaching.html" at <partial "header_imag...>: error calling partial: Partial "header_image.html" not found
ERROR 2019/01/07 22:49:12 render of "section" failed: "/Users/zwbetz/Development/Sites/FlipWebsite2017/layouts/section/publication.html:4:3": execute of template failed: template: section/publication.html:4:3: executing "section/publication.html" at <partial "header_imag...>: error calling partial: Partial "header_image.html" not found
Total in 63 ms
Error: Error building site: failed to render pages: render of "page" failed: "/Users/zwbetz/Development/Sites/FlipWebsite2017/layouts/teaching/class.html:5:5": execute of template failed: template: teaching/class.html:5:5: executing "teaching/class.html" at <partial "header_imag...>: error calling partial: Partial "header_image.html" not found

Oh wait, that github link I sent you, that is someone else. I was just following the steps that the professor performed to be able to add a watermark or background image. Since then he has changed his website repo https://github.com/fliptanedo/academic-flip but the steps for watermark remain same. His website looks amazing btw. I wanted to achieve the same background thing. I don’t have my website on Github as of now. Maybe I can do it tonight. But in my localhost you can see this -

Gotcha. I’m afraid I can’t help unless I can see your code.

Okay. I will put my code on Github tonight. Maybe we can continue this tomorrow. Meanwhile I will try to see if i am making any mistakes too. Thanks a ton for the effort.

@zwbetz I configured Netlify to publish my website from my git repo. Still the same issue. No watermark in aboutme section, however the other two watermarks show. You can use this repo for my website and hugo-academic or my fork of hugo-academic https://github.com/armsp/hugo-academic for the internal theme.
The contents of my netlify.toml are -

[build]
  publish = "public"
  command = "hugo"

[context.production.environment]
  HUGO_VERSION = "0.53"
  HUGO_ENV = "production"
  HUGO_ENABLEGITINFO = "true"

Even then I couldn’t see the watermark in aboutme section.

The baseURL in your config.toml needs to be the URL of your site, not / as you have it currently.

Corrected that. But that didn’t help.

In layouts/partials/header.html on line 166, change this:

style="background-image:url('{{ $.Site.BaseURL }}/img/{{ .Site.Params.watermark }}');

To this:

style="background-image:url('/img/{{ .Site.Params.watermark }}');

AKA just remove {{ $.Site.BaseURL }}

Worked like a charm :grinning: Thankyou so so much !!