Thanks to visit codestin.com
Credit goes to github.com

Skip to content

terdelyi/phanstatic

Repository files navigation

Phanstatic

Total Downloads Latest Stable Version License

Phanstatic is a dead simple, modern, lightweight, CLI based static site generator written in PHP. There are no frameworks or template engines, just simple pages written in pure PHP code and markdown files. During the building process, all of your content is transformed into static HTML files, ready to deploy or upload to your server.

Install

To create a new project just run:

composer create-project terdelyi/phanstatic

Build

To build static files to the dist folder from the files placed inside the content directory run the following command in your root folder:

php ./vendor/bin/phanstatic build

Preview

To preview the dist folder quickly in a browser:

php ./vendor/bin/phanstatic preview

This will start PHP's built-in server at localhost with port 8000 and make the files from the dist available in a browser.

You can override the default host (--host) and the port (--port) settings if necessary.

Configuration

You can place a configuration file under content/config.php which must return a ConfigBuilder object like this:

use Terdelyi\Phanstatic\Models\Config;
use Terdelyi\Phanstatic\Models\CollectionConfig;

return new Config(
    baseUrl: (string) getenv('BASE_URL'),
    title: 'My super-fast static site',
    collections: [
        'posts' => new CollectionConfig(
            title: 'Posts',
            slug: 'posts',
            pageSize: 10
        ),
    ],
);

If no config.php file exist the builder will use the default settings. To explore settings your IDE should guide you by offering the available properties with types.

Content basics

Structuring the content is simple. The content folder is where your files live:

  • content/pages: This is where you put your .php files.
  • content/collections: This is where you put your .md files under subdirectories named as your collection key.
  • content/assets: Any of these files will be published under dist/assets. It can be .js, .css or any type of images.

Example project structure

├── content
│   ├── assets
│   │   ├── images
│   │   ├── css
│   │   ├── js
│   ├── collections
│   │   ├── posts
│   │   │   ├── my-first-blog-post.md
│   ├── pages
│   │   ├── about.php
│   │   ├── index.php
│   ├── config.php
├── composer.json
├── composer.lock

If you create a folder under collections you must add it as a collection to your config file, unless you're going to have Configuration for collection 'Collection' is missing error.

About

A simple, lightweight and CLI based static site generator written in PHP

Topics

Resources

License

Stars

Watchers

Forks

Languages