PHPoole-library is a static website generator built on PHP, inspired by Jekyll and Hugo.
It converts Markdown files into a static HTML web site, with the help of Twig, a flexible and fast template engine.
You can easily create a blog, a personal website, a simple corporate website, etc.
- No database, files only (host your site anywhere)
- Fully configurable (Through options and plugins system) WIP
- Flexible template engine (Twig)
- Theme support
- Dynamic menu creation
- Configurable taxonomies (categories, tags, etc.)
- Paginator (for homepage, sections and taxonomy)
Please see the composer.json file.
Download the Phar (not up to date)
Run the following command:
$ composer require narno/phpoole-library:1.0.X-dev
Try the demo
To create a new website, you need 3 things:
- pages (content)
- templates (layouts)
- a build script (PHP)
Organize your content:
.
├─ content <- Contains Mardown files
| ├─ Blog <- A section named "Blog"
| | └─ Post 1.md <- A page in the section "Blog"
| ├─ Project <- A section named "Project"
| | └─ Post 1.md <- A page in the section "Project"
| └─ About.md <- A page in the root
├─ layouts <- Contains Twig templates
| ├─ _default <- Contains default templates
| | ├─ list.html <- Used by a node type 'list'
| | ├─ page.html <- Used by a node type 'page'
| ├─ index.html <- Used by the node type 'homepage'
└─ static <- Contains static files
Create a PHP script:
<?php
require_once 'vendor/autoload.php'; // Composer
//require_once 'phar://phpoole-library.phar'; // Phar
use PHPoole\PHPoole;
PHPoole::create(
'./', // The source directory
null, // The destination directory (the same as source)
[ // Options array
'site' => [
'title' => "My website", // The Site title
'baseurl' => 'http://localhost:8000/', // The Site base URL
],
]
)->build(); // Launch builder
exec('php -S localhost:8000 -t _site'); // Run a local server
The static website is created in _./site.
The content is represented by Markdown files organized in folders. Folders in the root are called "section" (ie: "Blog", "Project", etc.).
A page can contain a front matter (YAML) and/or a body (Markdown).
Any file that contains a YAML front matter will be processed to extract some variables. The front matter must be the first thing in the file and must be a valid YAML.
Predefined variables
Variable | Description |
---|---|
title | Title |
section | Section |
layout | Layout |
date | Date |
menu | Menu |
tags | Tags |
categories | Categories |
permalink | Permalink |
---
title: "The title"
date: "2013-01-01"
customvar: "Custom variable"
---
_Markdown_ page content.
A layout is a Twig template.
Site variables
Variable | Description |
---|---|
title | Title |
WIP
Page variables
Variable | Description |
---|---|
title | Title |
WIP
Paginator variables
Variable | Description |
---|---|
title | Title |
WIP
PHPoole variables
Variable | Description |
---|---|
title | Title |
WIP
<h1>{{ page.title }} | {{ site.title }}</h1>
<span>{{ page.date|date("j M Y") }}</span>
<b>{{ page.content }}</p>
<b>{{ page.myvar }}</p>
PHP script options to define how to build the website.
[
'site' => [
'title' => 'PHPoole', // site title
'baseline' => 'A PHPoole website', // site baseline
'baseurl' => 'http://localhost:8000/', // php -S localhost:8000 -t _site/ >/dev/null
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', // site description
'taxonomies' => [ // list of taxonomies
'tags' => 'tag', // tag vocabulary
'categories' => 'category', // category vocabulary
],
'paginate' => [ // pagination options
'max' => 5, // maximum numbers of listed pages
'path' => 'page', // ie: section/page/2
],
],
'content' => [
'dir' => 'content', // content directory (from source)
'ext' => 'md', // file extension (*.md)
],
'frontmatter' => [
'format' => 'yaml', // yaml or ini
],
'body' => [
'format' => 'md', // body format, Markdown by default
],
'static' => [
'dir' => 'static', // static files directory
],
'layouts' => [
'dir' => 'layouts', // layouts/templates files directory
],
'output' => [
'dir' => '_site', // output directory
'filename' => 'index.html', // default filename of generated files
],
'themes' => [
'dir' => 'themes', // themes directory
],
]