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

给你一囗甜甜゛ 提交于 2019-12-04 09:27:24

I think that you can directly show your html file if you put it directly in the blog folder. The name of the html file would be used as the slug. However, if your html page does not contain your template, you may not want that.

Use iframe

Hence, you can add your html file as an 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>

Auto resize iframe to fit content

And if you do not want that your visitors see it as an iframe, you can use some javascript to auto resize the iframe.
You need to add this in the "head" of your theme:

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

Then your post will be:

---
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>

Interesting suggestion with iframes... it does not work for me when embedding youtube content into an iframe:

https://blogs.nopcode.org/brainstorm/2016-06-10-the-right-to-repair-my-drone/

It stops rendering right in the iframe code, here you can see the source Markdown that used to work with my previous Jekyll installation before migrating to blogdown:

https://github.com/brainstorm/brainblog/blob/master/content/brainstorm/2016-06-10-the-right-to-repair-my-drone.md

Any hints on how to solve it (hopefully without changing all my blogposts) is super welcome!

EDIT: The standard blogdown way to embed youtube videos generates worrying messanges in the browser console:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!