3个不稳定版本
0.2.0 | 2021年10月17日 |
---|---|
0.1.1 | 2020年6月11日 |
0.1.0 | 2020年6月11日 |
#182 在 模板引擎
55KB
1K SLoC
Pagong 
无聊简单的静态网站生成器
你想要一个网站,但手动编写HTML很糟糕。我明白。但这不是问题!随意编写Markdown,运行pagong
,然后快速获得你漂亮的HTML,准备好上传到你的托管服务!
入门
安装
在终端运行以下命令来安装pagong
cargo install --git https://github.com/expectocode/pagong
然后在你的博客根目录下使用它
pagong
就这么简单!
博客结构
为了使pagong
发挥作用,你需要为你的博客准备一些条目。这些应该用Markdown编写,并保存到content/
目录中的.md
文件中。例如
myblog/
└── content/
└── hello-world.md
在myblog
目录内运行pagong
将创建以下dist/
文件夹,并且你的博客结构现在看起来像这样
myblog/
├── content/
│ └── hello-world.md
└── dist/
└── hello-world/
└── index.html
现在你可以将dist/
的内容移动到你的网站托管位置,并享受它。
自定义
元数据
你的.md
文件可能包含以下语法在顶部
```meta
key = value
```
**Markdown** content follows as usual…
带有meta
语言的代码块必须是文件中的第一个Markdown元素。支持的关键字有
title
:文章标题(例如“你好,世界!”)。如果未指定,则将使用文档中的第一个标题作为标题。如果没有第一个标题,则使用文件名。date
:发布日期,YYYY-MM-DD
(年、月、日)格式(例如“2020-02-20”)。如果未指定,则使用文件的创建日期。如果无法获取,则使用当前日期。updated
:更新日期,YYYY-MM-DD
格式。如果未指定,则使用文件的修改日期。如果无法获取,则使用date
。category
:帖子所属的分类(例如“计算机科学”)。如果未指定,将使用父文件夹名称(例如“博客”)。tags
:以逗号分隔的标签列表(例如“rust, ssg”)。如果未指定,将生成一个空标签列表。template
:用作此文件模板的HTML文件的路径,UNIX风格路径,相对于当前文件的位置(例如“/ _blog.html”或“../_template.html”)。
任何其他键将由pagong
忽略,但可用于您的需求。
CSS
任何.css
文件将被复制到dist/
,而任何.md
文件将加载同一目录或其上级目录中的所有.css
文件。
myblog/
└── content/
├── index.md
├── sitewide.css
└── blog/
├── hello-world.md
└── blogwide.css
为index.md
生成的HTML将使用sitewide.css
,为hello-world.md
生成的HTML将包含sitewide.css
然后是blogwide.css
。
HTML
任何.html
文件将原样复制到dist/
,但任何.md
文件的元数据中提到的文件除外。如果hello-world.md
包含template = /templates/base.html
,则base.html
不会原样复制,而是用作模板。鼓励您遵循自己的约定来放置模板或命名模板。
用作模板的HTML文件提供了一些非常基本的“预处理器”规则
This comment will tell pagong to insert the generated HTML in this spot:
<!--P/ CONTENTS /P-->
This comment will tell pagong to insert references to any CSS files in this spot:
<!--P/ CSS /P-->
This comment will tell pagong to automatically generate a Table of Contents for the current page (based on Markdown headings). You may optionally set the maximum depth:
<!--P/ TOC /P-->
<!--P/ TOC 3 /P-->
This comment will tell pagong to automatically generate a list of files in the given path (relative to the current markdown file). You may optionally sort by a meta key in either asc-ending or desc-ending order. You may optionally set a maximum depth. You may optionally skip certain relative URIs. You may combine all of these settings:
<!--P/ LIST path /P-->
<!--P/ LIST path sort updated desc /P-->
<!--P/ LIST path depth 2 /P-->
<!--P/ LIST path skip index.html skip secret.html /P-->
This comment will get replaced with whatever was put in the specified metadata key (in this example, the title):
<!--P/ META title /P-->
This comment will get replaced with the contents of whatever path is specified (relative to the current markdown file). HTML files won't be escaped, but everything else will:
<!--P/ INCLUDE path /P-->
在替换“预处理器”规则时,代码将精确查找字符串<!--P/
和/P-->
,因此请确保不要在之间引入空格。如果任何预处理器规则的值包含空格,请用双引号("
)包围它们。双引号内部允许的转义序列只有\"
,用于转义引号,以及\\
,用于转义反斜杠字符。
A default template.html
file is embedded withing pagong
itself. It will be used when no other template file is specified, in order to generate valid HTML5 (your HTML needs a body, after all).
Feed
任何.atom
文件将被复制到dist/
,但它的根feed
标签将自动填充entry
标签。这里是一个基本的.atom
文件,它可以做到这一点(您可以删除generator
标签)
<feed xml:lang="en">
<title>Example's Blog</title>
<link href="https://example.com/blog/"/>
<generator uri="https://github.com/expectocode/pagong">pagong with atom_syndication</generator>
</feed>
Media
任何其他文件将保持原样复制,路径和名称与content/
目录中的路径和名称相同,不会进行任何处理。
Contributing
该项目提供的功能数量故意较少。欢迎提出有关错误或可能增强的issue和pull请求。新功能或重大更改必须在issue部分进行讨论。未经讨论的新功能pull请求将被拒绝,但欢迎维护自己的分支。
License
Pagong采用Apache License,Version 2.0或MIT许可证,任选其一。
除非您明确声明,否则根据Apache-2.0许可证定义,您有意提交的、旨在包含在此软件包中的任何贡献,应按照上述方式双重授权,不附加任何其他条款或条件。
依赖项
约9.5MB
~228K SLoC