Giter Club home page Giter Club logo

phpoole-library's Introduction

A PHP library to generate a static website. WIP.

Build Status Code Coverage Scrutinizer Code Quality Code Climate Dependency Status

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.

Features

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

Requirements

Please see the composer.json file.

Installation

Manually

Download the Phar (not up to date)

Composer

Run the following command:

$ composer require narno/phpoole-library:1.0.X-dev

Demo

Try the demo

Usage

Overview

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.

Content

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

Front matter

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

Page example

---
title: "The title"
date: "2013-01-01"
customvar: "Custom variable"
---
_Markdown_ page content.

Layouts

A layout is a Twig template.

Variables

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

Layout example

<h1>{{ page.title }} | {{ site.title }}</h1>
<span>{{ page.date|date("j M Y") }}</span>
<b>{{ page.content }}</p>
<b>{{ page.myvar }}</p>

Options

PHP script options to define how to build the website.

Default options

[
    '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
    ],
]

phpoole-library's People

Contributors

arnaudligny avatar scrutinizer-auto-fixer avatar

Watchers

James Cloos avatar Benjamin Bellamy avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.