如何从单个降价渲染两个文件
How to render two files from a single markdown
我有一组降价文件,我想在构建页面时使用两个不同的布局文件在两组不同的文件中呈现:
– html 个网站文件
– xml 个文件
这可以吗?貌似一个markdown文件只能解析一次。有什么建议么?非常感谢
浏览使用每种布局的文件中的 markdown 文件,并使用液体过滤器markdownify
在不同的上下文中处理相同的内容。
Markdownify
Convert a Markdown-formatted string into HTML.
{{ page.content | markdownify }}
您不需要指向布局文件的降价文件,而是需要两个指向降价 post 文件的页面。
有许多方法可以指向 post 文件。我喜欢使用 where
过滤器:
{% assign post = site.posts | where:"url", include.url | first %}
现在您有一个 post
,假设您有 fileOne.html
,您想要将 post 放入其中。以下是您的处理方式:
---
layout:main
---
<h1>Some html here</h1>
{% assign post = site.posts | where:"url", include.url | first %}
{{ post.content }}
然后您可以在另一个名为 fileTwo.html
.
的文件中执行完全相同的操作
您可以为此使用 Includes。
注意:您可以将源 Markdown 文件存储在 _includes
文件夹中,然后通过 include
.
将它们包含到其他文件夹中
或者您将它们直接存储在目标文件所在的文件夹中并使用 include_relative
.
我在这里展示的是第一个选项。
这是一个文件,其内容将在另一个文件中结束:
/_includes/foo.md
:
**bold**
[Stack Overflow](https://whosebug.com)
这是包含 foo.md
:
的文件
a) 当它是 Markdown 文件时:
---
layout: default
title: blah
---
This is the "destination file" for the include.
{% include foo.md %}
b) 任何不是 Markdown 的东西:
(如果你想渲染来自 foo.md
的 Markdown,你必须手动执行此操作)
---
layout: default
title: blah
---
<p>This is the "destination file" for the include.</p>
{% capture tmp %}{% include foo.md %}{% endcapture %}
{{ tmp | markdownify }}
两种情况下的结果:
<p>This is the "destination file" for the include.</p>
<p><strong>bold</strong></p>
<p><a href="https://whosebug.com">Stack Overflow</a></p>
我有一组降价文件,我想在构建页面时使用两个不同的布局文件在两组不同的文件中呈现:
– html 个网站文件 – xml 个文件
这可以吗?貌似一个markdown文件只能解析一次。有什么建议么?非常感谢
浏览使用每种布局的文件中的 markdown 文件,并使用液体过滤器markdownify
在不同的上下文中处理相同的内容。
Markdownify
Convert a Markdown-formatted string into HTML.
{{ page.content | markdownify }}
您不需要指向布局文件的降价文件,而是需要两个指向降价 post 文件的页面。
有许多方法可以指向 post 文件。我喜欢使用 where
过滤器:
{% assign post = site.posts | where:"url", include.url | first %}
现在您有一个 post
,假设您有 fileOne.html
,您想要将 post 放入其中。以下是您的处理方式:
---
layout:main
---
<h1>Some html here</h1>
{% assign post = site.posts | where:"url", include.url | first %}
{{ post.content }}
然后您可以在另一个名为 fileTwo.html
.
您可以为此使用 Includes。
注意:您可以将源 Markdown 文件存储在 _includes
文件夹中,然后通过 include
.
将它们包含到其他文件夹中
或者您将它们直接存储在目标文件所在的文件夹中并使用 include_relative
.
我在这里展示的是第一个选项。
这是一个文件,其内容将在另一个文件中结束:
/_includes/foo.md
:
**bold**
[Stack Overflow](https://whosebug.com)
这是包含 foo.md
:
a) 当它是 Markdown 文件时:
---
layout: default
title: blah
---
This is the "destination file" for the include.
{% include foo.md %}
b) 任何不是 Markdown 的东西:
(如果你想渲染来自 foo.md
的 Markdown,你必须手动执行此操作)
---
layout: default
title: blah
---
<p>This is the "destination file" for the include.</p>
{% capture tmp %}{% include foo.md %}{% endcapture %}
{{ tmp | markdownify }}
两种情况下的结果:
<p>This is the "destination file" for the include.</p>
<p><strong>bold</strong></p>
<p><a href="https://whosebug.com">Stack Overflow</a></p>