staticka / staticka
A simple yet extensible "do-it-yourself" static site generator.
Requires
- php: >=5.3.0
- erusev/parsedown: ~1.6
- symfony/yaml: >=2.8
- twig/twig: ~1.3
- zapheus/zapheus: ~0.1
Requires (Dev)
- phpunit/phpunit: ~4.2|~5.7
- scrutinizer/ocular: ~1.1.0
This package is auto-updated.
Last update: 2024-03-16 00:33:26 UTC
README
Inspired by popular static site generators like Hugo and Jekyll, Staticka is an extensible PHP-based static site generator. It mainly converts Markdown content and PHP template files into static HTML.
Installation
Install Staticka
via Composer:
$ composer require staticka/staticka
Basic Usage
NOTE: The usage below only consists on how to use Staticka as a library and not as a commonly used static site generator. For the applications that this library is being used, kindly check Console or Expresso.
Compiling Markdown files
Create a new file named index.md
:
index.md
# Hello World!
This is a sample Markdown file.
Then add it as a page to Staticka
instance:
index.php
use Staticka\Factories\PageFactory; $factory = new PageFactory; $site = new Staticka\Website; $file = __DIR__ . '/index.md'; $site->add($factory->file($file)); $site->build(__DIR__ . '/public');
To compile the pages, run the php index.php
command:
$ php index.php
To see the output, open public/index.html
in a web browser.
public/index.html
<h1>Hello World!</h1> <p>This is a sample Markdown file.</p>
Adding Front Matter and additional data
Staticka supports Front Matter in which can add predefined variables in a specific content. Special variables like path
, link
, and title
are also generated by default but can be overwritten inside the content.
index.md
---
link: brave-world
---
# Hello World!
This is a sample Markdown file.
build/brave-world/index.html (after running php index.php
in the terminal)
<h1>Hello World!</h1> <p>This is a sample Markdown file.</p>
Page properties
The page properties that will be used by Staticka can be found on Staticka\Contracts\PageContract
:
// Content of the page PageContract::DATA_BODY = 'body'; // Specific name of the page PageContract::DATA_NAME = 'name'; // The URL path of the page PageContract::DATA_LINK = 'link'; // File path of the template PageContract::DATA_PLATE = 'plate'; // Title heading for the page PageContract::DATA_TITLE = 'title';
Customization
Filters
Staticka can use filters to modify the contents of the specified page. Creating filters require an instance to be implemented in FilterContract
.
index.php
use Staticka\Factories\PageFactory; use Staticka\Filter\HtmlMinifier; // NOTE: Add filters in the Layout instance $layout = new Staticka\Layout; $layout->filter(new HtmlMinifier); $factory = new PageFactory($layout); $site = new Staticka\Website; $file = __DIR__ . '/index.md'; $site->add($factory->file($file)); $site->build(__DIR__ . '/public');
build/brave-world/index.html (after running php index.php
in the terminal)
<h1>Hello World!</h1><p>This is a sample Markdown file.</p>
Helpers
Helpers can be used in putting methods inside template files. It must also be implemented in HelperContract
when creating a new helper.
index.md
---
link: brave-world
layout: layout
---
# Hello World!
This is a sample Markdown file.
layout.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title><?php echo $title; ?></title> </head> <body> <p><?php echo $url->set('hello'); ?></p> <?php echo $content; ?> </body> </html>
index.php
use Staticka\Factories\PageFactory; use Staticka\Helpers\LinkHelper; // NOTE: Add helpers in the Layout instance $layout = new Staticka\Layout; $helper = new LinkHelper('https://staticka.github.io'); $layout->helper($helper); $factory = new PageFactory($layout); $site = new Staticka\Website; $file = __DIR__ . '/index.md'; $site->add($factory->file($file)); $site->build(__DIR__ . '/public');
build/brave-world/index.html (after running php index.php
in the terminal)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Hello World!</title> </head> <body> <p>https://staticka.github.io/hello</p> <h1>Hello World!</h1> <p>This is a sample Markdown file.</p></body> </html>
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Credits
License
The MIT License (MIT). Please see LICENSE for more information.