本地访问我的网站很容易,所有的主题更改都可以被看到。
然而,一旦将网站部署到Netlify,我只看到一个空白的白屏。
我尝试切换baseURL
配置,但没有成功。但是,如果我将/content
文件夹中的_index.md
文件重命名为index.md
,则在通过Netlify部署时会显示该文件的内容。
在Netlify或本地没有构建错误。
您可以在以下GitHub存储库中查看我的工作文件。
_index.md
文件正在使用您的themes/gwynn/layouts/index.html
模板,但您未告诉它显示来自您前置元数据的任何内容或数据。
themes/gwynn/layouts/index.html
代码:<!DOCTYPE html>
<html>
<body>
{{ range first 10 .Data.Pages }}
<h1><a href={{ .Permalink }}>{{ .Title }}</a></h1>
{{ end }}
</body>
</html>
您看不到任何内容,因为您只显示了网站中的页面,但是在文章的前置元数据中都将draft: true
设置。
显示主页标题的解决方案:
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>
content/post/first.md
和 content/post/second.md
中设置 draft: false
。Netlify并不自动知道您有一个Hugo网站。在app.netlify.com界面中,导航到“站点设置”,然后在左侧导航中选择“构建和部署”。
在“Build command”字段中,输入hugo
,在“Publish directory”字段中,输入public
。我认为这就足够了。hugo
命令,生成整个站点,然后生成的public
目录成为我的repo的一部分。在这种情况下,我会将上面的Build command:
字段留空,但保留Publish directory: public
字段。
hugo
构建默认的 草稿、未来和过期内容。使用hugo server --buildDrafts
可以在本地服务器上预览草稿,而不带草稿的则使用hugo server
。 - talves