页面文件
Lume 如何根据源文件结构生成你的站点
页面是你的站点中被加载、处理和保存的文件。你可以使用不同的格式创建页面(md
、js
、ts
、jsx
、tsx
、yml
等),但最简单的方法是在根目录下添加一个 Markdown 文件,并使用合适的文件名和 .md
扩展名。Lume 将加载这些文件并使用它们生成 HTML 页面:
.
├── index.md => /index.html
├── about.md => /about/index.html
└── contact.md => /contact/index.html
你可以将页面组织到子目录中,此结构将用于站点构建的输出中:
.
├── index.md => /index.html
└── documentation
└── doc1.md => /documentation/doc1/index.html
└── doc2.md => /documentation/doc2/index.html
漂亮的 URL (Pretty URLs)
默认情况下,所有 HTML 页面(/404.html
除外)都将生成漂亮的 URL(不带 .html
扩展名的 URL)。这意味着,URL 不是 /about-us.html
,而是 /about-us/
。这是通过将所有文件保存为 index.html
并根据需要创建所有目录来完成的。
如果你想禁用它,请在 配置文件 中将 prettyUrls
设置为 false
, 这样你将得到如下结果:
.
├── index.md => /index.html
└── documentation
└── doc1.md => /documentation/doc1.html
└── doc2.md => /documentation/doc2.html
404.html
页面 /404.html
是一个特例,漂亮的 URL 不适用于此。原因是大多数服务器和静态托管网站,如 Vercel、 Netlify、 GitHub Pages 等,默认配置为在请求的文件不存在时提供 /404.html
页面。这几乎是服务静态网站时的标准。
漂亮的 URL 选项会将 404 页面转换为 /404/index.html
,这与服务 404 页面的标准方式相冲突,因此它被禁用。请注意,你可以通过在页面的 front matter 中显式设置 url
变量来更改此行为。
页面日期
所有页面都有一个 date
变量,其中包含文件创建日期。此值可用于对页面进行排序(例如在博客中)。如果你想定义不同的日期,你可以使用 yyyy-mm-dd
语法将其前置到文件名,后跟连字符 -
或下划线 _
(如果还需要时间,则使用 yyyy-mm-dd-hh-ii-ss
)。请注意,在生成最终 URL 时,这部分会被删除:
.
├── index.md => /index.html
└── posts
└── 2020-06-21_hello-world.md => /posts/hello-world/index.html
└── 2020-06-22_my-second-post.md => /posts/my-second-post/index.html
日期可以在文件夹中定义,因此它由内部的所有页面共享:
.
├── index.md => /index.html
└── posts
└── 2020-06-21_hello-world/
└── index.md => /posts/hello-world/index.html
└── other.md => /posts/hello-world/other/index.html
更改输出 URL
你可能希望源文件具有特定的目录结构,该结构与构建的站点不同。通过 url
变量,你可以更改任何页面的输出文件名(请参阅 页面数据)。