【问题标题】:blogdown `title` won't display on rendered `_index.html`blogdown `title` 不会显示在渲染的 `_index.html` 上
【发布时间】:2019-01-02 14:30:12
【问题描述】:

我在我的 blogdown /*/content/ 目录中创建了一个 _index.Rmd 文件,_index.Rmd 文件的正文如下所示:

---
title: "Home"
date: "2016-05-05T21:48:51-07:00"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

Welcome to the home page of this blogdown site.

我希望看到“主页”标题,但什么也没有出现。我认为这是一个有意的设计选择。我可以理解为什么,但就我而言,我希望在 YAML 中指定的标题显示在呈现的 _index.html 文件上。我该如何实现这个目标?

【问题讨论】:

  • 根据author's R series book 调整config.toml 文件中的标题。
  • 我的config.toml 中的 TOML 确实指定了title = "Home",但这只会更改 Chrome 选项卡(或 Firefox 选项卡)上的标题。它不会在我的 _index.html 文件中插入“主页”标题。
  • 我相信建议不要触摸渲染的.html 文件。可能会运行一些GO 语言进程来呈现每个主题的标题、页脚、侧边栏等。如果你得到你的渲染输出,为什么你需要在.html文件中看到它?
  • 嗯...所以About 出现(不是在标签上而是在网页顶部)但不是Home 并且两者都有相同的R 降价?我将在我的 blogdown 设置上循环测试。索引页可能会发生特殊映射。
  • 在这种情况下,为标题嵌入原始 html 代码,然后您可以指定字体大小和内容。例如,<h2 id="title" style=" font-size: 2em; ">Put Your super fancy home title here</h2>

标签: r r-markdown blogdown


【解决方案1】:

这是因为索引(主)页面对此主题进行了特殊处理。如何更改此设置是转到 themes/(yourtheme)/layouts/index.html。它看起来像:

{{ partial "header.html" . }}

<main class="content">

  <div class="list">
     {{ range (.Paginate ((where .Data.Pages "Type" "post").GroupByDate "2006")).PageGroups }}    
  <h2 class="list-title">{{ .Key }}</h2>
    {{ range .Pages }}

    {{ partial "list-item.html" . }}

    {{ end }}
    {{ end }}
  </div>  

  {{ partial "pagination.html" . }}

</main>

{{ partial "footer.html" . }}

现在您可以编辑此文件以通过多种方式添加所需的标题,例如,如果您想要与帖子标题相同的样式,您可以在 &lt;main class="content"&gt;&lt;div class="list&gt; 之间添加:

<h1 class="article-title">Home</h1>

如果您想从 .Rmd 文件中获取标题,您可以这样做:

<h1 class="article-title">{{ .Title }}</h1>

现在重建网站后,标题将出现在主页上。

【讨论】:

    猜你喜欢
    • 2021-06-10
    • 1970-01-01
    • 2021-02-06
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    相关资源
    最近更新 更多