将公众添加到.gitignore

时间:2018-06-07 21:31:23

标签: r hugo blogdown netlify

我试图遵循Blogdown书中的建议。有一段时间,我在本地构建我的博客网站,然后让Netlify部署它。

我现在正在阅读我可以将public/文件夹添加到.gitignore,因为Hugo应该在远程服务器上构建它:

  

如果您的网站要在Netlify等远程服务器上自动(重新)构建,则应忽略public /目录。

所以,我试过了。我确保GitHub不再公开跟踪。 我所做的就是这个。

首先,我向public添加了.gitignore 然后,我有这个git commit

git rm -r --cached .
git add .
git commit -am "Remove ignored files"

这会从预期的GitHub(https://github.com/taraskaduk/taraskaduk)中删除我的public/文件夹。

在Netlify上,我的部署失败了。 首先,这是我的部署设置(我觉得我应该在这里更改一些内容,但我没有看到任何指示这样做):

Repository: https://github.com/taraskaduk/taraskaduk
Build command: Not set
Publish directory: public
Production branch: master
Branch deploys: Deploy only the production branch and its deploy previews
Public deploy logs: Logs are public

(我尝试搞乱发布目录和构建命令,但没有说明,因为我不确定我在做什么,所以浪费时间) < / p>

现在,这是部署日志

5:18:42 PM: Build ready to start
5:18:44 PM: Fetching cached dependencies
5:18:44 PM: Starting to download cache of 131.5MB
5:18:45 PM: Finished downloading cache in 1.239616218s
5:18:45 PM: Starting to extract cache
5:18:46 PM: Finished extracting cache in 1.126354925s
5:18:46 PM: Finished fetching cache in 2.450276606s
5:18:46 PM: Starting to prepare the repo for build
5:18:47 PM: Preparing Git Reference refs/heads/master
5:18:47 PM: No build command found, continuing to publishing
5:18:47 PM: Failing build: Failed to build site
5:18:47 PM: failed during stage 'building site': Deploy directory 'public' does not exist
5:18:48 PM: Finished processing build request in 4.119821718s

我想我不清楚的是,如果它应该被重建,它为什么要查找公共目录?

我想有些东西不是为了点击我...我确定我的错误是相当愚蠢和基本的。帮助

编辑: 根据下面的建议,我添加了一个构建命令和hugo版本。现在部署并没有失败,Netlify表示该网站已上线,但网址上没有任何内容

2 个答案:

答案 0 :(得分:1)

评论中提出了解决方案(至少部分):我错过了hugo部署命令

答案 1 :(得分:0)

.gitignore正常工作后,向您的网站项目添加netlify.toml将有助于确保使用您针对部署上下文定位的版本运行正确的构建命令。

# Global settings applied to the whole site.
[build]
  command = "hugo"
  publish = "public"

# Build a preview of the site (Drafts and Future dates also) 
#   Un-comment next two lines.
#[context.deploy-preview]
#  command = "hugo --buildFuture"

[context.production.environment]
  HUGO_VERSION = "0.41"

# you can lock a version of hugo for a deploy preview
[context.deploy-preview.environment]
  HUGO_VERSION = "0.41"

# you can lock a version of hugo for a branch-deploy (other than previews)
[context.branch-deploy.environment]
  HUGO_VERSION = "0.41"

这样可以更好地控制您的构建。

注意: More information here also