dupot/static-generation-skeleton

2.0.0 2022-11-12 14:24 UTC

This package is auto-updated.

Last update: 2024-12-12 19:07:41 UTC


README

Skeleton to create a static-generation-framework website

Usage

Installation

composer create-project dupot/static-generation-skeleton myWebsite

Generation

docker-compose exec web php src/generate.php

Display the result

docker-compose up

Then open your browser on http://localhost/ url

How to use

Create your pages as class in Pages folder

  • Each page will use a layout and load component list
  • Each page will be generated as html page in docs folder, so don't miss to add in this folder all css/js dependances

Create components used by your pages in Components folder

  • Each component will use views

Example of use

You homepage

src/Pages/HomePage.php

<?php

namespace MyWebsite\Pages;

use Dupot\StaticGenerationFramework\Page\PageAbstract;
use Dupot\StaticGenerationFramework\Page\PageInterface;
use MyWebsite\Components\HomeWelcomeComponent;
use MyWebsite\Components\NavComponent;

class HomePage extends PageAbstract implements PageInterface
{
    const FILENAME = 'index.html';

    public function getFilename(): string
    {
        return self::FILENAME;
    }

    public function render(): string
    {
        return $this->renderLayoutWithParamList(
            __DIR__ . '/layout/default.php',
            [
                'nav' => new NavComponent($this->getFilename()),
                'contentList' => [
                    new HomeWelcomeComponent(),
                ]
            ]
        );
    }
}

Your components included in your page

src/Components/NavComponent.php

<?php

namespace MyWebsite\Components;

use Dupot\StaticGenerationFramework\Component\ComponentAbstract;
use Dupot\StaticGenerationFramework\Component\ComponentInterface;
use MyWebsite\Pages\HomePage;

class NavComponent extends ComponentAbstract implements ComponentInterface
{

    protected $pageSelected;

    public function __construct($pageSelected)
    {
        $this->pageSelected = $pageSelected;
    }

    public function render(): string
    {
        $linkList = [
            'Home' => HomePage::FILENAME,

        ];

        return $this->renderViewWithParamList(
            __DIR__ . '/Nav/nav.php',
            [
                'linkList' => $linkList,
                'pageSelected' => $this->pageSelected
            ]
        );
    }
}

view used by your component

src/Components/Nav/nav.php

<nav class="navbar navbar-wrapper navbar-default navbar-fade is-transparent" role="navigation" aria-label="main navigation">

    <div class="navbar-brand">
        <a class="navbar-item" href="index.html">
            <img src="css/images/logo.png" width="112" height="28">
        </a>

        <a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbar-menu">
            <span aria-hidden="true"></span>
            <span aria-hidden="true"></span>
            <span aria-hidden="true"></span>
        </a>
    </div>

    <div class="navbar-menu  " id="navbar-menu">

        <?php foreach ($this->paramList['linkList'] as $label => $link) : ?>
            <a class="navbar-item <?php if ($link == $this->paramList['pageSelected']) : ?>is-active<?php endif; ?>" href="<?php echo $link ?>"><?php echo $label ?></a>
        <?php endforeach; ?>

    </div>

</nav>

Generate script

Last but not least: don't miss to fill in generation script your page class list

<?php

use MyWebsite\Pages\HomePage;

require __DIR__ . '/../vendor/autoload.php';

$pagesList = [

    new HomePage(),
    //new OtherPage()

];

foreach ($pagesList as $pageLoop) {
    print("Generate " . $pageLoop->getFilename() . "\n");
    $pageLoop->generateTo(__DIR__ . '/../docs/');
}