如何在 .Rmd 的 hugo-academic 中为 post 创建图像预览?

How to create an image preview for a post in hugo-academic from .Rmd?

我正在尝试使用 hugo-academic 将图像预览添加到 post 并使用 blogdown 从 .Rmd 进行编译,但我不知道在 YAML 序言中要做什么。

一些相关的post没有提供解决方案的有:

-

-

Hugo-academic 希望在 TOML 序言中使用:

---
[header]
image="path"
---

根据 blogdown book,这是 TOML 中的 table。但是方括号似乎是 YAML 中的流量控制运算符,用反斜杠转义它们会停止对编译的抱怨,但不会导致预期的行为; image: "path" 显然被忽略了,因为任何字符串都可以替换 "path" 而不会改变行为。至少 bookdown 将图像放在 public/img/headers.

中的正确位置

那我错过了什么?从 .Rmd 开始时,如何在 hugo-academic 中获得 post 的图像预览?

[]toml 的内容 header 可以在 yaml 中不加括号但后面的参数缩进。
在你的情况下,使用 academic 主题,一个 YAML header 需要写成如下(记住路径是相对于 static/img/ 文件夹):

---
title: "Posts"
date: 2017-01-01
math: false
highlight: false
header:
  image: ""
  caption: ""
---

exampleSitegetting-started 文件另存为 Rmd 文件将具有以下 YAML header(我测试过它并且有效):

---
date: 2016-04-20
lastmod: 2017-09-03
draft: false
tags: ["academic", "hugo"]
title: "Getting started with the Academic framework for Hugo"
math: true
summary: "Create a beautifully simple personal or academic website in under 10 minutes."
header:
  image: "headers/getting-started.png"
  caption: "Image credit: [**Academic**](https://github.com/gcushen/hugo-academic/)"
---

我遇到了与 Hugo-Academic 主题相同的问题,上述解决方案对我不起作用。

这是我的 YAML header 我的 .Rmd 文件,我的 pizza.jpgstatic/img/ 文件夹中。

如您所见,没有显示预览图像:

但是,您确实项目中看到此图像:

如何使用 academic 主题正确获取图像 previews

You can check out my repo (https://github.com/moldach/moldach.github.com) if you want... but I tried to provide enough information here for posterity-sake as it will change in the future.

请注意"Getting Started with..."项目旁边的项目图片预览仅工作是因为它们是指向 .md 而非 .Rmd

中的外部网站的链接

已解决:

好的,错误是您需要 preview_only:(而不是 image_preview:)并注意 [=20= 下的正确缩进(2 space 条命中) ].

确保您有 Rmd 和预览图像(名为 featured.jpg/featured.png 位于 project 文件夹中的一个 子文件夹 像这样:

可能最好是 copy-paste,因为 YAML 对适当的间距很挑剔:

---
title: 'Shiny Dev and Software Release Cycles and Rayshader, Oh My!'
summary: ''
author: "Matthew J. Oldach"
tags: []
categories: []
date: "2019-11-23"
featured: false
draft: false

# Featured image
# To use, add an image named `featured.jpg/png` to your page's folder.
# Focal points: Smart, Center, TopLeft, Top, TopRight, Left, Right, BottomLeft, Bottom, BottomRight.
image:
  caption: ""
  focal_point: ""
  preview_only: true

# Projects (optional).
#   Associate this post with one or more of your projects.
#   Simply enter your project's folder or file name without extension.
#   E.g. `projects = ["internal-project"]` references `content/project/deep-learning/index.md`.
#   Otherwise, set `projects = []`.
projects: []
---

关于您的问题,唯一对我有用的方法是将 .rmd 文件重命名为 index.rmd。这解决了我所有的问题 ;-)