Why won't my Hugo site display when deploying to Netlify?

Viewed 1285

Locally, I can view my site easily and all theme changes.

However, once the site is deployed to Netlify, all I am greeted with is a blank white screen.

I tried toggling baseURL configurations to no avail. However, if I rename my _index.md file to index.md in the /content folder the contents of that file will display when deployed via Netlify.

There are no build errors in Netlify or locally.

My working files can be seen at the following GitHub repository.

2 Answers

Explanation Summary: The _index.md file at the root of your content directory is using your themes/gwynn/layouts/index.html template, but you are not telling it to display any content or data from your frontmatter.

themes/gwynn/layouts/index.html code:

<!DOCTYPE html>
<html>
<body>
  {{ range first 10 .Data.Pages }}
    <h1><a href={{ .Permalink }}>{{ .Title }}</a></h1>
  {{ end }}
</body>
</html>

Nothing is showing up because you are displaying only the pages in your site, but both have draft: true set in the frontmatter of the pages in post.

Solution to show Home page Title:

themes/gwynn/layouts/index.html

<!DOCTYPE html>
<html>
  <head>
    <title>{{ .Title }}</title>
  </head>
  <body>
    <h1>{{ .Title }}</h1>
    {{ range first 10 .Data.Pages }}
      <h1><a href={{ .Permalink }}>{{ .Title }}</a></h1>
    {{ end }}
  </body>
</html>

To show the page links, you can set draft: false within content/post/first.md and content/post/second.md

Netlify doesn’t automatically know that you have a Hugo site. In the app.netlify.com interface, navigate to Site settings, then “Build & deploy” in the left-hand navigation.

netlify

In the Build command field, type hugo, and in the Publish directory, type public. I think this should be enough.

(If not, here’s a more detailed config from the Hugo site. That strikes me as too complicated, though.)

Going further, and this is optional, I prefer to run the hugo command locally, which generates the whole site, and the resulting public directory becomes part of my repo. In that case, I leave the above Build command: field blank, but keep the Publish directory: public field.

Related