今天按照教程成功在本地可以通过blogdown::serversite()预览到写好的网页,但是在build之后将public文件夹上传到github之后然后使用netlify部署过程中出错了,并且报错再别处都没有找到。
5:49:54 PM: 1. build.command from netlify.toml
5:49:54 PM: ────────────────────────────────────────────────────────────────
5:49:54 PM: ​
5:49:54 PM: $ hugo
5:49:54 PM: Start building sites …
5:49:54 PM: Total in 18 ms
5:49:54 PM: Error: Error building site: "/opt/build/repo/content/post/2021-05-28-statistical-software-home-work/index.html:11:14": failed to extract shortcode: template for shortcode "blogdown/postref" not found
5:49:54 PM: ​
5:49:54 PM: ────────────────────────────────────────────────────────────────
5:49:54 PM: "build.command" failed
5:49:54 PM: ────────────────────────────────────────────────────────────────
5:49:54 PM: ​
5:49:54 PM: Error message
5:49:54 PM: Command failed with exit code 255: hugo
5:49:54 PM: ​
5:49:54 PM: Error location
5:49:54 PM: In build.command from netlify.toml:
5:49:54 PM: hugo
5:49:54 PM: ​
5:49:54 PM: Resolved config
5:49:54 PM: build:
5:49:54 PM: command: hugo
5:49:54 PM: commandOrigin: config
5:49:54 PM: environment:
5:49:54 PM: - HUGO_VERSION
5:49:54 PM: - HUGO_ENV
5:49:54 PM: publish: /opt/build/repo/public
5:49:54 PM: functions:
5:49:54 PM: '*': {}
5:49:54 PM: Caching artifacts
5:49:54 PM: Started saving build plugins
5:49:54 PM: Finished saving build plugins
5:49:54 PM: Started saving pip cache
5:49:54 PM: Finished saving pip cache
5:49:54 PM: Started saving emacs cask dependencies
5:49:54 PM: Finished saving emacs cask dependencies
5:49:54 PM: Started saving maven dependencies
5:49:55 PM: Finished saving maven dependencies
5:49:55 PM: Started saving boot dependencies
5:49:55 PM: Finished saving boot dependencies
5:49:55 PM: Started saving rust rustup cache
5:49:55 PM: Finished saving rust rustup cache
5:49:55 PM: Started saving go dependencies
5:49:55 PM: Finished saving go dependencies
5:49:57 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:49:57 PM: Creating deploy upload records
5:49:57 PM: Failing build: Failed to build site
5:49:57 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
5:49:57 PM: Finished processing build request in 11.437927875s

这里面好像是说缺少模板文件,可是我是按照教程都上传到github仓库中了,不知道大家有什么解决方法,不胜感激。

    yihui 您好,使用checksite之后弹出的to do 如下
    ― Checking config.yaml
    | Checking "baseURL" setting for Hugo...
    ● [TODO] Update "baseURL" to your actual URL when ready to publish.
    | Checking "ignoreFiles" setting for Hugo...
    ○ "ignoreFiles" looks good - nothing to do here!
    | Checking setting for Hugo's Markdown renderer...
    ○ All set! Found the "unsafe" setting for goldmark.
    ― Check complete: config.yaml

    请问这个baseURl是在config.yaml的那里添加,并且具体添加什么内容,不胜感激

      g853346463 这个 baseURL 倒不是大问题。真正的问题是有个文件 layouts/shortcodes/blogdown/postref.html 你没有提交到 Github 库中。我上面说 blogdown::check_site() 应该会自动指出来这个问题,是因为我有专门的代码来检查这个常见问题:https://github.com/rstudio/blogdown/blob/00a2090/R/check.R#L142-L160 我不明白为什么在你这个网站里没能查出来。这个 postref.html 文件是否存在?理论上是应该存在的(自动生成的)。

      若你要是有基本的排错技能,你可以帮我看看为什么这个问题漏网了:

      debug(blogdown::check_gitignore)
      blogdown::check_site()

      运行到 if (Sys.which('git') != '' && system2_quiet('git', 'status') == 0) { 那一行时,看为什么 x8 没有将 x7 加进去。

        yihui 您好,我看了下我的repo里面是有postref.html这个文件存在的。通过增加baseURL解决了上述问题。您提到的没有报错的我通过您提出的方法找到了源代码,初步感觉是没有将x7的值赋给x8,但是我个人编程能力很差,也有可能说错了。源码如下:
        if (Sys.which("git") != "" && system2_quiet("git", "status") ==
        0) {
        msg_next("Checking for files required by blogdown but not committed...")
        x7 = c("layouts/shortcodes/blogdown/postref.html")
        x8 = NULL
        for (i in x7) {
        if (!file_exists(i))
        next
        if (system2_quiet("git", c("ls-files", "--error-unmatch",
        i)) != 0)
        x8 = c(x8, i)
        }
        if (n <- length(x8)) {
        msg_todo("Found ", n, " file", if (n > 1)
        "s", " that should be committed in GIT:\n\n",
        indent_list(x8))
        }
        else {
        msg_okay("Great! Did not find such files.")
        }
        }
        msg_done(f)
        }

        CyrusYip 感谢,因为对netlify的工作原理不是很懂,就一股脑都上传上去了 😃