Skip to content

Simple PHP CLI generator of static sites

License

Notifications You must be signed in to change notification settings

webgen-org/webgen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webgen

Build Status

Simple PHP CLI generator of static web sites.

Become a Patron! Buy me a coffee

Features

Usage

$ cd examples/basic
$ php -f ../../webgen.php -- --run
$ cd output
$ ls
articles  index.html

Note: Webgen ignores files with @ on start of filename.

Templating

Texy in Latte template

{block |texy}
This is **Texy** snippet.
{/block}


{texy}
This is "Texy":https://texy.info snippet too.
{/texy}

Get name of current generated file

{$webgen->currentFile} {* prints for example: 'articles/article-2.texy' *}

Get relative path from currentFile to a file

{$webgen->createRelativeLink('articles/article-1.html')}
{* prints:
'article-1.html'          for currentFile = 'articles/article-2.texy'
'articles/article-1.html' for currentFile = 'index.texy'
*}

Shortcuts (output for 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">

Relative paths in Texy:

"Article #1":@articles/article-1.html

[* @images/photo.jpg *]

Highlight current page in menu (is link current?)

<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>

In mask ** means everything, * means everything except /.

Variables in Texy document

{{$var}}

{{$var = value}}

{{$var: value}}

Configuration

Configuration is stored in file named config.neon. NEON is format very similar to YAML, see https://ne-on.org/.

Change name of source or output directory

input:
	dir: <new-source-dir-name>

output:
	dir: <new-output-dir-name>

Change name of layout template

input:
	layout: @my-layout-name.latte

Copy files from source directory into output directory (CSS & JS files, images,...)

Boolean value (yes/no) or filemask(s):

input:
    copy: yes
input:
    copy:
        - *.js
        - *.css

Change default output file extension

output:
    ext: php

File-specific change:

{webgen ext => php}   ## in Latte template
{{webgen: ext: php}}  ## in Texy file

Change output filename

## 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

See example pagination-repeated-generating.

Who uses Webgen?

Articles:


License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/