webgen / webgen
用 PHP 编写的静态网站生成器。
dev-master
2018-12-16 19:30 UTC
Requires
- php: >=7.2.0
- czproject/logger: ^0.11.0
- czproject/path-helper: ^4.1
- kukulich/fshl: ^2.1
- latte/latte: ^2.4
- nette/finder: ^2.4
- nette/neon: ^2.4
- nette/robot-loader: ^3.0
- nette/utils: ^2.5
- texy/texy: ^2.9
Requires (Dev)
- nette/tester: ^2.0
This package is auto-updated.
Last update: 2024-08-29 04:50:15 UTC
README
简单的 PHP CLI 静态网站生成器。
特性
用法
$ cd examples/basic
$ php -f ../../webgen.php -- --run
$ cd output
$ ls
articles index.html
注意: Webgen 忽略文件名以 @ 开头的文件。
模板化
在 Latte 模板中使用 Texy
{block |texy} This is **Texy** snippet. {/block} {texy} This is "Texy":https://texy.info snippet too. {/texy}
获取当前生成文件的名称
{$webgen->currentFile} {* prints for example: 'articles/article-2.texy' *}
从 currentFile
获取到文件的相对路径
{$webgen->createRelativeLink('articles/article-1.html')} {* prints: 'article-1.html' for currentFile = 'articles/article-2.texy' 'articles/article-1.html' for currentFile = 'index.texy' *}
快捷键(输出为 currentFile = 'articles/article-2.texy'
)
{link articles/article-1.html} {* prints article-1.html *} <a n:href="articles/article-1.html">Article #1</a> {* prints *} <a href="article-1.html">Article #1</a> <link rel="stylesheet" n:href="css/style.css" type="text/css"> {* prints *} <link rel="stylesheet" href="../css/style.css" type="text/css"> <img n:src="images/photo.jpg"> {* prints *} <img src="../images/photo.jpg"> <img n:image="images/photo.jpg"> {* prints (image file must exist) *} <img src="../images/photo.jpg" width="1024" height="768">
Texy 中的相对路径
"Article #1":@articles/article-1.html
[* @images/photo.jpg *]
在菜单中突出显示当前页面 (链接当前吗?)
<div id="menu"> <a n:href="/" n:class="$webgen->isLinkCurrent('index.texy') ? current">Homepage</a> <a n:href="about-us/" n:class="$webgen->isLinkCurrent('about-us/**') ? current">About us</a> <a n:href="contact.html" n:class="$webgen->isLinkCurrent('contact.*') ? current">Contact</a> </div>
在掩码中 **
表示 一切,*
表示 一切 除了 /
。
Texy 文档中的变量
{{$var}}
{{$var = value}}
{{$var: value}}
配置
配置存储在名为 config.neon
的文件中。 NEON 是一个非常类似于 YAML 的格式,请参阅 https://ne-on.org/。
更改源或输出目录的名称
input:
dir: <new-source-dir-name>
output:
dir: <new-output-dir-name>
更改布局模板的名称
input:
layout: @my-layout-name.latte
将源目录中的文件复制到输出目录中(CSS & JS 文件、图像等)
布尔值(yes
/no
)或文件掩码
input:
copy: yes
input:
copy:
- *.js
- *.css
更改默认输出文件扩展名
output:
ext: php
文件特定的更改
{webgen ext => php} ## in Latte template {{webgen: ext: php}} ## in Texy file
更改输出文件名
## changes output file extension {webgen ext => php} ## changes output basename of file {webgen name => my-first-page} ## changes output filename (ignores 'ext' option) {webgen filename => my-first-page.html}
分页
请参阅示例 pagination-repeated-generating。
谁使用 Webgen?
文章
许可证:新 BSD 许可证
作者:Jan Pecha,https://www.janpecha.cz/