gpt4 book ai didi

jekyll - 如何将 Jekyll 内容置于多列布局中?

转载 作者:行者123 更新时间:2023-12-04 14:58:08 25 4
gpt4 key购买 nike

如何在 Markdown 文件中的特定部分周围放置标记?例如在两个列表周围放置 div,然后在其余内容周围放置另一个 div。

以此为例:

Markdown

* Eggs
* Flour
* Sugar

Text goes here

输出
<div class="section1">
<ul>
<li>Eggs</li>
<li>Flour</li>
<li>Sugar</li>
</ul>

<div class="section2">
<p>Text goes here</p>
</div>

最佳答案

我猜你想要这样的东西:

首先,为您不想显示成分和准备的页面创建一个“常规”布局文件:
/_layouts/default.html :

<!DOCTYPE html>
<html>
<head>
<title>{{ page.title }}</title>
</head>
<body>

<h1>{{ page.title }}</h1>

{{ content }}

</body>
</html>

这里没什么特别的,只是一个非常基本的布局文件。

然后,您实际要显示食谱的页面的第二个布局文件:
(我将其称为“食谱”,因为“配料”和“准备”听起来像是您正在建立一个关于 cooking 的网站)
/_layouts/recipe.html :
---
layout: default
---

<div class="ingredients">
<ul>
{% for item in page.ingredients %}
<li>{{item.name}}</li>
{% endfor %}
</ul>
</div>

<div class="preparation">
{{ content }}
</div>

现在您可以创建这样的页面,您可以在其中将成分列表放入 YAML 前言和内容中的准备中:
---
layout: recipe
title: Cake recipe
ingredients:
- name: sugar
- name: milk
- name: eggs
---

Here's the "how to prepare the cake" text

这将生成以下 HTML:
<!DOCTYPE html>
<html>
<head>
<title>Cake recipe</title>
</head>
<body>

<h1>Cake recipe</h1>

<div class="ingredients">
<ul>
<li>sugar</li>
<li>milk</li>
<li>eggs</li>
</ul>
</div>

<div class="preparation">
Here's the "how to prepare the cake" text
</div>

</body>
</html>

编辑:

关于你的问题:

I'm not sure though if it will work as I need to format the ingredients list with some bolding, e.g.:100ml water and I don't think I can do this in YAML?



您可以在页面的首页分开成分和数量:
---
layout: recipe
title: Cake recipe
ingredients:
- name: sugar
amount: 1 pound
- name: milk
amount: 100ml
- name: eggs
amount: 3
---

Here's the "how to prepare the cake" text

以及新的布局文件 /_layouts/recipe.html :
---
layout: default
---

<div class="ingredients">
<ul>
{% for item in page.ingredients %}
<li>{{item.amount}} <b>{{item.name}}</b></li>
{% endfor %}
</ul>
</div>

<div class="preparation">
{{ content }}
</div>

生成的 HTML:
<!DOCTYPE html>
<html>
<head>
<title>Cake recipe</title>
</head>
<body>

<h1>Cake recipe</h1>

<div class="ingredients">
<ul>
<li>1 pound <b>sugar</b></li>
<li>100ml <b>milk</b></li>
<li>3 <b>eggs</b></li>
</ul>
</div>

<div class="preparation">
Here's the "how to prepare the cake" text
</div>

</body>
</html>

关于jekyll - 如何将 Jekyll 内容置于多列布局中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26045817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com