主站的投稿指南都是针对 md 文档投稿的,没有针对 rmd 文档投稿的。楼主想要投一个rmd格式的文档,现在已经把本地的.rmd文档,.html文件和index_files文件夹整个都传到新建的分支上面了。但是不能预览,过程中有这些问题:

1.在Rstudio打开项目后,Addins-->New Post新建文档时,虽然选择了.rmd格式,但是出来的还是index.md而不是index.rmd,于是我给手动改了文件后缀变成了.rmd文档。随后 knit 生成的 html 文件打开后,yaml 文件头里面的文章题目、日期、作者等都不见了,一打开 html 文件就是目录。

2.在本地预览时,viewer窗格是一片白板。之前我本地的hugo版本是0.81.0,在我自己的博客项目里鼓捣rmd格式文档时是可以正常预览的。今天要投稿,hugo版本升到了0.101.0,就不能预览了。

Git相关操作如下

1.首先在 github 上面登录自己的账号 earfanfan,接着去cosname/cosx.org 上面点击 Fork,得到 earfanfan/cosx.org仓库
2.在本地新建一个文件夹用来存放克隆的仓库,比如 cos
3.打开 git-bash.exe,依次输入

cd D:/R/myblog/cos/
git init
git clone git@github.com:earfanfan/cosx.org.git

接下来需要新建一个分支,比如dtmanual

git checkout -b dtmanual

4.打开Rstudio,进入到对应的project下面,新建rmd文档,knit生成必要的文件,也就是要投稿的文章。
在Rstudio的Terminal终端输入

 git add content/post/2022-10-30-dt-manual-for-me/

接着点击commit,输入“投稿: DT 速查手册 袁凡”提交到暂存区
5.在Rstudio的Terminal输入

git push origin master:dtmanual

这样文档会被提交到新创建的分支 dtmanual 上面去
6.最后在 github 的 earfanfan/cosx.org 会自动出现一个绿色的按钮 CREATE pull request,点击以后好像就投稿完成了。

不过,还是不知道哪里失败了,因为虽然提交上去了,可是文章没法预览,还是请编辑部的大人们来帮忙看看吧。

    yuanfan
    你是不是手动删了 HTML 文件的部分内容,因为我看不到 YAML 内容,见下图。随 Rmd 文件渲染出来的 HTML 文件要原封不动地上传上来的,只要这样,才能预览新投的文章。


      Cloud2016
      我没动过 html 文件,是 knit 生成的时候就没有,我还纳闷怎么那个 html 文件打开一看直接就是目录连文章题目都没有。

        话说我点击Addins--New post的时候,虽然选择的是新建.rmd文档,但是生成的还是.md文档。并且有下面的提醒,于是我就手动把.md文档的文件后缀改成了.rmd,不造这么干是不是会出问题?

        > blogdown:::new_post_addin()
        
        Listening on http://127.0.0.1:3198
        Warning in file(con, "r") :
          cannot open file 'Content "D:\\R\\myblog\\cos\\cosx.org\\content\\post\\2022-10-30-dt-manual-for-me\\index.md"/index.md': Invalid argument
        Warning: Error in file: cannot open the connection
          9: shiny::runApp
          8: shiny::runGadget
          7: eval
          6: eval
          5: sys.source
          2: source_addin
          1: blogdown:::new_post_addin
        Warning message:
        The select input "tag" contains a large number of options; consider using server-side selectize for massively improved performance. See the Details section of the ?selectizeInput help topic. 

          @yihui 当告诉用户在R Markdown 生态中用knitr生成文档后,遇到 blogdown 教育用户不要用 knitr 的成本极高,也确实非常违和,也是很多人吐槽的地方,甚至也是 Quarto 宣传的重点。

            Cloud2016
            可能是我电脑配置不够,或者存在别的问题,blogdown:::serve_site()执行以后,viewer 窗格是一片白板。

            > blogdown:::serve_site()
            Launching the server via the command:
              C:/Users/fanfan/AppData/Roaming/Hugo/0.101.0/hugo.exe server --bind 127.0.0.1 -p 4321 --themesDir themes -t hugo-xmag -D -F --navigateToChanged --noTimes
            Serving the directory . at http://localhost:4321
            Launched the hugo server in the background (process ID: 7648). To stop it, call blogdown::stop_server() or restart the R session.

            这是执行blogdown::check_site()得到的结果,我没看出来撒问题。

            > blogdown::check_site()
            ― Running a series of automated checks for your blogdown website project...
            ---------------------------------------------------------------------------------------------------------------------------
            ○ A successful check looks like this.
            ● [TODO] A check that needs your attention looks like this.
            | Let's check out your blogdown site!
            ---------------------------------------------------------------------------------------------------------------------------
            ― Checking config.toml
            | Checking "baseURL" setting for Hugo...
            ○ Found baseURL = "https://cosx.org/"; nothing to do here!
            | 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.toml
            
            ― Checking .gitignore
            | Checking for items to remove...
            ○ Nothing to see here - found no items to remove.
            | Checking for items to change...
            ○ Nothing to see here - found no items to change.
            | Checking for items you can safely ignore...
            ○ Found! You have safely ignored: .DS_Store, Thumbs.db
            | Checking for items to ignore if you build the site on Netlify...
            ○ Found! You have safely ignored: /resources/, /public/
            | Checking for files required by blogdown but not committed...
            ○ Great! Did not find such files.
            ― Check complete: .gitignore
            
            ― Checking Hugo
            | Checking Hugo version...
            ○ Found 3 versions of Hugo. You are using Hugo 0.101.0.
            | Checking .Rprofile for Hugo version used by blogdown...
            ○ blogdown is using Hugo 0.101.0 to build site locally.
            ― Check complete: Hugo
            
            ― Checking netlify.toml...
            ○ Found HUGO_VERSION = 0.101.0 in [build] context of netlify.toml.
            | Checking that remote & local Hugo versions match...
            ○ It's a match! Local and remote Hugo versions are identical (0.101.0).
            | Checking that Netlify & local Hugo publish directories match...
            ○ Good to go - blogdown and Netlify are using the same publish directory: public
            ― Check complete: netlify.toml
            
            ― Checking content files
            | Checking for validity of YAML metadata in posts...
            ○ All YAML metadata appears to be syntactically valid.
            | Checking for previewed content that will not be published...
            ○ Found 0 files with future publish dates.
            ○ Found 0 files marked as drafts.
            | Checking your R Markdown content...
            ○ All R Markdown files have been knitted.
            ○ All R Markdown output files are up to date with their source files.
            | Checking for .html/.md files to clean up...
            ● [TODO] Found 1 duplicate output file:
            
              content/post/2022-04-23-choropleth-map/index.html
            
              To fix, run blogdown::clean_duplicates(preview = FALSE).
            ○ Found 0 incompatible .html files to clean up.
            | Checking for the unnecessary 'content/' directory in theme...
            ○ Great! Your theme does not contain the content/ directory.
            ― Check complete: Content

            Cloud2016
            哦,那你之前是怎么直接新建出来 index.rmd 的呢?

            益辉现在的美国时间还是周末,要明天才会出来打工呢,那我就等着吧。

              yuanfan 预览窗口出现白板可能是 Hugo 挂掉了,你需要安装开发版 blogdown

              remotes::install_github('rstudio/blogdown')

              具体原因见帖子 https://d.cosx.org/d/423509

              @yihui 顺便一提,我之前提的这个问题,影响面应该很大的,我注意到除了我还有不少人使用 Rmd 文档写博客,特别是外国人,但是,我也奇怪为什么只有我提出来了。

                Cloud2016

                预览窗口出现白板可能是 Hugo 挂掉了

                在往主站投稿之前,我已经先在我自己的博客里弄过一次,能够正常预览。我的博客原来的hugo版本是 0.81.0,今天操作投稿时,先让我更新到了 0.101.0,如果是hugo挂掉了的话,有没有可能是这个0.101.0版本的问题?

                  Cloud2016
                  湘云呐,几个月前你让我看这本Git 常识书的前4章,我就真得只看过前4章,Git子模块出现在第7章,所以我之前确实不知道还要克隆撒子模块……

                  我把克隆仓库、创建新分支、提交新的PR的流程写在本帖二楼了,我克隆仓库的代码仅仅只是

                  git clone git@github.com:earfanfan/cosx.org.git

                  所以,编辑部撒时候把投稿指南里面加上 rmd 格式投稿的内容呢?

                    Cloud2016 这个问题我两年前就已经在 blogdown 中修正了,点 Knit 按钮是可以的(尽管我并不太推荐)。问题只是我们的这个库没有设定 RStudio 项目类型,我刚加上了blogdown::check_site() 也会指出这个问题。

                    楼主需要合并一下 cosname/cosx.org 的主分支并重启 RStudio,不过这也不是什么大问题,不合并也行。手工修改文件名完全是可以的。

                    yuanfan > blogdown:::new_post_addin()

                    Listening on http://127.0.0.1:3198
                    Warning in file(con, "r") :
                    cannot open file 'Content "D:\\R\\myblog\\cos\\cosx.org\\content\\post\\2022-10-30-dt-manual-for-me\\index.md"/index.md': Invalid argument
                    Warning: Error in file: cannot open the connection

                    这个问题我去年就修正了。楼主的 blogdown 版本可能太老了?

                    Cloud2016 顺便一提,我之前提的这个问题,影响面应该很大的,我注意到除了我还有不少人使用 Rmd 文档写博客,特别是外国人,但是,我也奇怪为什么只有我提出来了。

                    影响面应该没那么大,这种百科全书式的写作风格还是相对少见的,多数人的 Rmd 文档应该都不会很复杂。一会儿我会往 CRAN 更新一下 blogdown。在它到达 CRAN 之前,楼主需要安装开发版本的 blogdown,如果是用 Windows,最好也安装 processx 包:

                    install.packages("blogdown", repos = "https://rstudio.r-universe.dev")
                    install.packages("processx")

                      我原来的R版本是4.2.0,因为要安装新的blogdown,要求我把R升级到4.2.1,但是R升级以后,重新安装blogdown又报错了……主要是'digest', 'jsonlite', 'markdown', 'xfun', 'yaml'这几个包安装报错。

                      [1/6] Installing digest...
                      
                      
                        有二进制版本的,但源代码版本是后来的:
                             binary source needs_compilation
                      digest 0.6.29 0.6.30              TRUE
                      
                      安装源码包'digest'
                      
                      试开URL’https://cran.rstudio.com/src/contrib/digest_0.6.30.tar.gz'
                      Content type 'application/x-gzip' length 163424 bytes (159 KB)
                      ==================================================
                      downloaded 159 KB
                      
                      * installing *source* package 'digest' ...
                      ** package 'digest' successfully unpacked and MD5 sums checked
                      ** using staged installation
                      ** libs
                      g++  -std=gnu++11 -I"D:/R/R-4.2.1/include" -DNDEBUG     -I"c:/rtools42/x86_64-w64-mingw32.static.posix/include"     -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -c SpookyV2.cpp -o SpookyV2.o
                      sh: g++: command not found
                      make: *** [D:/R/R-4.2.1/etc/x64/Makeconf:260: SpookyV2.o] Error 127
                      ERROR: compilation failed for package 'digest'
                      * removing 'D:/R/R-4.2.1/library/digest'
                      
                      
                      [2/6] Installing jsonlite...
                      
                      
                      下载的程序包在
                      	'C:\Users\fanfan\AppData\Local\Temp\RtmpsPjKko\downloaded_packages'里
                      
                        有二进制版本的,但源代码版本是后来的:
                               binary source needs_compilation
                      jsonlite  1.8.2  1.8.3              TRUE
                      
                      安装源码包'jsonlite'
                      
                      试开URL’https://cran.rstudio.com/src/contrib/jsonlite_1.8.3.tar.gz'
                      Content type 'application/x-gzip' length 1053099 bytes (1.0 MB)
                      ==================================================
                      downloaded 1.0 MB
                      
                      * installing *source* package 'jsonlite' ...
                      ** package 'jsonlite' successfully unpacked and MD5 sums checked
                      ** using staged installation
                      ** libs
                      gcc  -I"D:/R/R-4.2.1/include" -DNDEBUG -Iyajl/api    -I"c:/rtools42/x86_64-w64-mingw32.static.posix/include"   -D__USE_MINGW_ANSI_STDIO   -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mstackrealign  -c base64.c -o base64.o
                      sh: gcc: command not found
                      make: *** [D:/R/R-4.2.1/etc/x64/Makeconf:253: base64.o] Error 127
                      
                      
                      [3/6] Installing commonmark...
                      
                      ERROR: compilation failed for package 'jsonlite'
                      * removing 'D:/R/R-4.2.1/library/jsonlite'
                      
                      下载的程序包在
                      	'C:\Users\fanfan\AppData\Local\Temp\RtmpsPjKko\downloaded_packages'里
                      
                        有二进制版本的,但源代码版本是后来的:
                                 binary source needs_compilation
                      commonmark  1.8.0  1.8.1              TRUE
                      
                      安装源码包'commonmark'
                      
                      试开URL’https://cran.rstudio.com/src/contrib/commonmark_1.8.1.tar.gz'
                      Content type 'application/x-gzip' length 139636 bytes (136 KB)
                      ==================================================
                      downloaded 136 KB
                      
                      * installing *source* package 'commonmark' ...
                      ** package 'commonmark' successfully unpacked and MD5 sums checked
                      ** using staged installation
                      rm -f cmark/cmark.o cmark/node.o cmark/iterator.o cmark/blocks.o cmark/inlines.o cmark/scanners.o cmark/utf8.o cmark/buffer.o cmark/references.o cmark/render.o cmark/man.o cmark/xml.o cmark/html.o cmark/commonmark.o cmark/latex.o cmark/houdini_href_e.o cmark/houdini_html_e.o cmark/houdini_html_u.o cmark/cmark_ctype.o cmark/arena.o cmark/linked_list.o cmark/plugin.o cmark/registry.o cmark/syntax_extension.o cmark/plaintext.o cmark/footnotes.o cmark/map.o extensions/autolink.o extensions/core-extensions.o extensions/ext_scanners.o extensions/strikethrough.o extensions/table.o extensions/tagfilter.o extensions/tasklist.o extensions.o init.o wrapper.o commonmark.dll cmark/libstatcmark.a
                      ** libs
                      gcc  -I"D:/R/R-4.2.1/include" -DNDEBUG -Icmark -I. -DCMARK_GFM_STATIC_DEFINE -DCMARK_GFM_EXTENSIONS_STATIC_DEFINE -DR_NO_REMAP -DSTRICT_R_HEADERS    -I"c:/rtools42/x86_64-w64-mingw32.static.posix/include"     -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mstackrealign  -c extensions.c -o extensions.o
                      sh: gcc: command not found
                      make: *** [D:/R/R-4.2.1/etc/x64/Makeconf:253: extensions.o] Error 127
                      
                      
                      [4/6] Installing xfun...
                      
                      ERROR: compilation failed for package 'commonmark'
                      * removing 'D:/R/R-4.2.1/library/commonmark'
                      
                      下载的程序包在
                      	'C:\Users\fanfan\AppData\Local\Temp\RtmpsPjKko\downloaded_packages'里
                      
                        有二进制版本的,但源代码版本是后来的:
                           binary source needs_compilation
                      xfun   0.33   0.34              TRUE
                      
                      安装源码包'xfun'
                      
                      试开URL’https://cran.rstudio.com/src/contrib/xfun_0.34.tar.gz'
                      Content type 'application/x-gzip' length 128092 bytes (125 KB)
                      ==================================================
                      downloaded 125 KB
                      
                      * installing *source* package 'xfun' ...
                      ** package 'xfun' successfully unpacked and MD5 sums checked
                      ** using staged installation
                      gcc  -I"D:/R/R-4.2.1/include" -DNDEBUG     -I"c:/rtools42/x86_64-w64-mingw32.static.posix/include"     -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mstackrealign  -c base64.c -o base64.o
                      ** libs
                      sh: gcc: command not found
                      make: *** [D:/R/R-4.2.1/etc/x64/Makeconf:253: base64.o] Error 127
                      
                      
                      [5/6] Installing markdown...
                      
                      ERROR: compilation failed for package 'xfun'
                      * removing 'D:/R/R-4.2.1/library/xfun'
                      
                      下载的程序包在
                      	'C:\Users\fanfan\AppData\Local\Temp\RtmpsPjKko\downloaded_packages'里
                      还安装相依关系'commonmark', 'xfun'
                      
                      
                        有二进制版本的,但源代码版本是后来的:
                                 binary source needs_compilation
                      commonmark  1.8.0  1.8.1              TRUE
                      xfun         0.33   0.34              TRUE
                      markdown      1.1    1.3              TRUE
                      
                      安装源码包'commonmark', 'xfun', 'markdown'
                      
                      试开URL’https://cran.rstudio.com/src/contrib/commonmark_1.8.1.tar.gz'
                      Content type 'application/x-gzip' length 139636 bytes (136 KB)
                      ==================================================
                      downloaded 136 KB
                      
                      试开URL’https://cran.rstudio.com/src/contrib/xfun_0.34.tar.gz'
                      Content type 'application/x-gzip' length 128092 bytes (125 KB)
                      ==================================================
                      downloaded 125 KB
                      
                      试开URL’https://cran.rstudio.com/src/contrib/markdown_1.3.tar.gz'
                      Content type 'application/x-gzip' length 44590 bytes (43 KB)
                      ==================================================
                      downloaded 43 KB
                      
                      * installing *source* package 'commonmark' ...
                      ** package 'commonmark' successfully unpacked and MD5 sums checked
                      ** using staged installation
                      ** libs
                      rm -f cmark/cmark.o cmark/node.o cmark/iterator.o cmark/blocks.o cmark/inlines.o cmark/scanners.o cmark/utf8.o cmark/buffer.o cmark/references.o cmark/render.o cmark/man.o cmark/xml.o cmark/html.o cmark/commonmark.o cmark/latex.o cmark/houdini_href_e.o cmark/houdini_html_e.o cmark/houdini_html_u.o cmark/cmark_ctype.o cmark/arena.o cmark/linked_list.o cmark/plugin.o cmark/registry.o cmark/syntax_extension.o cmark/plaintext.o cmark/footnotes.o cmark/map.o extensions/autolink.o extensions/core-extensions.o extensions/ext_scanners.o extensions/strikethrough.o extensions/table.o extensions/tagfilter.o extensions/tasklist.o extensions.o init.o wrapper.o commonmark.dll cmark/libstatcmark.a
                      gcc  -I"D:/R/R-4.2.1/include" -DNDEBUG -Icmark -I. -DCMARK_GFM_STATIC_DEFINE -DCMARK_GFM_EXTENSIONS_STATIC_DEFINE -DR_NO_REMAP -DSTRICT_R_HEADERS    -I"c:/rtools42/x86_64-w64-mingw32.static.posix/include"     -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mstackrealign  -c extensions.c -o extensions.o
                      sh: gcc: command not found
                      make: *** [D:/R/R-4.2.1/etc/x64/Makeconf:253: extensions.o] Error 127
                      ERROR: compilation failed for package 'commonmark'
                      * removing 'D:/R/R-4.2.1/library/commonmark'
                      * installing *source* package 'xfun' ...
                      ** package 'xfun' successfully unpacked and MD5 sums checked
                      ** using staged installation
                      gcc  -I"D:/R/R-4.2.1/include" -DNDEBUG     -I"c:/rtools42/x86_64-w64-mingw32.static.posix/include"     -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mstackrealign  -c base64.c -o base64.o
                      ** libs
                      sh: gcc: command not found
                      make: *** [D:/R/R-4.2.1/etc/x64/Makeconf:253: base64.o] Error 127
                      ERROR: compilation failed for package 'xfun'
                      * removing 'D:/R/R-4.2.1/library/xfun'
                      
                      
                      [6/6] Installing yaml...
                      
                      ERROR: dependencies 'commonmark', 'xfun' are not available for package 'markdown'
                      * removing 'D:/R/R-4.2.1/library/markdown'
                      
                      下载的程序包在
                      	'C:\Users\fanfan\AppData\Local\Temp\RtmpsPjKko\downloaded_packages'里
                      
                        有二进制版本的,但源代码版本是后来的:
                           binary source needs_compilation
                      yaml  2.3.5  2.3.6              TRUE
                      
                      安装源码包'yaml'
                      
                      试开URL’https://cran.rstudio.com/src/contrib/yaml_2.3.6.tar.gz'
                      Content type 'application/x-gzip' length 94304 bytes (92 KB)
                      ==================================================
                      downloaded 92 KB
                      
                      * installing *source* package 'yaml' ...
                      ** package 'yaml' successfully unpacked and MD5 sums checked
                      ** using staged installation
                      gcc  -I"D:/R/R-4.2.1/include" -DNDEBUG -I. -DNDEBUG    -I"c:/rtools42/x86_64-w64-mingw32.static.posix/include"     -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mstackrealign  -c api.c -o api.o
                      ** libs
                      sh: gcc: command not found
                      make: *** [D:/R/R-4.2.1/etc/x64/Makeconf:253: api.o] Error 127
                      ERROR: compilation failed for package 'yaml'
                      * removing 'D:/R/R-4.2.1/library/yaml'
                      
                      下载的程序包在
                      	'C:\Users\fanfan\AppData\Local\Temp\RtmpsPjKko\downloaded_packages'里
                      
                      
                      ✔ Packages successfully installed.
                      Warning messages:
                      1: In utils::install.packages("digest", repos = "https://cran.rstudio.com/") :
                        安装程序包'digest'时退出狀態的值不是0
                      2: In utils::install.packages("jsonlite", repos = "https://cran.rstudio.com/") :
                        安装程序包'jsonlite'时退出狀態的值不是0
                      3: In utils::install.packages("commonmark", repos = "https://cran.rstudio.com/") :
                        安装程序包'commonmark'时退出狀態的值不是0
                      4: In utils::install.packages("xfun", repos = "https://cran.rstudio.com/") :
                        安装程序包'xfun'时退出狀態的值不是0
                      5: In utils::install.packages("markdown", repos = "https://cran.rstudio.com/") :
                        安装程序包'commonmark'时退出狀態的值不是0
                      6: In utils::install.packages("markdown", repos = "https://cran.rstudio.com/") :
                        安装程序包'xfun'时退出狀態的值不是0
                      7: In utils::install.packages("markdown", repos = "https://cran.rstudio.com/") :
                        安装程序包'markdown'时退出狀態的值不是0
                      8: In utils::install.packages("yaml", repos = "https://cran.rstudio.com/") :
                        安装程序包'yaml'时退出狀態的值不是0