Giter VIP home page Giter VIP logo

static-content-generator-bundle's Introduction

Symfony Static Content Generator Bundle

Tests Minimum PHP Version Minimum Symfony Version

Generate static html pages from all Symfony routes available in your system.

Installation

composer require norberttech/static-content-generator-bundle

Configuration

<?php
// bundles.php

return [
    NorbertTech\StaticContentGeneratorBundle\StaticContentGeneratorBundle::class => ['all' => true],
];
# static_content_generator.yaml

static_content_generator:
  output_directory: "%kernel.project_dir%/output"

Usage

Transform all routes into static html pages.

bin/console static-content-generator:generate:routes

Options:

  • --parallel=4 - generate static content in parallel using 4 sub processes at once
  • --clean - clean output path before start
  • --filter-route - generate content only for given routes
  • --filter-route-prefix - generate content for routes with given prefix
  • --exclude-route - generate content for all routes except given
  • --exclude-route-prefix - generate content for all routes except those with given prefix

Copy all assets from public directory into output directory

bin/console static-content-generator:copy:assets

Parametrized Routes

In order to dump parametrized routes you need to register service that implements SourceProvider interface which will return all possible combinations of parameters for given route you would like to dump.

Don't forget that this services must have static_content_generator.source_provider tag.

# service.yaml 

services:

    FixtureProject\Source\ParametrizedSourceProvider:
        tags: ['static_content_generator.source_provider']

Controller:

<?php declare(strict_types=1);

namespace FixtureProject\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class StaticRoutesController extends AbstractController
{
    /**
     * @Route("/parametrized/{param1}/{param2}", name="parametrized_route")
     */
    public function withParameters(string $param1, string $param2) : Response
    {
        return $this->render('parametrized.html.twig', ['param1' => $param1, 'param2' => $param2]);
    }
}

Provider:

<?php

declare(strict_types=1);

namespace FixtureProject\Source;

use NorbertTech\StaticContentGeneratorBundle\Content\Source;
use NorbertTech\StaticContentGeneratorBundle\Content\SourceProvider;

final class ParametrizedSourceProvider implements SourceProvider
{
    public function all() : array
    {
        return [
            new Source('parametrized_route', ['param1' => 'first-param', 'param2' => 'second-param']),
        ];
    }
}

This will generate /output/parametrized/first-param/second-param/index.hmtml

Testing

php -S localhost:8000 -t output

static-content-generator-bundle's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar norberttech avatar aeon-automation avatar jerome-barbato avatar

Stargazers

 avatar  avatar  avatar Wolf avatar Boris avatar  avatar Robert Mikołajuk avatar Yanko Simeonoff avatar Yanko Simeonoff avatar Jérémy DECOOL avatar Miroslav Evják avatar Dmitry Korolev avatar Kevin van Sonsbeek avatar Efimov Evgenij avatar Ján Bočínec avatar Wojtek Zymonik avatar Mihai Nica avatar Dominik Frankowicz avatar Nicolas Hart avatar Álvaro García León avatar  avatar Iv Po avatar Romаn Mоvchan avatar Borislav Kosun avatar Hennadii Tarasenko avatar Benedict avatar  avatar Alfie Salomons avatar José Carlos avatar Łukasz Staniszewski avatar  avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

xazoom jwbrownie

static-content-generator-bundle's Issues

Any recommendations on how to output the error pages as well?

I'm using this using S3 + CloudFront and I really enjoy it. There's a way for S3 to redirect to a specific 404 page when a page doesn't exist and I have a template in my Symfony project at:

templates/bundles/TwigBundle/Exception/error404.html.twig

However, this doesn't get output in the output folder.

Exclude routes

How do I have to render all the routes, except the ones that have or start with /admin?

Dependency Issue in Symfony 6.1

Hi,

I am working on adding this bundle to my Symfony 6.1 but it fails to install with the following error:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires norberttech/static-content-generator-bundle ^0.4.0 -> satisfiable by norberttech/static-content-generator-bundle[0.4.0].
    - norberttech/static-content-generator-bundle 0.4.0 requires symfony/browser-kit ^4.4|^5.0 -> found symfony/browser-kit[v4.4.0, ..., v4.4.37, v5.0.0, ..., v5.4.3] but these were not loaded, likely because it conflicts with another require.

Is this beautiful bundle going to be compatible with Symfony 6.1 anytime soon? Please, I am not capable of fixing it myself.

For your attention thank you very much.
Regards,

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.