如何显示另一个 html 文档来代替标准博客 post?

How to display another html document in place of a standard blog post?

我有一个使用 R Blogdown 更新的博客。它有一个带有 YAML 配置和前端的 Hugo 主题。我在 Netlify 上主持。我想创建一个 post,在其中单击 post 的 link 后,用户会看到一个完全独立的 html 文件,而不是标题为 post.例如,我认为以下前面的内容会在我将所需文档放在 'static/files'...

中的地方起作用
---
title: 'Example blog post'
author: Logit
date: '2018-02-21'
URL: ["/files/page_to_display_instead.html"]
---

但是我想要的页面没有加载。相反,我的地址栏尝试加载“/posts/2018-02-21-example-blog-post”

我注意到在我的 post 的 body 中包含以下内容完全符合我的要求,并验证了我的相对路径、文件名和所需页面是否正确...

Click [here](/files/page_to_display_instead.html) to see the right page.

但这需要用户额外点击才能访问内容,而且不是很优雅。

同样,将以下内容放在上面 post 的 body 中接近工作...

![](/files/page_to_display_instead.html)

但是这个解决方案保留了博客标题和主题,只是在一个框架内显示了我想要的页面。有点丑。

必须有一个简单的解决方案来加载或重定向到所需的页面,而不是标题为 post 本身。我是否误解了 Hugo 的 "URL" 变量在我的前言中的使用?我应该使用另一个 front matter 变量或语法吗?提前感谢您的任何建议。

编辑:除了 Sebastien Rochette 在下面的出色回答之外,我发现由于我在 R Markdown 中工作,以下内容也解决了这个问题:

```{r, include=FALSE}
shiny::includeHTML("/files/page_to_display_instead.html") 
```

我觉得直接把你的html文件放在blog文件夹里就可以直接显示了。 html 文件的名称将用作 slug。但是,如果您的 html 页面不包含您的模板,您可能不需要它。

使用 iframe

因此,您可以将 html 文件添加为 iframe:

---
title: 'Example blog post'
author: Logit
date: '2018-02-21'
---

<iframe width="100%" height="150" name="iframe" src="/files/page_to_display_instead.html"></iframe>

自动调整 iframe 大小以适应内容

如果您不希望访问者将其视为 iframe,您可以使用一些 javascript 来自动调整 iframe 的大小。
您需要在主题的 "head" 中添加:

<script>
  function resizeIframe(obj) {
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
  }
</script>

那么您的 post 将是:

---
title: 'Example blog post'
author: Logit
date: '2018-02-21'
---

<iframe width="100%" height="150" name="iframe" src="/files/page_to_display_instead.html" frameborder="0" scrolling="no" onload="resizeIframe(this)"></iframe>