如何在Hugo/Markdown页面中包含另一个文件? [英] How can another file be Included in a Hugo/Markdown page?

查看:942
本文介绍了如何在Hugo/Markdown页面中包含另一个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我重新开发了一个网站.重新制作的网站将在 Markdown 中完成,并通过

Recently the re-development of a web site was given to me. The re-worked site is to be done in Markdown and run through the Hugo static site generator.

是否有一种方法可以将其他文件包含在通过Hugo处理的Markdown网页中?如果是这样,怎么办?除非我错过了一些东西,否则 Hugo文档中不会解决.

Is there a way to include other files in a Markdown web page processed through Hugo? If so, how? Unless I've missed something, this isn't addressed in the Hugo docs.

使用HTML和某些服务器(至少是Apache),您可以执行以下操作:

With HTML and some servers (Apache, at least) you can do something like:

<html>
<body>
Some content
<!--#include virtual="name_of_first_file_to_include" -->
More content
<!--#include virtual="name_of_second_file_to_include" -->
Still more content
</body>
<html>

我尝试创建一个模板页面,该页面将诸如某些内容"和更多内容"之类的内容放入模板中,然后将包含在我的.md文件中的内容通过{{.Content}}包含在".include"中模板.但是,1)这似乎是使用模板的错误方法. 2)如果我需要更多文件,我还没有找到一种方法.

I've tried creating a template page which puts stuff like "Some content" and "More content" into the template and then the included stuff in my .md file which gets "included" via {{ .Content }} in the template. However, 1) That seems like the wrong way to use a template. 2) I've not figured out a way to bring in more files if I need them.

推荐答案

对于内容文件,有两个选项:

For content files there are two options:

  1. 简码.强大且有据可查.
  2. 使用mmark作为其include功能的降价渲染引擎.将内容文件重命名为"* .mmark".参见 https://github.com/miekg/mmark
  1. Shortcodes. Powerful and documented.
  2. Use mmark as the markdown rendering engine with its include feature. Rename the content files to "*.mmark". See https://github.com/miekg/mmark

我是雨果的维护者.

这篇关于如何在Hugo/Markdown页面中包含另一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆