Jekyll 如何知道它应该为每个特定的 URL 使用什么布局?

发布于 2024-11-29 15:23:28 字数 210 浏览 4 评论 0原文

当我请求 Jekyll 上运行的网站上的特定 URL 时,例如。 www.mysite.com/blog.html Jekyll 如何知道应该呈现什么布局来显示 blog.html?

我曾经使用 Django,其中有 urls.py 文件,它保存成对的 URL 和为每个 URL 呈现的模板。我是 RoR 和 Jekyll 的新手,在 Jekyll 中找不到与 urls.py 类似的东西。

When I request a specific URL on a website ran on Jekyll, eg. www.mysite.com/blog.html how does Jekyll know what layout it should render to display blog.html?

I used to work with Django, where there was urls.py file that kept pairs of URL and templates to render for each URL. I'm new to RoR and Jekyll and couldn't find anything similar to urls.py in Jekyll.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぃ双果 2024-12-06 15:23:28

您可以使用 YAML frontmatter 选择用于特定生成页面的布局。来自 Jekyll 文档

_布局

这些是插入帖子的模板。布局是在 YAML 前面的内容中逐个帖子定义的,这将在下一节中描述。 Liquid 标签 {{ content }} 用于将数据注入到页面上。

[...]

index.html 和其他 HTML/Markdown/Textile 文件

假设这个文件有一个 YAML Front Matter 部分,它将被 Jekyll 转换。对于站点根目录或上面未列出的目录中的任何 .html、.markdown 或 .textile 文件,也会发生同样的情况。

YAML front-matter 是文件顶部的部分,指定该文件的元数据。它看起来像:

---
layout: post
title: Blogging Like a Hacker
---

You can choose which layout to use for a specific generated page using the YAML frontmatter. From the Jekyll documentation:

_layouts

These are the templates which posts are inserted into. Layouts are defined on a post-by-post basis in the YAML front matter, which is described in the next section. The liquid tag {{ content }} is used to inject data onto the page.

[...]

index.html and Other HTML/Markdown/Textile Files

Granted that this file has a YAML Front Matter section, it will be transformed by Jekyll. The same will happen for any .html, .markdown, or .textile file in your site’s root directory or directories not listed above.

The YAML front-matter is a section at the top of a file that specifies metadata for that file. It looks something like:

---
layout: post
title: Blogging Like a Hacker
---
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文