norberttech / static-content-generator-bundle
从您的symfony应用程序生成静态HTML页面
0.6.1
2024-02-10 20:24 UTC
Requires
- php: ~8.1 || ~8.2 || ~8.3
- ext-json: *
- norberttech/symfony-process-executor: ^2.0.4
- symfony/browser-kit: ^5.4|^6.4|^7.0
- symfony/dependency-injection: ^5.4|^6.4|^7.0
- symfony/http-kernel: ^5.4|^6.4|^7.0
Requires (Dev)
- doctrine/annotations: ^1.11.1 || ^2.0.0
- nikic/php-parser: ^4.18
- symfony/dotenv: ^5.4|^6.4|^7.0
- symfony/framework-bundle: ^5.4|^6.4|^7.0
- symfony/maker-bundle: ^1.36.4
- symfony/stopwatch: ^5.4|^6.4|^7.0
- symfony/twig-pack: ^1.0
- symfony/web-profiler-bundle: ^5.4|^6.4|^7.0
- symfony/yaml: ^5.4|^6.4|^7.0
This package is auto-updated.
Last update: 2024-09-10 21:47:27 UTC
README
从系统中的所有Symfony路由生成静态HTML页面。
安装
composer require norberttech/static-content-generator-bundle
配置
<?php // bundles.php return [ NorbertTech\StaticContentGeneratorBundle\StaticContentGeneratorBundle::class => ['all' => true], ];
# static_content_generator.yaml static_content_generator: output_directory: "%kernel.project_dir%/output"
使用
将所有路由转换为静态HTML页面。
bin/console static-content-generator:generate:routes
选项
--parallel=4
- 同时使用4个子进程并行生成静态内容--clean
- 在开始前清理输出路径--filter-route
- 仅生成指定路由的内容--filter-route-prefix
- 生成具有指定前缀的路由的内容--exclude-route
- 生成除了指定路由之外的所有路由的内容--exclude-route-prefix
- 生成除了具有指定前缀的路由之外的所有路由的内容
将所有资源从public
目录复制到输出目录
bin/console static-content-generator:copy:assets
参数化路由
为了导出参数化路由,您需要注册实现SourceProvider
接口的服务,该服务将返回您想要导出的给定路由的所有可能的参数组合。
别忘了这个服务必须有static_content_generator.source_provider
标签。
# service.yaml services: FixtureProject\Source\ParametrizedSourceProvider: tags: ['static_content_generator.source_provider']
控制器
<?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]); } }
提供者
<?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']), ]; } }
这将生成/output/parametrized/first-param/second-param/index.html
测试
php -S localhost:8000 -t output