nassau / kunstmaan-static-site-bundle
将 Kunstmaan Bundles CMS 网站导出为静态 HTML 文件
0.2
2016-12-14 14:37 UTC
Requires
- kunstmaan/bundles-cms: ^3.5
- nassau/registry-compiler: ^1.1
This package is auto-updated.
Last update: 2024-09-23 19:28:20 UTC
README
安装
composer require nassau/kunstmaan-static-site-bundle
配置
使用 symfony 配置来配置您想要导出的路径和文件。以下示例是默认配置
# app/config/config.yml kunstmaan_static_site: # # Set your full domain name to be used when generating full URLs: # url_prefix: 'http://example.com' # just static files you’d like to export files: # by default, extract everything in the public "web" folder, excluding PHP files web: directory: '%kernel.root_dir%/../web' exclude: '*.php' # # For example, add some custom directory, and store it in generated site under "uploads" path # uploads: # directory: '%kernel.root_dir%/../uploads' # include: '*.jpg' # target: 'uploads/' # those files will be generated using the application: routes: # all of the published CMS pages pages: # use this route to access route: '_slug' # there is a generator named nodes, and it returns a collection of route params # for each nodeTranslation, so a proper url can be generated for it generator: 'nodes' # we’d like to have a sitemap! sitemap_index: # this route has only one version, so there is no need to define a generator route: 'KunstmaanSitemapBundle_sitemapindex' # but there is a required argument to generate url, we provide it here defaults: _format: 'xml' # sitemaps for each language sitemaps: route: 'KunstmaanSitemapBundle_sitemap' # there are multiple versions, one for each locale, so a generator is needed generator: 'locales' # in addition to values provided by the generator, add those values to generate URL: defaults: _format: 'xml' # simplest config. one route, one url. robots: route: 'KunstmaanSeoBundle_robots' # # for example you have a custom contact page with two variants: # contact: # # this is your route name # route: acme_contact # # this service needs to generate an array of params for each variant, see below how to do this! # generator: acme_contact
使用方法
运行 nassau:static-site:dump file://target-directory
。目录必须存在。
这将导出
- 所有静态文件(从
web
目录) - 所有 CMS 页面
- 网站地图和机器人文件
- 在设置区域添加的重定向
定制
存储后端
仅提供了一个简单的 FileSystemStorage
。通过实现 Nassau\KunstmaanStaticSiteBundle\Service\Dumper\Storage
接口并标记容器中的服务来创建自己的。这最适合 Amazon S3 或 FTP 后端。
storeStaticSite
方法在整个网站中仅被调用一次。这样您就可以将所有文件导出为 zip
或 tar
归档。
示例
class DiskPreservingFileSystemStorage implements Storage { public function storeStaticSite($location, StaticSiteDumper $dumper) { foreach ($dumper->getStaticSite() as $path => $response) { if (rand(1,10) > 5) { // we’re running out of disk space, let’s skip some files! continue; } // do stuff! } } }
# services.yml
services:
acme.disk_preserving_storage:
class: DiskPreservingFileSystemStorage
tags:
- name: nassau.static_site.storage
alias: random
现在您可以使用此后端使用 random://
协议: app/console nassau:static-site:dump random://tmp/static-site
路由参数生成器
实现 Nassau\KunstmaanStaticSiteBundle\Service\Generator\RouteParametersGenerator
接口并在容器中标记您的服务。
例如,这里有一个虚构的 formats
生成器,为三种格式中的每一种生成一个单独的 URL。当使用时,给定的路由将导出三次,每次以不同的格式。
class FormatsGenerator extends RouteParametersGenerator { /** * @return array[] */ public function getItems() { return [ ['_format' => 'html'], ['_format' => 'json'], ['_format' => 'xml'], ]; } }
# services.yml
services:
acme.generators.format:
class: FormatsGenerator
tags:
- name: nassau.static_site.generator
alias: formats