{
  "version": "https://jsonfeed.org/version/1.1",
  "title": "Cecil - Developers",
  "home_page_url": "https://cloudflare.cecil.app/documentation/developers/",
  "feed_url": "https://cloudflare.cecil.app/documentation/developers/feed.json",
  "description": "Extend Cecil with PHP, use it as a library and understand its architecture.",
  "icon": "https://cloudflare.cecil.app/favicon.7ff4b89eec6dad139a7d2d6561543285.png",
  "favicon": "https://cloudflare.cecil.app/thumbnails/64x/favicon.7ff4b89eec6dad139a7d2d6561543285.png",
  "language": "en",
  "items": [
    {
      "id": "https://cloudflare.cecil.app/documentation/developers/architecture/",
      "url": "https://cloudflare.cecil.app/documentation/developers/architecture/",
      "title": "Architecture",
      "summary": "Diagrams of the build pipeline and of the technical architecture, and key components.",
      "date_published": "2026-05-27T00:00:00+00:00",
      "date_modified": "2026-10-26T00:00:00+00:00","content_text": "Architecture\nThis page gives an overview of Cecil’s build pipeline, its technical architecture and its key components.\nBuild pipeline\nPipeline overview\ngraph LR\n    SRC[\"Sources\\n(pages, data, assets,\\nstatic, layouts, themes)\"]\n    CFG[\"Configuration\"]\n    EXTS[\"Extensions\\n(plugins, events)\"]\n    BUILDER[\"Builder\"]\n    LOAD[\"Load\\n(pages, data,\\nstatic files)\"]\n    CONVERT[\"Create &amp; convert\\n(pages, taxonomies)\"]\n    GENERATE[\"Generate\\n(generators, menus)\"]\n    RENDER[\"Render\\n(Twig)\"]\n    SAVE[\"Save &amp; optimize\\n(pages, assets,\\nstatic files)\"]\n    OUT[\"_site\/\"]\n\n    CFG --&gt; BUILDER\n    EXTS --&gt; BUILDER\n    SRC --&gt; LOAD\n    BUILDER --&gt; LOAD --&gt; CONVERT --&gt; GENERATE --&gt; RENDER --&gt; SAVE --&gt; OUT\nDetailed pipeline\ngraph TD\n    %% Entry\n    CLI[\"bin\/cecil\\n(CLI entry point)\"]\n    APP[\"Application\\n(Symfony Console)\"]\n    CMD[\"Commands\\nbuild \/ serve \/ doctor\\nnew:* \/ clear \/ cache:clear\\nshow:* \/ util:* \/ ...\"]\n\n    CLI --&gt; APP --&gt; CMD\n\n    %% Orchestrator\n    BUILDER[\"Builder\\n(Orchestrator)\"]\n    CONFIG[\"Configuration\\n(plugins &lt; default.php\\n&lt; themes &lt; cecil.yml\\n&lt; env vars + CLI options)\"]\n    CMD --&gt; BUILDER\n    CONFIG --&gt; BUILDER\n\n    %% Extensions\n    EXTN[\"Extensions\\n(Autoloader + Loader:\\nplugins, event subscribers,\\ngenerators, Twig extensions,\\npost-processors)\"]\n    EVENTS[\"Build events\\n(build.*, step.*, page.*)\"]\n    BUILDER --&gt; EXTN\n    EXTN -- \"plugins config\" --&gt; CONFIG\n    BUILDER -. \"dispatch\" .-&gt; EVENTS\n    EVENTS -. \"notify subscribers\" .-&gt; EXTN\n\n    %% Pipeline\n    subgraph PIPELINE[\"Build pipeline (steps)\"]\n        S1[\"1. Pages\/Load\\n(Finder → Markdown files)\"]\n        S2[\"2. Data\/Load\\n(data files)\"]\n        S3[\"3. StaticFiles\/Load\\n(if static.load is enabled)\"]\n        S4[\"4. Pages\/Create\\n(create Page objects)\"]\n        S5[\"5. Pages\/Convert\\n(front matter +\\nMarkdown → HTML)\"]\n        S6[\"6. Taxonomies\/Create\\n(create taxonomies)\"]\n        S7[\"7. Pages\/Generate\\n(generators)\"]\n        S8[\"8. Menus\/Create\\n(create menus)\"]\n        S9[\"9. StaticFiles\/Copy\\n(copy static files)\"]\n        S10[\"10. Pages\/Render\\n(Twig rendering)\"]\n        S11[\"11. Pages\/Save\\n(save pages)\"]\n        S12[\"12. Assets\/Save\\n(save assets)\"]\n        S13[\"13-16. Optimize\/Html, Css, Js, Images\\n(if optimization is enabled)\"]\n\n        S1 --&gt; S2 --&gt; S3 --&gt; S4 --&gt; S5 --&gt; S6 --&gt; S7 --&gt; S8 --&gt; S9 --&gt; S10 --&gt; S11 --&gt; S12 --&gt; S13\n    end\n\n    BUILDER --&gt; PIPELINE\n\n    %% Subsystems\n    CONV[\"Converter\\n(pages.converter, pages.body.parser:\\nParsedown + highlighter)\"]\n\n    subgraph COLLECTIONS[\"Collections\"]\n        PC[\"PagesCollection\\n(Page objects)\"]\n        TC[\"TaxonomiesCollection\\n(vocabularies\/terms)\"]\n        MC[\"MenusCollection\"]\n    end\n\n    subgraph GENERATORS[\"Generators (by priority)\"]\n        G1[\"DefaultPages\\n(index, 404, robots, sitemap, xsl)\"]\n        G3[\"ExternalBody\"]\n        G4[\"Section\"]\n        G5[\"Taxonomy\"]\n        G6[\"Homepage\"]\n        G7[\"Pagination\"]\n        G8[\"Alias\"]\n        G9[\"Redirect\"]\n        G10[\"Custom generators\\n(priority 100 by default)\"]\n        G1 --&gt; G3 --&gt; G4 --&gt; G5 --&gt; G6 --&gt; G7 --&gt; G8 --&gt; G9 --&gt; G10\n    end\n\n    subgraph RENDERER[\"Twig rendering\"]\n        TW[\"Twig engine\"]\n        EXT[\"Twig extensions\\n(Core, Content, Collection,\\nTranslation, Intl, Components\\n+ custom)\"]\n        PP[\"PostProcessors\\n(generator meta tag, excerpts, links\\n+ custom)\"]\n        TH[\"Themes \/ Layouts\"]\n        TW --&gt; EXT\n        TW --&gt; PP\n        TH --&gt; TW\n    end\n\n    subgraph ASSETS[\"Assets\"]\n        AL[\"Asset locator\"]\n        AC[\"Compiler\\n(SCSS → CSS)\"]\n        AI[\"Image processor\\n(resize, responsive, WebP, AVIF)\"]\n        AO[\"Optimizer\\n(CSS\/JS minification,\\nimage optimization)\"]\n    end\n\n    CACHE[\".cache\/\\n(assets, templates, translations)\"]\n\n    subgraph OUTPUT[\"Output (_site\/)\"]\n        HTML[\"pages (HTML, XML, JSON, etc.)\"]\n        CSS2[\"CSS\/JS assets\"]\n        IMG[\"images\"]\n        SF[\"static files\"]\n    end\n\n    S5 --&gt; CONV\n    S4 --&gt; PC\n    S6 --&gt; TC\n    S8 --&gt; MC\n    S7 --&gt; GENERATORS\n    GENERATORS --&gt; PC\n    S10 --&gt; RENDERER\n    EXTN --&gt; GENERATORS\n    EXTN --&gt; EXT\n    EXTN --&gt; PP\n    PIPELINE -. \"step.*, page.*\" .-&gt; EVENTS\n\n    PC --&gt; RENDERER\n    TC --&gt; RENDERER\n    MC --&gt; RENDERER\n    S2 -- \"site.data\" --&gt; RENDERER\n    S3 -- \"site.static\" --&gt; RENDERER\n\n    %% assets are created by the converter (Markdown images, links) and by templates (asset() function),\n    %% processed and stored in cache, then copied to the output\n    CONV --&gt; ASSETS\n    EXT --&gt; ASSETS\n    ASSETS --&gt; CACHE\n    CACHE --&gt; S12\n\n    RENDERER --&gt; S11\n    S11 --&gt; HTML\n    S12 --&gt; CSS2\n    S12 --&gt; IMG\n    S9 --&gt; SF\n    S13 -. \"optimize files in place\" .-&gt; OUTPUT\n\n    %% Inputs\n    subgraph INPUT[\"Sources\"]\n        MD[\"pages\/\\n(Markdown + front matter)\"]\n        DATA[\"data\/\\n(YAML, JSON, XML, CSV)\"]\n        STATIC[\"static\/\"]\n        ASSETSDIR[\"assets\/\"]\n        LAYOUTS[\"layouts\/\\n(Twig templates)\"]\n        TRANS[\"translations\/\"]\n        THEMES[\"themes\/\\n(config, layouts, assets,\\nstatic, data, translations,\\nextensions)\"]\n        EXTDIR[\"extensions\/\\n(PHP classes)\"]\n    end\n\n    MD --&gt; S1\n    DATA --&gt; S2\n    STATIC --&gt; S3\n    STATIC --&gt; S9\n    ASSETSDIR --&gt; AL\n    LAYOUTS --&gt; TH\n    TRANS --&gt; EXT\n    THEMES --&gt; CONFIG\n    THEMES --&gt; TH\n    THEMES --&gt; EXTN\n    EXTDIR --&gt; EXTN\nTechnical architecture\nThe diagrams below show how the code is organized in layers, from the command line to the file system, and which libraries each component relies on.\nArchitecture overview\ngraph TB\n    ENTRY[\"Entry points\\n(bin\/cecil, cecil.phar)\"]\n    CONSOLE[\"Console\\n(commands)\"]\n    DEV[\"Local server\\n(serve, live reload)\"]\n    CORE[\"Core\\n(Builder, Config, Steps,\\nCollections, Generators)\"]\n    EXTS[\"Extensions\\n(plugins, events)\"]\n    SERVICES[\"Services\\n(Converter, Renderer,\\nAssets, Cache, Doctor)\"]\n    LIBS[\"Libraries\\n(Symfony, Twig, Parsedown,\\nscssphp, Intervention Image, ...)\"]\n    FS[\"File system\\n(sources, .cache\/, _site\/)\"]\n\n    ENTRY --&gt; CONSOLE --&gt; CORE\n    CONSOLE --&gt; DEV --&gt; CORE\n    CORE &lt;--&gt; EXTS\n    CORE --&gt; SERVICES\n    CORE --&gt; FS\n    SERVICES --&gt; FS\n    SERVICES --&gt; LIBS\nDetailed architecture\ngraph TB\n    %% Distribution and entry points\n    subgraph ENTRY[\"Entry points\"]\n        BIN[\"bin\/cecil\\n(Composer)\"]\n        PHAR[\"cecil.phar\\n(Box, self-update)\"]\n    end\n\n    subgraph CONSOLE[\"Console layer (Symfony Console)\"]\n        APP[\"Application\"]\n        ENV[\".env\\n(phpdotenv)\"]\n        BUILD[\"build\"]\n        SERVE[\"serve\"]\n        DOCTOR[\"doctor:*\"]\n        OTHERS[\"new:* \/ show:* \/ clear \/ cache:clear \/ util:*\"]\n        APP --&gt; BUILD\n        APP --&gt; SERVE\n        APP --&gt; DOCTOR\n        APP --&gt; OTHERS\n        ENV --&gt; APP\n    end\n\n    BIN --&gt; APP\n    PHAR --&gt; APP\n\n    subgraph DEV[\"Local server (serve)\"]\n        PHPS[\"PHP built-in server\\n(.cecil\/router.php)\"]\n        WATCH[\"FileWatcher\\n(changes.flag)\"]\n        PROC[\"Build sub-process\\n(Symfony Process)\"]\n        LR[\"livereload.js\\n(Server-Sent Events)\"]\n        WATCH -- \"rebuild\" --&gt; PROC\n        WATCH -- \"notify\" --&gt; PHPS\n        PHPS --&gt; LR\n    end\n\n    SERVE --&gt; DEV\n\n    subgraph CORE[\"Core\"]\n        BUILDER[\"Builder\\n(steps orchestration, metrics)\"]\n        CFG[\"Config\\n(Merger, Deprecations,\\nnette\/schema)\"]\n        LOG[\"Logger\\n(PSR-3: Console, Progress, Print)\"]\n        STEPS[\"Steps\\n(StepInterface)\"]\n        COLL[\"Collections\\n(Page, Taxonomy, Menu)\"]\n        GEN[\"Generators\\n(GeneratorManager)\"]\n        BUILDER --&gt; CFG\n        BUILDER --&gt; LOG\n        BUILDER --&gt; STEPS\n        STEPS --&gt; COLL\n        STEPS --&gt; GEN\n    end\n\n    BUILD --&gt; BUILDER\n    PROC --&gt; BUILDER\n    OTHERS --&gt; BUILDER\n\n    subgraph EXTS[\"Extensions\"]\n        AUTO[\"Autoloader\\n(extensions\/, PSR-4,\\nextensions\/vendor\/)\"]\n        LOADER[\"Loader\\n(by name and priority,\\nextensions.strict)\"]\n        PLUG[\"Plugins\\n(Registry)\"]\n        EVT[\"Event dispatcher\\n(BuildEvents, subscribers)\"]\n        PLUG --&gt; LOADER\n    end\n\n    BUILDER --&gt; AUTO\n    BUILDER --&gt; PLUG\n    PLUG -- \"default config\" --&gt; CFG\n    BUILDER -- \"dispatch\" --&gt; EVT\n    STEPS -- \"dispatch\" --&gt; EVT\n    LOADER --&gt; GEN\n\n    subgraph SERVICES[\"Services\"]\n        CONV[\"Converter\\n(ConverterInterface, Parsedown Extra + TOC,\\nhighlight.php \/ Tempest)\"]\n        REND[\"Renderer\\n(Twig, Symfony Translation,\\nTwig Components)\"]\n        ASSET[\"Asset\\n(Locator, Compiler, Image, Optimizer)\"]\n        CACHE[\"Cache\\n(PSR-16, files)\"]\n        DOC[\"Doctor\\n(Site, Frontmatter, Links, SEO)\"]\n    end\n\n    STEPS --&gt; CONV\n    STEPS --&gt; REND\n    STEPS --&gt; ASSET\n    REND --&gt; ASSET\n    CONV --&gt; ASSET\n    ASSET --&gt; CACHE\n    REND --&gt; CACHE\n    DOCTOR --&gt; DOC\n    DOC --&gt; BUILDER\n    LOADER --&gt; REND\n\n    subgraph LIBS[\"Main libraries\"]\n        L1[\"Symfony\\n(Finder, Filesystem, Yaml, Serializer,\\nValidator, DomCrawler, EventDispatcher)\"]\n        L2[\"scssphp\"]\n        L3[\"Intervention Image\\n(GD, Imagick, libvips)\"]\n        L4[\"matthiasmullie\/minify\\nvoku\/html-min\"]\n        L5[\"spatie\/image-optimizer\\n(external binaries)\"]\n        L6[\"yosymfony\/toml\"]\n        L7[\"getID3, mp3info\\n(audio\/video metadata)\"]\n    end\n\n    CORE --&gt; L1\n    ASSET --&gt; L2\n    ASSET --&gt; L3\n    ASSET --&gt; L4\n    STEPS --&gt; L4\n    ASSET --&gt; L5\n    CONV --&gt; L6\n    ASSET --&gt; L7\n\n    subgraph FS[\"File system\"]\n        SRC[\"Sources\\n(pages\/, data\/, assets\/, static\/,\\nlayouts\/, translations\/, themes\/,\\nextensions\/)\"]\n        CACHEDIR[\".cache\/\"]\n        TMP[\".cecil\/\\n(router, live reload, metrics, logs)\"]\n        OUT[\"_site\/\"]\n    end\n\n    STEPS -- \"read\" --&gt; SRC\n    AUTO -- \"read\" --&gt; SRC\n    CACHE --&gt; CACHEDIR\n    STEPS -- \"write\" --&gt; OUT\n    PHPS -- \"serve\" --&gt; OUT\n    DEV --&gt; TMP\nKey components\n\n\n\nComponent\nRole\n\n\n\n\nBuilder\nCentral orchestrator that executes steps in sequence\n\n\nConfig\nMerges plugins, default, themes and project configuration (Config\\Merger), environment variables (CECIL_*) and CLI options, and reports deprecated options (Config\\Deprecations)\n\n\nSteps\nModular pipeline (16 steps), each with init() \/ canProcess() \/ process()\n\n\nCollections\nPages, Taxonomies, Menus: core data structures\n\n\nConverter\nParses the front matter (YAML, INI, TOML or JSON) and converts Markdown to HTML (Parsedown, code highlighting); replaceable with pages.converter and pages.body.parser\n\n\nGenerators\nCreate or update pages (default pages, sections, taxonomies, pagination, aliases, redirects, etc.)\n\n\nExtensions\nGenerators, Twig extensions, post-processors, event subscribers and plugins declared by name, loaded and validated by Extension\\Loader, autoloaded by Extension\\Autoloader\n\n\nEvents\nBuild events (Event\\BuildEvents) dispatched around the build, each step and each page lifecycle, to extend Cecil\n\n\nRenderer (Twig)\nApplies templates + extensions + post-processors\n\n\nAssets\nCreated from Markdown content and templates: compiles SCSS, minifies, resizes and converts images, fingerprints files\n\n\nCache\nStores processed assets, compiled templates and translations in .cache\/ to speed up subsequent builds\n\n\nDoctor\nDiagnoses the project: front matter, links, SEO, cache (doctor commands)\n\n\n",
      "content_html": "<h1>Architecture</h1>\n<p>This page gives an overview of Cecil’s build pipeline, its technical architecture and its key components.</p>\n<h2 id=\"build-pipeline\">Build pipeline<a class=\"heading-anchor\" href=\"#build-pipeline\" aria-hidden=\"true\" tabindex=\"-1\"></a></h2>\n<h3 id=\"pipeline-overview\">Pipeline overview<a class=\"heading-anchor\" href=\"#pipeline-overview\" aria-hidden=\"true\" tabindex=\"-1\"></a></h3>\n<pre data-lang=\"mermaid\"><code class=\"language-mermaid\" translate=\"no\">graph LR\n    SRC[\"Sources\\n(pages, data, assets,\\nstatic, layouts, themes)\"]\n    CFG[\"Configuration\"]\n    EXTS[\"Extensions\\n(plugins, events)\"]\n    BUILDER[\"Builder\"]\n    LOAD[\"Load\\n(pages, data,\\nstatic files)\"]\n    CONVERT[\"Create &amp; convert\\n(pages, taxonomies)\"]\n    GENERATE[\"Generate\\n(generators, menus)\"]\n    RENDER[\"Render\\n(Twig)\"]\n    SAVE[\"Save &amp; optimize\\n(pages, assets,\\nstatic files)\"]\n    OUT[\"_site/\"]\n\n    CFG --&gt; BUILDER\n    EXTS --&gt; BUILDER\n    SRC --&gt; LOAD\n    BUILDER --&gt; LOAD --&gt; CONVERT --&gt; GENERATE --&gt; RENDER --&gt; SAVE --&gt; OUT</code></pre>\n<h3 id=\"detailed-pipeline\">Detailed pipeline<a class=\"heading-anchor\" href=\"#detailed-pipeline\" aria-hidden=\"true\" tabindex=\"-1\"></a></h3>\n<pre data-lang=\"mermaid\"><code class=\"language-mermaid\" translate=\"no\">graph TD\n    %% Entry\n    CLI[\"bin/cecil\\n(CLI entry point)\"]\n    APP[\"Application\\n(Symfony Console)\"]\n    CMD[\"Commands\\nbuild / serve / doctor\\nnew:* / clear / cache:clear\\nshow:* / util:* / ...\"]\n\n    CLI --&gt; APP --&gt; CMD\n\n    %% Orchestrator\n    BUILDER[\"Builder\\n(Orchestrator)\"]\n    CONFIG[\"Configuration\\n(plugins &lt; default.php\\n&lt; themes &lt; cecil.yml\\n&lt; env vars + CLI options)\"]\n    CMD --&gt; BUILDER\n    CONFIG --&gt; BUILDER\n\n    %% Extensions\n    EXTN[\"Extensions\\n(Autoloader + Loader:\\nplugins, event subscribers,\\ngenerators, Twig extensions,\\npost-processors)\"]\n    EVENTS[\"Build events\\n(build.*, step.*, page.*)\"]\n    BUILDER --&gt; EXTN\n    EXTN -- \"plugins config\" --&gt; CONFIG\n    BUILDER -. \"dispatch\" .-&gt; EVENTS\n    EVENTS -. \"notify subscribers\" .-&gt; EXTN\n\n    %% Pipeline\n    subgraph PIPELINE[\"Build pipeline (steps)\"]\n        S1[\"1. Pages/Load\\n(Finder → Markdown files)\"]\n        S2[\"2. Data/Load\\n(data files)\"]\n        S3[\"3. StaticFiles/Load\\n(if static.load is enabled)\"]\n        S4[\"4. Pages/Create\\n(create Page objects)\"]\n        S5[\"5. Pages/Convert\\n(front matter +\\nMarkdown → HTML)\"]\n        S6[\"6. Taxonomies/Create\\n(create taxonomies)\"]\n        S7[\"7. Pages/Generate\\n(generators)\"]\n        S8[\"8. Menus/Create\\n(create menus)\"]\n        S9[\"9. StaticFiles/Copy\\n(copy static files)\"]\n        S10[\"10. Pages/Render\\n(Twig rendering)\"]\n        S11[\"11. Pages/Save\\n(save pages)\"]\n        S12[\"12. Assets/Save\\n(save assets)\"]\n        S13[\"13-16. Optimize/Html, Css, Js, Images\\n(if optimization is enabled)\"]\n\n        S1 --&gt; S2 --&gt; S3 --&gt; S4 --&gt; S5 --&gt; S6 --&gt; S7 --&gt; S8 --&gt; S9 --&gt; S10 --&gt; S11 --&gt; S12 --&gt; S13\n    end\n\n    BUILDER --&gt; PIPELINE\n\n    %% Subsystems\n    CONV[\"Converter\\n(pages.converter, pages.body.parser:\\nParsedown + highlighter)\"]\n\n    subgraph COLLECTIONS[\"Collections\"]\n        PC[\"PagesCollection\\n(Page objects)\"]\n        TC[\"TaxonomiesCollection\\n(vocabularies/terms)\"]\n        MC[\"MenusCollection\"]\n    end\n\n    subgraph GENERATORS[\"Generators (by priority)\"]\n        G1[\"DefaultPages\\n(index, 404, robots, sitemap, xsl)\"]\n        G3[\"ExternalBody\"]\n        G4[\"Section\"]\n        G5[\"Taxonomy\"]\n        G6[\"Homepage\"]\n        G7[\"Pagination\"]\n        G8[\"Alias\"]\n        G9[\"Redirect\"]\n        G10[\"Custom generators\\n(priority 100 by default)\"]\n        G1 --&gt; G3 --&gt; G4 --&gt; G5 --&gt; G6 --&gt; G7 --&gt; G8 --&gt; G9 --&gt; G10\n    end\n\n    subgraph RENDERER[\"Twig rendering\"]\n        TW[\"Twig engine\"]\n        EXT[\"Twig extensions\\n(Core, Content, Collection,\\nTranslation, Intl, Components\\n+ custom)\"]\n        PP[\"PostProcessors\\n(generator meta tag, excerpts, links\\n+ custom)\"]\n        TH[\"Themes / Layouts\"]\n        TW --&gt; EXT\n        TW --&gt; PP\n        TH --&gt; TW\n    end\n\n    subgraph ASSETS[\"Assets\"]\n        AL[\"Asset locator\"]\n        AC[\"Compiler\\n(SCSS → CSS)\"]\n        AI[\"Image processor\\n(resize, responsive, WebP, AVIF)\"]\n        AO[\"Optimizer\\n(CSS/JS minification,\\nimage optimization)\"]\n    end\n\n    CACHE[\".cache/\\n(assets, templates, translations)\"]\n\n    subgraph OUTPUT[\"Output (_site/)\"]\n        HTML[\"pages (HTML, XML, JSON, etc.)\"]\n        CSS2[\"CSS/JS assets\"]\n        IMG[\"images\"]\n        SF[\"static files\"]\n    end\n\n    S5 --&gt; CONV\n    S4 --&gt; PC\n    S6 --&gt; TC\n    S8 --&gt; MC\n    S7 --&gt; GENERATORS\n    GENERATORS --&gt; PC\n    S10 --&gt; RENDERER\n    EXTN --&gt; GENERATORS\n    EXTN --&gt; EXT\n    EXTN --&gt; PP\n    PIPELINE -. \"step.*, page.*\" .-&gt; EVENTS\n\n    PC --&gt; RENDERER\n    TC --&gt; RENDERER\n    MC --&gt; RENDERER\n    S2 -- \"site.data\" --&gt; RENDERER\n    S3 -- \"site.static\" --&gt; RENDERER\n\n    %% assets are created by the converter (Markdown images, links) and by templates (asset() function),\n    %% processed and stored in cache, then copied to the output\n    CONV --&gt; ASSETS\n    EXT --&gt; ASSETS\n    ASSETS --&gt; CACHE\n    CACHE --&gt; S12\n\n    RENDERER --&gt; S11\n    S11 --&gt; HTML\n    S12 --&gt; CSS2\n    S12 --&gt; IMG\n    S9 --&gt; SF\n    S13 -. \"optimize files in place\" .-&gt; OUTPUT\n\n    %% Inputs\n    subgraph INPUT[\"Sources\"]\n        MD[\"pages/\\n(Markdown + front matter)\"]\n        DATA[\"data/\\n(YAML, JSON, XML, CSV)\"]\n        STATIC[\"static/\"]\n        ASSETSDIR[\"assets/\"]\n        LAYOUTS[\"layouts/\\n(Twig templates)\"]\n        TRANS[\"translations/\"]\n        THEMES[\"themes/\\n(config, layouts, assets,\\nstatic, data, translations,\\nextensions)\"]\n        EXTDIR[\"extensions/\\n(PHP classes)\"]\n    end\n\n    MD --&gt; S1\n    DATA --&gt; S2\n    STATIC --&gt; S3\n    STATIC --&gt; S9\n    ASSETSDIR --&gt; AL\n    LAYOUTS --&gt; TH\n    TRANS --&gt; EXT\n    THEMES --&gt; CONFIG\n    THEMES --&gt; TH\n    THEMES --&gt; EXTN\n    EXTDIR --&gt; EXTN</code></pre>\n<h2 id=\"technical-architecture\">Technical architecture<a class=\"heading-anchor\" href=\"#technical-architecture\" aria-hidden=\"true\" tabindex=\"-1\"></a></h2>\n<p>The diagrams below show how the code is organized in layers, from the command line to the file system, and which libraries each component relies on.</p>\n<h3 id=\"architecture-overview\">Architecture overview<a class=\"heading-anchor\" href=\"#architecture-overview\" aria-hidden=\"true\" tabindex=\"-1\"></a></h3>\n<pre data-lang=\"mermaid\"><code class=\"language-mermaid\" translate=\"no\">graph TB\n    ENTRY[\"Entry points\\n(bin/cecil, cecil.phar)\"]\n    CONSOLE[\"Console\\n(commands)\"]\n    DEV[\"Local server\\n(serve, live reload)\"]\n    CORE[\"Core\\n(Builder, Config, Steps,\\nCollections, Generators)\"]\n    EXTS[\"Extensions\\n(plugins, events)\"]\n    SERVICES[\"Services\\n(Converter, Renderer,\\nAssets, Cache, Doctor)\"]\n    LIBS[\"Libraries\\n(Symfony, Twig, Parsedown,\\nscssphp, Intervention Image, ...)\"]\n    FS[\"File system\\n(sources, .cache/, _site/)\"]\n\n    ENTRY --&gt; CONSOLE --&gt; CORE\n    CONSOLE --&gt; DEV --&gt; CORE\n    CORE &lt;--&gt; EXTS\n    CORE --&gt; SERVICES\n    CORE --&gt; FS\n    SERVICES --&gt; FS\n    SERVICES --&gt; LIBS</code></pre>\n<h3 id=\"detailed-architecture\">Detailed architecture<a class=\"heading-anchor\" href=\"#detailed-architecture\" aria-hidden=\"true\" tabindex=\"-1\"></a></h3>\n<pre data-lang=\"mermaid\"><code class=\"language-mermaid\" translate=\"no\">graph TB\n    %% Distribution and entry points\n    subgraph ENTRY[\"Entry points\"]\n        BIN[\"bin/cecil\\n(Composer)\"]\n        PHAR[\"cecil.phar\\n(Box, self-update)\"]\n    end\n\n    subgraph CONSOLE[\"Console layer (Symfony Console)\"]\n        APP[\"Application\"]\n        ENV[\".env\\n(phpdotenv)\"]\n        BUILD[\"build\"]\n        SERVE[\"serve\"]\n        DOCTOR[\"doctor:*\"]\n        OTHERS[\"new:* / show:* / clear / cache:clear / util:*\"]\n        APP --&gt; BUILD\n        APP --&gt; SERVE\n        APP --&gt; DOCTOR\n        APP --&gt; OTHERS\n        ENV --&gt; APP\n    end\n\n    BIN --&gt; APP\n    PHAR --&gt; APP\n\n    subgraph DEV[\"Local server (serve)\"]\n        PHPS[\"PHP built-in server\\n(.cecil/router.php)\"]\n        WATCH[\"FileWatcher\\n(changes.flag)\"]\n        PROC[\"Build sub-process\\n(Symfony Process)\"]\n        LR[\"livereload.js\\n(Server-Sent Events)\"]\n        WATCH -- \"rebuild\" --&gt; PROC\n        WATCH -- \"notify\" --&gt; PHPS\n        PHPS --&gt; LR\n    end\n\n    SERVE --&gt; DEV\n\n    subgraph CORE[\"Core\"]\n        BUILDER[\"Builder\\n(steps orchestration, metrics)\"]\n        CFG[\"Config\\n(Merger, Deprecations,\\nnette/schema)\"]\n        LOG[\"Logger\\n(PSR-3: Console, Progress, Print)\"]\n        STEPS[\"Steps\\n(StepInterface)\"]\n        COLL[\"Collections\\n(Page, Taxonomy, Menu)\"]\n        GEN[\"Generators\\n(GeneratorManager)\"]\n        BUILDER --&gt; CFG\n        BUILDER --&gt; LOG\n        BUILDER --&gt; STEPS\n        STEPS --&gt; COLL\n        STEPS --&gt; GEN\n    end\n\n    BUILD --&gt; BUILDER\n    PROC --&gt; BUILDER\n    OTHERS --&gt; BUILDER\n\n    subgraph EXTS[\"Extensions\"]\n        AUTO[\"Autoloader\\n(extensions/, PSR-4,\\nextensions/vendor/)\"]\n        LOADER[\"Loader\\n(by name and priority,\\nextensions.strict)\"]\n        PLUG[\"Plugins\\n(Registry)\"]\n        EVT[\"Event dispatcher\\n(BuildEvents, subscribers)\"]\n        PLUG --&gt; LOADER\n    end\n\n    BUILDER --&gt; AUTO\n    BUILDER --&gt; PLUG\n    PLUG -- \"default config\" --&gt; CFG\n    BUILDER -- \"dispatch\" --&gt; EVT\n    STEPS -- \"dispatch\" --&gt; EVT\n    LOADER --&gt; GEN\n\n    subgraph SERVICES[\"Services\"]\n        CONV[\"Converter\\n(ConverterInterface, Parsedown Extra + TOC,\\nhighlight.php / Tempest)\"]\n        REND[\"Renderer\\n(Twig, Symfony Translation,\\nTwig Components)\"]\n        ASSET[\"Asset\\n(Locator, Compiler, Image, Optimizer)\"]\n        CACHE[\"Cache\\n(PSR-16, files)\"]\n        DOC[\"Doctor\\n(Site, Frontmatter, Links, SEO)\"]\n    end\n\n    STEPS --&gt; CONV\n    STEPS --&gt; REND\n    STEPS --&gt; ASSET\n    REND --&gt; ASSET\n    CONV --&gt; ASSET\n    ASSET --&gt; CACHE\n    REND --&gt; CACHE\n    DOCTOR --&gt; DOC\n    DOC --&gt; BUILDER\n    LOADER --&gt; REND\n\n    subgraph LIBS[\"Main libraries\"]\n        L1[\"Symfony\\n(Finder, Filesystem, Yaml, Serializer,\\nValidator, DomCrawler, EventDispatcher)\"]\n        L2[\"scssphp\"]\n        L3[\"Intervention Image\\n(GD, Imagick, libvips)\"]\n        L4[\"matthiasmullie/minify\\nvoku/html-min\"]\n        L5[\"spatie/image-optimizer\\n(external binaries)\"]\n        L6[\"yosymfony/toml\"]\n        L7[\"getID3, mp3info\\n(audio/video metadata)\"]\n    end\n\n    CORE --&gt; L1\n    ASSET --&gt; L2\n    ASSET --&gt; L3\n    ASSET --&gt; L4\n    STEPS --&gt; L4\n    ASSET --&gt; L5\n    CONV --&gt; L6\n    ASSET --&gt; L7\n\n    subgraph FS[\"File system\"]\n        SRC[\"Sources\\n(pages/, data/, assets/, static/,\\nlayouts/, translations/, themes/,\\nextensions/)\"]\n        CACHEDIR[\".cache/\"]\n        TMP[\".cecil/\\n(router, live reload, metrics, logs)\"]\n        OUT[\"_site/\"]\n    end\n\n    STEPS -- \"read\" --&gt; SRC\n    AUTO -- \"read\" --&gt; SRC\n    CACHE --&gt; CACHEDIR\n    STEPS -- \"write\" --&gt; OUT\n    PHPS -- \"serve\" --&gt; OUT\n    DEV --&gt; TMP</code></pre>\n<h2 id=\"key-components\">Key components<a class=\"heading-anchor\" href=\"#key-components\" aria-hidden=\"true\" tabindex=\"-1\"></a></h2>\n<table>\n<thead>\n<tr>\n<th>Component</th>\n<th>Role</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><strong>Builder</strong></td>\n<td>Central orchestrator that executes steps in sequence</td>\n</tr>\n<tr>\n<td><strong>Config</strong></td>\n<td>Merges plugins, default, themes and project configuration (<code translate=\"no\">Config\\Merger</code>), environment variables (<code translate=\"no\">CECIL_*</code>) and CLI options, and reports deprecated options (<code translate=\"no\">Config\\Deprecations</code>)</td>\n</tr>\n<tr>\n<td><strong>Steps</strong></td>\n<td>Modular pipeline (16 steps), each with <code translate=\"no\">init()</code> / <code translate=\"no\">canProcess()</code> / <code translate=\"no\">process()</code></td>\n</tr>\n<tr>\n<td><strong>Collections</strong></td>\n<td>Pages, Taxonomies, Menus: core data structures</td>\n</tr>\n<tr>\n<td><strong>Converter</strong></td>\n<td>Parses the front matter (YAML, INI, TOML or JSON) and converts Markdown to HTML (Parsedown, code highlighting); replaceable with <code translate=\"no\">pages.converter</code> and <code translate=\"no\">pages.body.parser</code></td>\n</tr>\n<tr>\n<td><strong>Generators</strong></td>\n<td>Create or update pages (default pages, sections, taxonomies, pagination, aliases, redirects, etc.)</td>\n</tr>\n<tr>\n<td><strong>Extensions</strong></td>\n<td>Generators, Twig extensions, post-processors, event subscribers and plugins declared by name, loaded and validated by <code translate=\"no\">Extension\\Loader</code>, autoloaded by <code translate=\"no\">Extension\\Autoloader</code></td>\n</tr>\n<tr>\n<td><strong>Events</strong></td>\n<td>Build events (<code translate=\"no\">Event\\BuildEvents</code>) dispatched around the build, each step and each page lifecycle, to <a href=\"1-extend.md#build-events\">extend Cecil</a></td>\n</tr>\n<tr>\n<td><strong>Renderer (Twig)</strong></td>\n<td>Applies templates + extensions + post-processors</td>\n</tr>\n<tr>\n<td><strong>Assets</strong></td>\n<td>Created from Markdown content and templates: compiles SCSS, minifies, resizes and converts images, fingerprints files</td>\n</tr>\n<tr>\n<td><strong>Cache</strong></td>\n<td>Stores processed assets, compiled templates and translations in <code translate=\"no\">.cache/</code> to speed up subsequent builds</td>\n</tr>\n<tr>\n<td><strong>Doctor</strong></td>\n<td>Diagnoses the project: front matter, links, SEO, cache (<code translate=\"no\">doctor</code> commands)</td>\n</tr>\n</tbody>\n</table>",
      "language": "en"
    },
    {
      "id": "https://cloudflare.cecil.app/documentation/developers/library/",
      "url": "https://cloudflare.cecil.app/documentation/developers/library/",
      "title": "Library",
      "summary": "Use Cecil as a PHP library: install it with Composer, then build, convert Markdown and diagnose programmatically.",
      "date_published": "2023-12-13T00:00:00+00:00",
      "date_modified": "2026-10-30T00:00:00+00:00","content_text": "Library\nCecil provides a simple PHP API to build your website.\nYou can read the API documentation for more details.\nInstallation\ncomposer require cecil\/cecil\nlibvips support\nTo process images with libvips (optional), install the libvips driver in your project:\ncomposer require intervention\/image-driver-vips\nThis driver requires libvips installed on your system and the PHP FFI extension enabled.\nCecil uses Imagick when available, otherwise libvips (if installed), otherwise GD.\nUsage\nBuild\nBuild a new website with a custom configuration:\n&lt;?php\n\nrequire_once 'vendor\/autoload.php';\n\nuse Cecil\\Builder;\n\n$config = [\n    'title'   =&gt; \"My website\",\n    'baseurl' =&gt; 'https:\/\/domain.tld\/',\n];\n\nBuilder::create($config)\n    -&gt;setSourceDir(__DIR__)      \/\/ directory of the website sources (current directory by default)\n    -&gt;setDestinationDir(__DIR__) \/\/ where the output directory (`_site`) is created (source directory by default)\n    -&gt;build([]);\n\nexec('php -S localhost:8000 -t _site'); \/\/ preview locally\nBuilder::create() accepts a PHP array or a Cecil\\Config instance, and optionally a PSR-3 logger.\nThe build() method accepts an array of options:\n\n\n\nOption\nDescription\nDefault\n\n\n\n\ndrafts\nIncludes drafts.\nfalse\n\n\ndry-run\nBuilds without saving files.\nfalse\n\n\npage\nBuilds a specific page.\n''\n\n\nrender-subset\nRenders a named subset of pages.\n''\n\n\n\nThese options match the build command options.\nMarkdown\nConvert Markdown to HTML like Cecil does (Markdown parser of the site, pages.body configuration, notes, code highlighting), without building the website: e.g. to preview a page while it is edited.\n&lt;?php\n\nrequire_once 'vendor\/autoload.php';\n\nuse Cecil\\Builder;\nuse Cecil\\Converter\\ParserFactory;\n\n$builder = Builder::create(require 'config.php')-&gt;setSourceDir(__DIR__);\n\n$parser = ParserFactory::create($builder, [\n    'language'  =&gt; 'en',\n    'assets'    =&gt; false,\n    'asset_url' =&gt; fn (string $path): string =&gt; 'http:\/\/localhost:8000' . $path,\n]);\n\necho $parser-&gt;text(file_get_contents('pages\/index.md'));\nThe Markdown parser options:\n\n\n\nOption\nDescription\nDefault\n\n\n\n\nlanguage\nLanguage of the content.\nnull\n\n\nselectors\nHeadings of the table of contents.\npages.body.toc\n\n\nassets\nProcesses the files of the body (images, video and audio) as assets (located, resized, converted, copied): with false, they are kept as they are.\ntrue\n\n\nasset_url\nWith assets set to false, a callable returning the URL of a local file from its path in the body.\nnull\n\n\n\nWithout processing the files as assets, a missing image does not throw an exception, nothing is written to the cache, and remote images are not downloaded.\nDiagnostics\nYou can also run doctor checks through dedicated domain services, without using CLI commands:\n\nCecil\\Doctor\\SiteDoctor::diagnose(): configuration and environment\nCecil\\Doctor\\FrontmatterDoctor::diagnose(): front matter of pages\nCecil\\Doctor\\SeoDoctor::audit(): SEO of rendered pages (runs a dry-run build)\nCecil\\Doctor\\LinksDoctor::audit(): internal and external links\n\n&lt;?php\n\nrequire_once 'vendor\/autoload.php';\n\nuse Cecil\\Builder;\nuse Cecil\\Doctor\\SeoDoctor;\nuse Cecil\\Doctor\\SiteDoctor;\n\n$builder = Builder::create(require 'config.php')\n    -&gt;setSourceDir(__DIR__)\n    -&gt;setDestinationDir(__DIR__);\n\n$siteDoctor = new SiteDoctor();\n$diagnosis = $siteDoctor-&gt;diagnose($builder, __DIR__, ['cecil.yml']);\n\n$seoDoctor = new SeoDoctor();\n$seoAudit = $seoDoctor-&gt;audit($builder, [\n    'page' =&gt; '',\n    'include_generated' =&gt; false,\n]);\n\nvar_dump($diagnosis['errors'], $seoAudit['summary']);",
      "content_html": "<h1>Library</h1>\n<p>Cecil provides a simple PHP API to build your website.</p>\n<p>You can read the <a href=\"https://cloudflare.cecil.app/documentation/library/api/namespaces/cecil.html\">API documentation</a> for more details.</p>\n<h2 id=\"installation\">Installation<a class=\"heading-anchor\" href=\"#installation\" aria-hidden=\"true\" tabindex=\"-1\"></a></h2>\n<pre data-lang=\"bash\"><code class=\"language-bash hljs bash\" translate=\"no\">composer require cecil/cecil</code></pre>\n<h3 id=\"libvips-support\">libvips support<a class=\"heading-anchor\" href=\"#libvips-support\" aria-hidden=\"true\" tabindex=\"-1\"></a></h3>\n<p>To process images with <a href=\"https://www.libvips.org/\" target=\"_blank\" rel=\"noopener noreferrer\">libvips</a> (optional), install the libvips driver in your project:</p>\n<pre data-lang=\"bash\"><code class=\"language-bash hljs bash\" translate=\"no\">composer require intervention/image-driver-vips</code></pre>\n<aside class=\"note note-important\"><p>This driver requires <a href=\"https://www.libvips.org/install.html\" target=\"_blank\" rel=\"noopener noreferrer\">libvips</a> installed on your system and the PHP <a href=\"https://www.php.net/manual/book.ffi.php\" target=\"_blank\" rel=\"noopener noreferrer\">FFI</a> extension enabled.</p>\n<p>Cecil uses <a href=\"https://www.php.net/manual/book.imagick.php\" target=\"_blank\" rel=\"noopener noreferrer\">Imagick</a> when available, otherwise libvips (if installed), otherwise <a href=\"https://www.php.net/manual/book.image.php\" target=\"_blank\" rel=\"noopener noreferrer\">GD</a>.</p></aside>\n<h2 id=\"usage\">Usage<a class=\"heading-anchor\" href=\"#usage\" aria-hidden=\"true\" tabindex=\"-1\"></a></h2>\n<h3 id=\"build\">Build<a class=\"heading-anchor\" href=\"#build\" aria-hidden=\"true\" tabindex=\"-1\"></a></h3>\n<p>Build a new website with a custom configuration:</p>\n<pre data-lang=\"php\"><code class=\"language-php hljs php\" translate=\"no\"><span class=\"hljs-meta\">&lt;?php</span>\n\n<span class=\"hljs-keyword\">require_once</span> <span class=\"hljs-string\">'vendor/autoload.php'</span>;\n\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Builder</span>;\n\n$config = [\n    <span class=\"hljs-string\">'title'</span>   =&gt; <span class=\"hljs-string\">\"My website\"</span>,\n    <span class=\"hljs-string\">'baseurl'</span> =&gt; <span class=\"hljs-string\">'https://domain.tld/'</span>,\n];\n\nBuilder::create($config)\n    -&gt;setSourceDir(<span class=\"hljs-keyword\">__DIR__</span>)      <span class=\"hljs-comment\">// directory of the website sources (current directory by default)</span>\n    -&gt;setDestinationDir(<span class=\"hljs-keyword\">__DIR__</span>) <span class=\"hljs-comment\">// where the output directory (`_site`) is created (source directory by default)</span>\n    -&gt;build([]);\n\nexec(<span class=\"hljs-string\">'php -S localhost:8000 -t _site'</span>); <span class=\"hljs-comment\">// preview locally</span></code></pre>\n<aside class=\"note note-info\"><p><code translate=\"no\">Builder::create()</code> accepts a PHP <code translate=\"no\">array</code> or a <a href=\"https://github.com/Cecilapp/Cecil/blob/main/src/Config.php\" target=\"_blank\" rel=\"noopener noreferrer\"><code translate=\"no\">Cecil\\Config</code></a> instance, and optionally a <a href=\"https://www.php-fig.org/psr/psr-3/\" target=\"_blank\" rel=\"noopener noreferrer\">PSR-3</a> logger.</p></aside>\n<p>The <code translate=\"no\">build()</code> method accepts an array of options:</p>\n<table>\n<thead>\n<tr>\n<th>Option</th>\n<th>Description</th>\n<th>Default</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code translate=\"no\">drafts</code></td>\n<td>Includes drafts.</td>\n<td><code translate=\"no\">false</code></td>\n</tr>\n<tr>\n<td><code translate=\"no\">dry-run</code></td>\n<td>Builds without saving files.</td>\n<td><code translate=\"no\">false</code></td>\n</tr>\n<tr>\n<td><code translate=\"no\">page</code></td>\n<td>Builds a specific page.</td>\n<td><code translate=\"no\">''</code></td>\n</tr>\n<tr>\n<td><code translate=\"no\">render-subset</code></td>\n<td>Renders a named subset of pages.</td>\n<td><code translate=\"no\">''</code></td>\n</tr>\n</tbody>\n</table>\n<p>These options match the <a href=\"../commands/4-build.md\"><code translate=\"no\">build</code></a> command options.</p>\n<h3 id=\"markdown\">Markdown<a class=\"heading-anchor\" href=\"#markdown\" aria-hidden=\"true\" tabindex=\"-1\"></a></h3>\n<p>Convert Markdown to HTML like Cecil does (Markdown parser of the site, <a href=\"../configuration/4-pages.md#pages-body\"><code translate=\"no\">pages.body</code></a> configuration, notes, code highlighting), without building the website: e.g. to preview a page while it is edited.</p>\n<pre data-lang=\"php\"><code class=\"language-php hljs php\" translate=\"no\"><span class=\"hljs-meta\">&lt;?php</span>\n\n<span class=\"hljs-keyword\">require_once</span> <span class=\"hljs-string\">'vendor/autoload.php'</span>;\n\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Builder</span>;\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Converter</span>\\<span class=\"hljs-title\">ParserFactory</span>;\n\n$builder = Builder::create(<span class=\"hljs-keyword\">require</span> <span class=\"hljs-string\">'config.php'</span>)-&gt;setSourceDir(<span class=\"hljs-keyword\">__DIR__</span>);\n\n$parser = ParserFactory::create($builder, [\n    <span class=\"hljs-string\">'language'</span>  =&gt; <span class=\"hljs-string\">'en'</span>,\n    <span class=\"hljs-string\">'assets'</span>    =&gt; <span class=\"hljs-keyword\">false</span>,\n    <span class=\"hljs-string\">'asset_url'</span> =&gt; fn (string $path): string =&gt; <span class=\"hljs-string\">'http://localhost:8000'</span> . $path,\n]);\n\n<span class=\"hljs-keyword\">echo</span> $parser-&gt;text(file_get_contents(<span class=\"hljs-string\">'pages/index.md'</span>));</code></pre>\n<p>The Markdown parser options:</p>\n<table>\n<thead>\n<tr>\n<th>Option</th>\n<th>Description</th>\n<th>Default</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code translate=\"no\">language</code></td>\n<td>Language of the content.</td>\n<td><code translate=\"no\">null</code></td>\n</tr>\n<tr>\n<td><code translate=\"no\">selectors</code></td>\n<td>Headings of the table of contents.</td>\n<td><code translate=\"no\">pages.body.toc</code></td>\n</tr>\n<tr>\n<td><code translate=\"no\">assets</code></td>\n<td>Processes the files of the body (images, video and audio) as assets (located, resized, converted, copied): with <code translate=\"no\">false</code>, they are kept as they are.</td>\n<td><code translate=\"no\">true</code></td>\n</tr>\n<tr>\n<td><code translate=\"no\">asset_url</code></td>\n<td>With <code translate=\"no\">assets</code> set to <code translate=\"no\">false</code>, a callable returning the URL of a local file from its path in the body.</td>\n<td><code translate=\"no\">null</code></td>\n</tr>\n</tbody>\n</table>\n<aside class=\"note note-tip\"><p>Without processing the files as assets, a missing image does not throw an exception, nothing is written to the cache, and remote images are not downloaded.</p></aside>\n<h3 id=\"diagnostics\">Diagnostics<a class=\"heading-anchor\" href=\"#diagnostics\" aria-hidden=\"true\" tabindex=\"-1\"></a></h3>\n<p>You can also run doctor checks through dedicated domain services, without using CLI commands:</p>\n<ul>\n<li><code translate=\"no\">Cecil\\Doctor\\SiteDoctor::diagnose()</code>: configuration and environment</li>\n<li><code translate=\"no\">Cecil\\Doctor\\FrontmatterDoctor::diagnose()</code>: front matter of pages</li>\n<li><code translate=\"no\">Cecil\\Doctor\\SeoDoctor::audit()</code>: SEO of rendered pages (runs a dry-run build)</li>\n<li><code translate=\"no\">Cecil\\Doctor\\LinksDoctor::audit()</code>: internal and external links</li>\n</ul>\n<pre data-lang=\"php\"><code class=\"language-php hljs php\" translate=\"no\"><span class=\"hljs-meta\">&lt;?php</span>\n\n<span class=\"hljs-keyword\">require_once</span> <span class=\"hljs-string\">'vendor/autoload.php'</span>;\n\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Builder</span>;\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Doctor</span>\\<span class=\"hljs-title\">SeoDoctor</span>;\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Doctor</span>\\<span class=\"hljs-title\">SiteDoctor</span>;\n\n$builder = Builder::create(<span class=\"hljs-keyword\">require</span> <span class=\"hljs-string\">'config.php'</span>)\n    -&gt;setSourceDir(<span class=\"hljs-keyword\">__DIR__</span>)\n    -&gt;setDestinationDir(<span class=\"hljs-keyword\">__DIR__</span>);\n\n$siteDoctor = <span class=\"hljs-keyword\">new</span> SiteDoctor();\n$diagnosis = $siteDoctor-&gt;diagnose($builder, <span class=\"hljs-keyword\">__DIR__</span>, [<span class=\"hljs-string\">'cecil.yml'</span>]);\n\n$seoDoctor = <span class=\"hljs-keyword\">new</span> SeoDoctor();\n$seoAudit = $seoDoctor-&gt;audit($builder, [\n    <span class=\"hljs-string\">'page'</span> =&gt; <span class=\"hljs-string\">''</span>,\n    <span class=\"hljs-string\">'include_generated'</span> =&gt; <span class=\"hljs-keyword\">false</span>,\n]);\n\nvar_dump($diagnosis[<span class=\"hljs-string\">'errors'</span>], $seoAudit[<span class=\"hljs-string\">'summary'</span>]);</code></pre>",
      "language": "en"
    },
    {
      "id": "https://cloudflare.cecil.app/documentation/developers/extend/",
      "url": "https://cloudflare.cecil.app/documentation/developers/extend/",
      "title": "Extend Cecil",
      "summary": "Create custom page generators, add Twig extensions, post-process output files and listen to build events.",
      "date_published": "2023-04-17T00:00:00+00:00",
      "date_modified": "2026-10-30T00:00:00+00:00","content_text": "Extend Cecil\nBecause Cecil is written in PHP, it's easy to extend its capabilities.\nUse the new:extension command to create the skeleton of an extension: cecil new:extension --type=generator --name=Database --namespace=MySite.\nAutoloading\nCustom classes are autoloaded from the extensions directory of your site (or of a theme), the file path matching the namespace: the class MySite\\Generator\\MyGenerator is loaded from extensions\/MySite\/Generator\/MyGenerator.php.\nTo use another layout, declare PSR-4 mappings, relative to the site (or theme) directory:\nextensions:\n  autoload:\n    'MySite\\': src\/ # `MySite\\Generator\\MyGenerator` is loaded from `src\/Generator\/MyGenerator.php`\nIf your extensions depend on third-party libraries, install them with Composer in the extensions directory (composer require &lt;package&gt; --working-dir=extensions): extensions\/vendor\/autoload.php is loaded automatically, even with the Cecil phar. Libraries already provided by Cecil are not overridden.\nUse your own namespace (e.g.: MySite\\ or the name of your theme): the Cecil\\ namespace is reserved, and using it for custom classes is deprecated.\nConfiguration\nPage generators, Twig extensions, output post-processors, build events subscribers and plugins are declared the same way, as a map indexed by name:\n&lt;key&gt;:\n  &lt;name&gt;: &lt;class&gt;                                         # default priority (100)\n  &lt;name&gt;: { class: &lt;class&gt;, priority: &lt;int&gt; }             # explicit priority\n  &lt;name&gt;: false                                           # disabled\n\nExtensions run in ascending order of their priority; without a priority, they run after the built-in ones (priority 100), in their declaration order.\nA built-in extension can be disabled (Redirect: false) or moved (Section: { priority: 45 }) by its name.\nAn extension that cannot be loaded (unknown class, wrong interface, invalid option) is skipped and the error is logged. To fail the build instead, enable the strict mode (false only logs the error, without the Cecil 10 warning):\n\nextensions:\n  strict: true\nIndexing extensions by priority (e.g.: 35: MySite\\Generator\\Database) or by position (a list) is deprecated: it is still supported, with a warning, but will not be in Cecil 10. Use Database: { class: MySite\\Generator\\Database, priority: 35 } instead.\nIn Cecil 10, the strict mode will be enabled by default.\nPage generators\nA generator helps you create pages without Markdown files (for example, with data from an API or a database) or alter existing pages.\nCreate a new PHP class extending Cecil\\Generator\\AbstractGenerator, and add it to the pages.generators list.\nBuilt-in generators use the priorities 10 to 90: choose the priority of your generator depending on the pages it needs (e.g.: after Section to access sections pages).\nA generator adds pages to $this-&gt;generatedPages (a page with the ID of an existing page replaces it), and can remove existing pages with $this-&gt;removePage('&lt;page-id&gt;').\nExample:\n\/extensions\/MySite\/Generator\/DummyPage.php\n&lt;?php\nnamespace MySite\\Generator;\n\nuse Cecil\\Collection\\Page\\Page;\nuse Cecil\\Collection\\Page\\Type;\nuse Cecil\\Generator\\AbstractGenerator;\nuse Cecil\\Generator\\GeneratorInterface;\n\nclass DummyPage extends AbstractGenerator implements GeneratorInterface\n{\n    public function generate(): void\n    {\n        \/\/ create a new page $page, then add it to the site collection\n        $page = (new Page('my-page'))\n            -&gt;setType(Type::PAGE)\n            -&gt;setPath('mypage')\n            -&gt;setBodyHtml('&lt;p&gt;My page body&lt;\/p&gt;')\n            -&gt;setVariable('language', 'en')\n            -&gt;setVariable('title', 'My page')\n            -&gt;setVariable('date', new \\DateTime())\n            -&gt;setVariable('menu', ['main' =&gt; ['weight' =&gt; 99]]);\n        $this-&gt;generatedPages-&gt;add($page);\n    }\n}\n\/extensions\/MySite\/Generator\/Database.php\n&lt;?php\nnamespace MySite\\Generator;\n\nuse Cecil\\Collection\\Page\\Page;\nuse Cecil\\Collection\\Page\\Type;\nuse Cecil\\Generator\\AbstractGenerator;\nuse Cecil\\Generator\\GeneratorInterface;\n\nclass Database extends AbstractGenerator implements GeneratorInterface\n{\n    public function generate(): void\n    {\n        \/\/ create pages from a SQLite database\n        $db = new \\SQLite3('database.sqlite');\n        $statement = $db-&gt;prepare('SELECT * FROM blog');\n        $result = $statement-&gt;execute();\n        while ($row = $result-&gt;fetchArray(\\SQLITE3_ASSOC)) {\n            $page = (new Page($row['page-id']))\n                -&gt;setType(Type::PAGE)\n                -&gt;setPath($row['path'])\n                -&gt;setBodyHtml($row['html'])\n                -&gt;setVariable('title', $row['title'])\n                -&gt;setVariable('date', $row['date']);\n            $this-&gt;generatedPages-&gt;add($page);\n        }\n        $result-&gt;finalize();\n        $db-&gt;close();\n    }\n}\nconfiguration\npages:\n  generators:\n    DummyPage: MySite\\Generator\\DummyPage\n    Database: { class: MySite\\Generator\\Database, priority: 35 }\nTwig extension\nYou can add custom functions and filters:\n\ncreate a Twig extension\nadd the PHP file in the extensions directory (see Autoloading)\nadd it to the layouts.extensions configuration\n\nThe extension constructor receives the Cecil\\Builder instance, which gives access to the configuration and the site content.\nExample:\n\/extensions\/MySite\/Twig\/MyTwigExtension.php\n&lt;?php\nnamespace MySite\\Twig;\n\nclass MyTwigExtension extends \\Twig\\Extension\\AbstractExtension\n{\n    public function getFilters(): array\n    {\n        \/\/ add a new filter named 'md5'\n        return [\n            new \\Twig\\TwigFilter('md5', 'md5'),\n        ];\n    }\n}\nconfiguration\nlayouts:\n  extensions:\n    MyExtension: MySite\\Twig\\MyTwigExtension\nOutput post-processors\nYou can post-process the rendered output of pages.\nCreate a new PHP class extending Cecil\\Renderer\\PostProcessor\\AbstractPostProcessor, and add it to the output.postprocessors list.\nBuilt-in post-processors (GeneratorMetaTag, HtmlExcerpt and MarkdownLink) use the priorities 10 to 30, so they run first by default.\nExample:\n\/extensions\/MySite\/PostProcessor\/MyProcessor.php\n&lt;?php\nnamespace MySite\\PostProcessor;\n\nuse Cecil\\Collection\\Page\\Page;\nuse Cecil\\Renderer\\PostProcessor\\AbstractPostProcessor;\n\nclass MyProcessor extends AbstractPostProcessor\n{\n    public function process(Page $page, string $output, string $format): string\n    {\n        \/\/ add a meta tag to the head of the HTML output\n        if ($format == 'html') {\n            if (!preg_match('\/&lt;meta name=\"test\".*\/i', $output)) {\n                $meta = '&lt;meta name=\"test\" content=\"Test\"&gt;';\n                $output = preg_replace_callback('\/([[:blank:]]*)(&lt;\\\/head&gt;)\/i', function ($matches) use ($meta) {\n                    return str_repeat($matches[1] ?: ' ', 2) . $meta . \"\\n\" . $matches[1] . $matches[2];\n                }, $output);\n            }\n        }\n\n        return $output;\n    }\n}\nconfiguration\noutput:\n  postprocessors:\n    MyProcessor: MySite\\PostProcessor\\MyProcessor\nMarkdown converter\nThe front matter and the Markdown body of pages are converted by the class defined in pages.converter. It is also used by the markdown_to_html filter and for external pages (the toc filter uses the Markdown parser directly).\nTo change the conversion, create a PHP class implementing Cecil\\Converter\\ConverterInterface (its constructor receives the Cecil\\Builder instance), or extending the default Cecil\\Converter\\Converter class.\nExample:\n\/extensions\/MySite\/Converter.php\n&lt;?php\nnamespace MySite;\n\nclass Converter extends \\Cecil\\Converter\\Converter\n{\n    public function convertBody(string $string, ?string $language = null): string\n    {\n        \/\/ replaces `[[page-id]]` with a link, before the default conversion\n        $string = preg_replace('\/\\[\\[([a-z0-9-\\\/]+)\\]\\]\/', '[$1]($1.md)', $string);\n\n        return parent::convertBody($string, $language);\n    }\n}\nconfiguration\npages:\n  converter: MySite\\Converter\nMarkdown parser\nTo add your own Markdown syntax, replace the Markdown parser used by the default converter (and by the markdown_to_html and toc filters) with the pages.body.parser option.\nCreate a PHP class extending Cecil\\Converter\\Parsedown, based on Parsedown (1.x) and Parsedown Extra, and register your syntax with its extension mechanism: a marker character in $this-&gt;InlineTypes (or $this-&gt;BlockTypes) refers to an inline&lt;Type&gt;() method (or block&lt;Type&gt;(), block&lt;Type&gt;Continue() and block&lt;Type&gt;Complete() methods).\nA custom parser relies on Parsedown internals: it may need to be updated when Cecil upgrades Parsedown.\nThe parser can also be created outside of a build (see Library): pass the options to the parent constructor, and do not rely on the state of a build (e.g. the pages collection).\nExample:\n\/extensions\/MySite\/Parsedown.php\n&lt;?php\nnamespace MySite;\n\nuse Cecil\\Builder;\n\nclass Parsedown extends \\Cecil\\Converter\\Parsedown\n{\n    public function __construct(Builder $builder, ?array $options = null)\n    {\n        parent::__construct($builder, $options);\n        \/\/ `==text==` → `&lt;mark&gt;text&lt;\/mark&gt;`\n        $this-&gt;InlineTypes['='][] = 'Mark';\n        $this-&gt;inlineMarkerList .= '=';\n    }\n\n    protected function inlineMark($Excerpt)\n    {\n        if (preg_match('\/^==(?=\\S)(.+?)(?&lt;=\\S)==\/', $Excerpt['text'], $matches)) {\n            return [\n                'extent'  =&gt; \\strlen($matches[0]),\n                'element' =&gt; ['name' =&gt; 'mark', 'text' =&gt; $matches[1], 'handler' =&gt; 'line'],\n            ];\n        }\n\n        return null;\n    }\n}\nconfiguration\npages:\n  body:\n    parser: MySite\\Parsedown\nBuild events\nEvents are dispatched during the build: listen to them to run your own code before or after the build, each step, or at each step of the life cycle of a page (e.g.: to create a search index, notify a service, or modify the output of pages).\n\n\n\nEvent\nConstant\nWhen\nEvent class\n\n\n\n\nbuild.start\nBuildEvents::BUILD_START\nbefore the first step\nBuildEvent\n\n\nbuild.finished\nBuildEvents::BUILD_FINISHED\nafter the last step\nBuildEvent\n\n\nstep.pre\nBuildEvents::STEP_PRE\nbefore each step\nStepEvent\n\n\nstep.post\nBuildEvents::STEP_POST\nafter each step\nStepEvent\n\n\npage.created\nBuildEvents::PAGE_CREATED\nafter a page is created from a content file\nPageEvent\n\n\npage.converted\nBuildEvents::PAGE_CONVERTED\nafter a published page is converted (front matter and body)\nPageEvent\n\n\npage.rendered\nBuildEvents::PAGE_RENDERED\nafter a page is rendered in a format (after post-processors)\nPageRenderedEvent\n\n\npage.saved\nBuildEvents::PAGE_SAVED\nafter a rendered page is saved to a file\nPageSavedEvent\n\n\n\nEvery event gives access to the build context (getBuilder()) and options (getOptions()); StepEvent adds getStep(), PageEvent adds getPage(), PageRenderedEvent adds getFormat(), getOutput() and setOutput(), PageSavedEvent adds getFormat() and getPathname().\nCreate an event subscriber extending Cecil\\Event\\AbstractSubscriber (which gives access to $this-&gt;builder and $this-&gt;config), and add it to the extensions.subscribers list.\nExample:\n\/extensions\/MySite\/SearchIndex.php\n&lt;?php\nnamespace MySite;\n\nuse Cecil\\Event\\AbstractSubscriber;\nuse Cecil\\Event\\BuildEvent;\nuse Cecil\\Event\\BuildEvents;\nuse Cecil\\Event\\PageEvent;\n\nclass SearchIndex extends AbstractSubscriber\n{\n    private array $index = [];\n\n    public static function getSubscribedEvents(): array\n    {\n        return [\n            BuildEvents::PAGE_CONVERTED =&gt; 'onPageConverted',\n            BuildEvents::BUILD_FINISHED =&gt; 'onBuildFinished',\n        ];\n    }\n\n    public function onPageConverted(PageEvent $event): void\n    {\n        $page = $event-&gt;getPage();\n        $this-&gt;index[] = ['title' =&gt; $page-&gt;getVariable('title'), 'path' =&gt; $page-&gt;getPath()];\n    }\n\n    public function onBuildFinished(BuildEvent $event): void\n    {\n        if ($event-&gt;getOptions()['dry-run']) {\n            return;\n        }\n        file_put_contents($this-&gt;config-&gt;getOutputPath() . '\/search.json', json_encode($this-&gt;index));\n    }\n}\nconfiguration\nextensions:\n  subscribers:\n    SearchIndex: MySite\\SearchIndex\nWhen using Cecil as a PHP library, listeners can also be added directly to the dispatcher before the build: $builder-&gt;getEventDispatcher()-&gt;addListener(BuildEvents::PAGE_SAVED, $callable).\nPlugins\nA plugin is a single entry point that registers a set of extensions: generators, Twig extensions, post-processors, event subscribers and listeners, and default configuration. It's the recommended way to ship extensions with a theme: enabling the theme enables its plugin, with no other configuration.\nCreate a PHP class extending Cecil\\Plugin\\AbstractPlugin (which gives access to $this-&gt;builder and $this-&gt;config), and add it to the extensions.plugins list.\nExample:\n\/themes\/example\/extensions\/Example\/ExamplePlugin.php\n&lt;?php\nnamespace Example;\n\nuse Cecil\\Event\\BuildEvents;\nuse Cecil\\Plugin\\AbstractPlugin;\nuse Cecil\\Plugin\\Registry;\n\nclass ExamplePlugin extends AbstractPlugin\n{\n    public function register(Registry $registry): void\n    {\n        $registry\n            -&gt;config(['example' =&gt; ['feed' =&gt; ['limit' =&gt; 10]]]) \/\/ default options\n            -&gt;twigExtension(Twig\\ExampleExtension::class)\n            -&gt;generator(Generator\\Feed::class, priority: 35)\n            -&gt;postProcessor(PostProcessor\\Minify::class)\n            -&gt;subscriber(SearchIndex::class)\n            -&gt;listen(BuildEvents::BUILD_FINISHED, fn () =&gt; $this-&gt;builder-&gt;getLogger()-&gt;notice('Example is ready'));\n    }\n}\n\/themes\/example\/config.yml\nextensions:\n  plugins:\n    Example: Example\\ExamplePlugin\nExtensions registered by a plugin are named after their short class name (e.g.: Feed), unless a name is given, and use the default priority (100) unless a priority is given. The plugin configuration has the lowest precedence: the site (and themes) configuration can override its options, and disable (Feed: false) or move (Feed: { priority: 45 }) its extensions by name.",
      "content_html": "<h1>Extend Cecil</h1>\n<p>Because Cecil is written in PHP, it's easy to extend its capabilities.</p>\n<aside class=\"note note-tip\"><p>Use the <a href=\"../commands/6-new-extension.md\"><code translate=\"no\">new:extension</code></a> command to create the skeleton of an extension: <code translate=\"no\">cecil new:extension --type=generator --name=Database --namespace=MySite</code>.</p></aside>\n<h2 id=\"autoloading\">Autoloading<a class=\"heading-anchor\" href=\"#autoloading\" aria-hidden=\"true\" tabindex=\"-1\"></a></h2>\n<p>Custom classes are autoloaded from the <code translate=\"no\">extensions</code> directory of your site (or of a theme), the file path matching the namespace: the class <code translate=\"no\">MySite\\Generator\\MyGenerator</code> is loaded from <code translate=\"no\">extensions/MySite/Generator/MyGenerator.php</code>.</p>\n<p>To use another layout, declare <a href=\"https://www.php-fig.org/psr/psr-4/\" target=\"_blank\" rel=\"noopener noreferrer\">PSR-4</a> mappings, relative to the site (or theme) directory:</p>\n<pre data-lang=\"yaml\"><code class=\"language-yaml hljs yaml\" translate=\"no\"><span class=\"hljs-attr\">extensions:</span>\n  <span class=\"hljs-attr\">autoload:</span>\n    <span class=\"hljs-string\">'MySite\\': src/ # `MySite\\Generator\\MyGenerator` is loaded from `src/Generator/MyGenerator.php`</span></code></pre>\n<p>If your extensions depend on third-party libraries, install them with <a href=\"https://getcomposer.org\" target=\"_blank\" rel=\"noopener noreferrer\">Composer</a> in the <code translate=\"no\">extensions</code> directory (<code translate=\"no\">composer require &lt;package&gt; --working-dir=extensions</code>): <code translate=\"no\">extensions/vendor/autoload.php</code> is loaded automatically, even with the Cecil phar. Libraries already provided by Cecil are not overridden.</p>\n<aside class=\"note note-important\"><p>Use your own namespace (e.g.: <code translate=\"no\">MySite\\</code> or the name of your theme): the <code translate=\"no\">Cecil\\</code> namespace is reserved, and using it for custom classes is deprecated.</p></aside>\n<h2 id=\"configuration\">Configuration<a class=\"heading-anchor\" href=\"#configuration\" aria-hidden=\"true\" tabindex=\"-1\"></a></h2>\n<p>Page generators, Twig extensions, output post-processors, <a href=\"#build-events\">build events</a> subscribers and <a href=\"#plugins\">plugins</a> are declared the same way, as a map indexed by name:</p>\n<pre data-lang=\"yaml\"><code class=\"language-yaml hljs yaml\" translate=\"no\"><span class=\"hljs-string\">&lt;key&gt;:</span>\n  <span class=\"hljs-string\">&lt;name&gt;:</span> <span class=\"hljs-string\">&lt;class&gt;</span>                                         <span class=\"hljs-comment\"># default priority (100)</span>\n  <span class=\"hljs-string\">&lt;name&gt;:</span> <span class=\"hljs-string\">{</span> <span class=\"hljs-attr\">class:</span> <span class=\"hljs-string\">&lt;class&gt;,</span> <span class=\"hljs-attr\">priority:</span> <span class=\"hljs-string\">&lt;int&gt;</span> <span class=\"hljs-string\">}</span>             <span class=\"hljs-comment\"># explicit priority</span>\n  <span class=\"hljs-string\">&lt;name&gt;:</span> <span class=\"hljs-literal\">false</span>                                           <span class=\"hljs-comment\"># disabled</span></code></pre>\n<ul>\n<li>Extensions run in ascending order of their priority; without a priority, they run after the built-in ones (priority <code translate=\"no\">100</code>), in their declaration order.</li>\n<li>A built-in extension can be disabled (<code translate=\"no\">Redirect: false</code>) or moved (<code translate=\"no\">Section: { priority: 45 }</code>) by its name.</li>\n<li>An extension that cannot be loaded (unknown class, wrong interface, invalid option) is skipped and the error is logged. To fail the build instead, enable the strict mode (<code translate=\"no\">false</code> only logs the error, without the Cecil 10 warning):</li>\n</ul>\n<pre data-lang=\"yaml\"><code class=\"language-yaml hljs yaml\" translate=\"no\"><span class=\"hljs-attr\">extensions:</span>\n  <span class=\"hljs-attr\">strict:</span> <span class=\"hljs-literal\">true</span></code></pre>\n<aside class=\"note note-important\"><p>Indexing extensions by priority (e.g.: <code translate=\"no\">35: MySite\\Generator\\Database</code>) or by position (a list) is deprecated: it is still supported, with a warning, but will not be in Cecil 10. Use <code translate=\"no\">Database: { class: MySite\\Generator\\Database, priority: 35 }</code> instead.</p>\n<p>In Cecil 10, the strict mode will be enabled by default.</p></aside>\n<h2 id=\"page-generators\">Page generators<a class=\"heading-anchor\" href=\"#page-generators\" aria-hidden=\"true\" tabindex=\"-1\"></a></h2>\n<p>A generator helps you create pages without Markdown files (for example, with data from an API or a database) or alter existing pages.</p>\n<p>Create a new PHP class extending <code translate=\"no\">Cecil\\Generator\\AbstractGenerator</code>, and add it to the <a href=\"../configuration/4-pages.md#pages-generators\"><code translate=\"no\">pages.generators</code></a> list.</p>\n<p>Built-in generators use the priorities <code translate=\"no\">10</code> to <code translate=\"no\">90</code>: choose the priority of your generator depending on the pages it needs (e.g.: after <code translate=\"no\">Section</code> to access sections pages).</p>\n<p>A generator adds pages to <code translate=\"no\">$this-&gt;generatedPages</code> (a page with the ID of an existing page replaces it), and can remove existing pages with <code translate=\"no\">$this-&gt;removePage('&lt;page-id&gt;')</code>.</p>\n<p><strong>Example:</strong></p>\n<p><em>/extensions/MySite/Generator/DummyPage.php</em></p>\n<pre data-lang=\"php\"><code class=\"language-php hljs php\" translate=\"no\"><span class=\"hljs-meta\">&lt;?php</span>\n<span class=\"hljs-keyword\">namespace</span> <span class=\"hljs-title\">MySite</span>\\<span class=\"hljs-title\">Generator</span>;\n\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Collection</span>\\<span class=\"hljs-title\">Page</span>\\<span class=\"hljs-title\">Page</span>;\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Collection</span>\\<span class=\"hljs-title\">Page</span>\\<span class=\"hljs-title\">Type</span>;\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Generator</span>\\<span class=\"hljs-title\">AbstractGenerator</span>;\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Generator</span>\\<span class=\"hljs-title\">GeneratorInterface</span>;\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class</span> <span class=\"hljs-title\">DummyPage</span> <span class=\"hljs-keyword\">extends</span> <span class=\"hljs-title\">AbstractGenerator</span> <span class=\"hljs-keyword\">implements</span> <span class=\"hljs-title\">GeneratorInterface</span>\n</span>{\n    <span class=\"hljs-keyword\">public</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span> <span class=\"hljs-title\">generate</span><span class=\"hljs-params\">()</span>: <span class=\"hljs-title\">void</span>\n    </span>{\n        <span class=\"hljs-comment\">// create a new page $page, then add it to the site collection</span>\n        $page = (<span class=\"hljs-keyword\">new</span> Page(<span class=\"hljs-string\">'my-page'</span>))\n            -&gt;setType(Type::PAGE)\n            -&gt;setPath(<span class=\"hljs-string\">'mypage'</span>)\n            -&gt;setBodyHtml(<span class=\"hljs-string\">'&lt;p&gt;My page body&lt;/p&gt;'</span>)\n            -&gt;setVariable(<span class=\"hljs-string\">'language'</span>, <span class=\"hljs-string\">'en'</span>)\n            -&gt;setVariable(<span class=\"hljs-string\">'title'</span>, <span class=\"hljs-string\">'My page'</span>)\n            -&gt;setVariable(<span class=\"hljs-string\">'date'</span>, <span class=\"hljs-keyword\">new</span> \\DateTime())\n            -&gt;setVariable(<span class=\"hljs-string\">'menu'</span>, [<span class=\"hljs-string\">'main'</span> =&gt; [<span class=\"hljs-string\">'weight'</span> =&gt; <span class=\"hljs-number\">99</span>]]);\n        <span class=\"hljs-keyword\">$this</span>-&gt;generatedPages-&gt;add($page);\n    }\n}</code></pre>\n<p><em>/extensions/MySite/Generator/Database.php</em></p>\n<pre data-lang=\"php\"><code class=\"language-php hljs php\" translate=\"no\"><span class=\"hljs-meta\">&lt;?php</span>\n<span class=\"hljs-keyword\">namespace</span> <span class=\"hljs-title\">MySite</span>\\<span class=\"hljs-title\">Generator</span>;\n\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Collection</span>\\<span class=\"hljs-title\">Page</span>\\<span class=\"hljs-title\">Page</span>;\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Collection</span>\\<span class=\"hljs-title\">Page</span>\\<span class=\"hljs-title\">Type</span>;\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Generator</span>\\<span class=\"hljs-title\">AbstractGenerator</span>;\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Generator</span>\\<span class=\"hljs-title\">GeneratorInterface</span>;\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class</span> <span class=\"hljs-title\">Database</span> <span class=\"hljs-keyword\">extends</span> <span class=\"hljs-title\">AbstractGenerator</span> <span class=\"hljs-keyword\">implements</span> <span class=\"hljs-title\">GeneratorInterface</span>\n</span>{\n    <span class=\"hljs-keyword\">public</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span> <span class=\"hljs-title\">generate</span><span class=\"hljs-params\">()</span>: <span class=\"hljs-title\">void</span>\n    </span>{\n        <span class=\"hljs-comment\">// create pages from a SQLite database</span>\n        $db = <span class=\"hljs-keyword\">new</span> \\SQLite3(<span class=\"hljs-string\">'database.sqlite'</span>);\n        $statement = $db-&gt;prepare(<span class=\"hljs-string\">'SELECT * FROM blog'</span>);\n        $result = $statement-&gt;execute();\n        <span class=\"hljs-keyword\">while</span> ($row = $result-&gt;fetchArray(\\SQLITE3_ASSOC)) {\n            $page = (<span class=\"hljs-keyword\">new</span> Page($row[<span class=\"hljs-string\">'page-id'</span>]))\n                -&gt;setType(Type::PAGE)\n                -&gt;setPath($row[<span class=\"hljs-string\">'path'</span>])\n                -&gt;setBodyHtml($row[<span class=\"hljs-string\">'html'</span>])\n                -&gt;setVariable(<span class=\"hljs-string\">'title'</span>, $row[<span class=\"hljs-string\">'title'</span>])\n                -&gt;setVariable(<span class=\"hljs-string\">'date'</span>, $row[<span class=\"hljs-string\">'date'</span>]);\n            <span class=\"hljs-keyword\">$this</span>-&gt;generatedPages-&gt;add($page);\n        }\n        $result-&gt;finalize();\n        $db-&gt;close();\n    }\n}</code></pre>\n<p><em>configuration</em></p>\n<pre data-lang=\"yaml\"><code class=\"language-yaml hljs yaml\" translate=\"no\"><span class=\"hljs-attr\">pages:</span>\n  <span class=\"hljs-attr\">generators:</span>\n    <span class=\"hljs-attr\">DummyPage:</span> <span class=\"hljs-string\">MySite\\Generator\\DummyPage</span>\n    <span class=\"hljs-attr\">Database:</span> <span class=\"hljs-string\">{</span> <span class=\"hljs-attr\">class:</span> <span class=\"hljs-string\">MySite\\Generator\\Database,</span> <span class=\"hljs-attr\">priority:</span> <span class=\"hljs-number\">35</span> <span class=\"hljs-string\">}</span></code></pre>\n<h2 id=\"twig-extension\">Twig extension<a class=\"heading-anchor\" href=\"#twig-extension\" aria-hidden=\"true\" tabindex=\"-1\"></a></h2>\n<p>You can add custom <a href=\"../templates/reference/1-functions.md\">functions</a> and <a href=\"../templates/reference/3-filters.md\">filters</a>:</p>\n<ol>\n<li><a href=\"https://twig.symfony.com/doc/advanced.html#creating-an-extension\" target=\"_blank\" rel=\"noopener noreferrer\">create a Twig extension</a></li>\n<li>add the PHP file in the <code translate=\"no\">extensions</code> directory (see <a href=\"#autoloading\">Autoloading</a>)</li>\n<li>add it to the <a href=\"../configuration/7-layouts.md#layouts-extensions\"><code translate=\"no\">layouts.extensions</code></a> configuration</li>\n</ol>\n<p>The extension constructor receives the <code translate=\"no\">Cecil\\Builder</code> instance, which gives access to the configuration and the site content.</p>\n<p><strong>Example:</strong></p>\n<p><em>/extensions/MySite/Twig/MyTwigExtension.php</em></p>\n<pre data-lang=\"php\"><code class=\"language-php hljs php\" translate=\"no\"><span class=\"hljs-meta\">&lt;?php</span>\n<span class=\"hljs-keyword\">namespace</span> <span class=\"hljs-title\">MySite</span>\\<span class=\"hljs-title\">Twig</span>;\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class</span> <span class=\"hljs-title\">MyTwigExtension</span> <span class=\"hljs-keyword\">extends</span> \\<span class=\"hljs-title\">Twig</span>\\<span class=\"hljs-title\">Extension</span>\\<span class=\"hljs-title\">AbstractExtension</span>\n</span>{\n    <span class=\"hljs-keyword\">public</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span> <span class=\"hljs-title\">getFilters</span><span class=\"hljs-params\">()</span>: <span class=\"hljs-title\">array</span>\n    </span>{\n        <span class=\"hljs-comment\">// add a new filter named 'md5'</span>\n        <span class=\"hljs-keyword\">return</span> [\n            <span class=\"hljs-keyword\">new</span> \\Twig\\TwigFilter(<span class=\"hljs-string\">'md5'</span>, <span class=\"hljs-string\">'md5'</span>),\n        ];\n    }\n}</code></pre>\n<p><em>configuration</em></p>\n<pre data-lang=\"yaml\"><code class=\"language-yaml hljs yaml\" translate=\"no\"><span class=\"hljs-attr\">layouts:</span>\n  <span class=\"hljs-attr\">extensions:</span>\n    <span class=\"hljs-attr\">MyExtension:</span> <span class=\"hljs-string\">MySite\\Twig\\MyTwigExtension</span></code></pre>\n<h2 id=\"output-post-processors\">Output post-processors<a class=\"heading-anchor\" href=\"#output-post-processors\" aria-hidden=\"true\" tabindex=\"-1\"></a></h2>\n<p>You can post-process the rendered output of pages.</p>\n<p>Create a new PHP class extending <code translate=\"no\">Cecil\\Renderer\\PostProcessor\\AbstractPostProcessor</code>, and add it to the <a href=\"../configuration/8-output.md#output-postprocessors\"><code translate=\"no\">output.postprocessors</code></a> list.</p>\n<p>Built-in post-processors (<code translate=\"no\">GeneratorMetaTag</code>, <code translate=\"no\">HtmlExcerpt</code> and <code translate=\"no\">MarkdownLink</code>) use the priorities <code translate=\"no\">10</code> to <code translate=\"no\">30</code>, so they run first by default.</p>\n<p><strong>Example:</strong></p>\n<p><em>/extensions/MySite/PostProcessor/MyProcessor.php</em></p>\n<pre data-lang=\"php\"><code class=\"language-php hljs php\" translate=\"no\"><span class=\"hljs-meta\">&lt;?php</span>\n<span class=\"hljs-keyword\">namespace</span> <span class=\"hljs-title\">MySite</span>\\<span class=\"hljs-title\">PostProcessor</span>;\n\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Collection</span>\\<span class=\"hljs-title\">Page</span>\\<span class=\"hljs-title\">Page</span>;\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Renderer</span>\\<span class=\"hljs-title\">PostProcessor</span>\\<span class=\"hljs-title\">AbstractPostProcessor</span>;\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class</span> <span class=\"hljs-title\">MyProcessor</span> <span class=\"hljs-keyword\">extends</span> <span class=\"hljs-title\">AbstractPostProcessor</span>\n</span>{\n    <span class=\"hljs-keyword\">public</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span> <span class=\"hljs-title\">process</span><span class=\"hljs-params\">(Page $page, string $output, string $format)</span>: <span class=\"hljs-title\">string</span>\n    </span>{\n        <span class=\"hljs-comment\">// add a meta tag to the head of the HTML output</span>\n        <span class=\"hljs-keyword\">if</span> ($format == <span class=\"hljs-string\">'html'</span>) {\n            <span class=\"hljs-keyword\">if</span> (!preg_match(<span class=\"hljs-string\">'/&lt;meta name=\"test\".*/i'</span>, $output)) {\n                $meta = <span class=\"hljs-string\">'&lt;meta name=\"test\" content=\"Test\"&gt;'</span>;\n                $output = preg_replace_callback(<span class=\"hljs-string\">'/([[:blank:]]*)(&lt;\\/head&gt;)/i'</span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span> <span class=\"hljs-params\">($matches)</span> <span class=\"hljs-title\">use</span> <span class=\"hljs-params\">($meta)</span> </span>{\n                    <span class=\"hljs-keyword\">return</span> str_repeat($matches[<span class=\"hljs-number\">1</span>] ?: <span class=\"hljs-string\">' '</span>, <span class=\"hljs-number\">2</span>) . $meta . <span class=\"hljs-string\">\"\\n\"</span> . $matches[<span class=\"hljs-number\">1</span>] . $matches[<span class=\"hljs-number\">2</span>];\n                }, $output);\n            }\n        }\n\n        <span class=\"hljs-keyword\">return</span> $output;\n    }\n}</code></pre>\n<p><em>configuration</em></p>\n<pre data-lang=\"yaml\"><code class=\"language-yaml hljs yaml\" translate=\"no\"><span class=\"hljs-attr\">output:</span>\n  <span class=\"hljs-attr\">postprocessors:</span>\n    <span class=\"hljs-attr\">MyProcessor:</span> <span class=\"hljs-string\">MySite\\PostProcessor\\MyProcessor</span></code></pre>\n<h2 id=\"markdown-converter\">Markdown converter<a class=\"heading-anchor\" href=\"#markdown-converter\" aria-hidden=\"true\" tabindex=\"-1\"></a></h2>\n<p>The front matter and the Markdown body of pages are converted by the class defined in <a href=\"../configuration/4-pages.md#pages-converter\"><code translate=\"no\">pages.converter</code></a>. It is also used by the <code translate=\"no\">markdown_to_html</code> filter and for external pages (the <code translate=\"no\">toc</code> filter uses the <a href=\"#markdown-parser\">Markdown parser</a> directly).</p>\n<p>To change the conversion, create a PHP class implementing <code translate=\"no\">Cecil\\Converter\\ConverterInterface</code> (its constructor receives the <code translate=\"no\">Cecil\\Builder</code> instance), or extending the default <code translate=\"no\">Cecil\\Converter\\Converter</code> class.</p>\n<p><strong>Example:</strong></p>\n<p><em>/extensions/MySite/Converter.php</em></p>\n<pre data-lang=\"php\"><code class=\"language-php hljs php\" translate=\"no\"><span class=\"hljs-meta\">&lt;?php</span>\n<span class=\"hljs-keyword\">namespace</span> <span class=\"hljs-title\">MySite</span>;\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class</span> <span class=\"hljs-title\">Converter</span> <span class=\"hljs-keyword\">extends</span> \\<span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Converter</span>\\<span class=\"hljs-title\">Converter</span>\n</span>{\n    <span class=\"hljs-keyword\">public</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span> <span class=\"hljs-title\">convertBody</span><span class=\"hljs-params\">(string $string, ?string $language = null)</span>: <span class=\"hljs-title\">string</span>\n    </span>{\n        <span class=\"hljs-comment\">// replaces `[[page-id]]` with a link, before the default conversion</span>\n        $string = preg_replace(<span class=\"hljs-string\">'/\\[\\[([a-z0-9-\\/]+)\\]\\]/'</span>, <span class=\"hljs-string\">'[$1]($1.md)'</span>, $string);\n\n        <span class=\"hljs-keyword\">return</span> <span class=\"hljs-keyword\">parent</span>::convertBody($string, $language);\n    }\n}</code></pre>\n<p><em>configuration</em></p>\n<pre data-lang=\"yaml\"><code class=\"language-yaml hljs yaml\" translate=\"no\"><span class=\"hljs-attr\">pages:</span>\n  <span class=\"hljs-attr\">converter:</span> <span class=\"hljs-string\">MySite\\Converter</span></code></pre>\n<h2 id=\"markdown-parser\">Markdown parser<a class=\"heading-anchor\" href=\"#markdown-parser\" aria-hidden=\"true\" tabindex=\"-1\"></a></h2>\n<p>To add your own Markdown syntax, replace the Markdown parser used by the default converter (and by the <code translate=\"no\">markdown_to_html</code> and <code translate=\"no\">toc</code> filters) with the <a href=\"../configuration/4-pages.md#pages-body-parser\"><code translate=\"no\">pages.body.parser</code></a> option.</p>\n<p>Create a PHP class extending <code translate=\"no\">Cecil\\Converter\\Parsedown</code>, based on <a href=\"https://github.com/erusev/parsedown\" target=\"_blank\" rel=\"noopener noreferrer\">Parsedown</a> (1.x) and <a href=\"https://github.com/erusev/parsedown-extra\" target=\"_blank\" rel=\"noopener noreferrer\">Parsedown Extra</a>, and register your syntax with its extension mechanism: a marker character in <code translate=\"no\">$this-&gt;InlineTypes</code> (or <code translate=\"no\">$this-&gt;BlockTypes</code>) refers to an <code translate=\"no\">inline&lt;Type&gt;()</code> method (or <code translate=\"no\">block&lt;Type&gt;()</code>, <code translate=\"no\">block&lt;Type&gt;Continue()</code> and <code translate=\"no\">block&lt;Type&gt;Complete()</code> methods).</p>\n<aside class=\"note note-warning\"><p>A custom parser relies on Parsedown internals: it may need to be updated when Cecil upgrades Parsedown.</p></aside>\n<p>The parser can also be created outside of a build (see <a href=\"2-library.md#markdown\">Library</a>): pass the options to the parent constructor, and do not rely on the state of a build (e.g. the pages collection).</p>\n<p><strong>Example:</strong></p>\n<p><em>/extensions/MySite/Parsedown.php</em></p>\n<pre data-lang=\"php\"><code class=\"language-php hljs php\" translate=\"no\"><span class=\"hljs-meta\">&lt;?php</span>\n<span class=\"hljs-keyword\">namespace</span> <span class=\"hljs-title\">MySite</span>;\n\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Builder</span>;\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class</span> <span class=\"hljs-title\">Parsedown</span> <span class=\"hljs-keyword\">extends</span> \\<span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Converter</span>\\<span class=\"hljs-title\">Parsedown</span>\n</span>{\n    <span class=\"hljs-keyword\">public</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span> <span class=\"hljs-title\">__construct</span><span class=\"hljs-params\">(Builder $builder, ?array $options = null)</span>\n    </span>{\n        <span class=\"hljs-keyword\">parent</span>::__construct($builder, $options);\n        <span class=\"hljs-comment\">// `==text==` → `&lt;mark&gt;text&lt;/mark&gt;`</span>\n        <span class=\"hljs-keyword\">$this</span>-&gt;InlineTypes[<span class=\"hljs-string\">'='</span>][] = <span class=\"hljs-string\">'Mark'</span>;\n        <span class=\"hljs-keyword\">$this</span>-&gt;inlineMarkerList .= <span class=\"hljs-string\">'='</span>;\n    }\n\n    <span class=\"hljs-keyword\">protected</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span> <span class=\"hljs-title\">inlineMark</span><span class=\"hljs-params\">($Excerpt)</span>\n    </span>{\n        <span class=\"hljs-keyword\">if</span> (preg_match(<span class=\"hljs-string\">'/^==(?=\\S)(.+?)(?&lt;=\\S)==/'</span>, $Excerpt[<span class=\"hljs-string\">'text'</span>], $matches)) {\n            <span class=\"hljs-keyword\">return</span> [\n                <span class=\"hljs-string\">'extent'</span>  =&gt; \\strlen($matches[<span class=\"hljs-number\">0</span>]),\n                <span class=\"hljs-string\">'element'</span> =&gt; [<span class=\"hljs-string\">'name'</span> =&gt; <span class=\"hljs-string\">'mark'</span>, <span class=\"hljs-string\">'text'</span> =&gt; $matches[<span class=\"hljs-number\">1</span>], <span class=\"hljs-string\">'handler'</span> =&gt; <span class=\"hljs-string\">'line'</span>],\n            ];\n        }\n\n        <span class=\"hljs-keyword\">return</span> <span class=\"hljs-keyword\">null</span>;\n    }\n}</code></pre>\n<p><em>configuration</em></p>\n<pre data-lang=\"yaml\"><code class=\"language-yaml hljs yaml\" translate=\"no\"><span class=\"hljs-attr\">pages:</span>\n  <span class=\"hljs-attr\">body:</span>\n    <span class=\"hljs-attr\">parser:</span> <span class=\"hljs-string\">MySite\\Parsedown</span></code></pre>\n<h2 id=\"build-events\">Build events<a class=\"heading-anchor\" href=\"#build-events\" aria-hidden=\"true\" tabindex=\"-1\"></a></h2>\n<p>Events are dispatched during the build: listen to them to run your own code before or after the build, each step, or at each step of the life cycle of a page (e.g.: to create a search index, notify a service, or modify the output of pages).</p>\n<table>\n<thead>\n<tr>\n<th>Event</th>\n<th>Constant</th>\n<th>When</th>\n<th>Event class</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code translate=\"no\">build.start</code></td>\n<td><code translate=\"no\">BuildEvents::BUILD_START</code></td>\n<td>before the first step</td>\n<td><code translate=\"no\">BuildEvent</code></td>\n</tr>\n<tr>\n<td><code translate=\"no\">build.finished</code></td>\n<td><code translate=\"no\">BuildEvents::BUILD_FINISHED</code></td>\n<td>after the last step</td>\n<td><code translate=\"no\">BuildEvent</code></td>\n</tr>\n<tr>\n<td><code translate=\"no\">step.pre</code></td>\n<td><code translate=\"no\">BuildEvents::STEP_PRE</code></td>\n<td>before each step</td>\n<td><code translate=\"no\">StepEvent</code></td>\n</tr>\n<tr>\n<td><code translate=\"no\">step.post</code></td>\n<td><code translate=\"no\">BuildEvents::STEP_POST</code></td>\n<td>after each step</td>\n<td><code translate=\"no\">StepEvent</code></td>\n</tr>\n<tr>\n<td><code translate=\"no\">page.created</code></td>\n<td><code translate=\"no\">BuildEvents::PAGE_CREATED</code></td>\n<td>after a page is created from a content file</td>\n<td><code translate=\"no\">PageEvent</code></td>\n</tr>\n<tr>\n<td><code translate=\"no\">page.converted</code></td>\n<td><code translate=\"no\">BuildEvents::PAGE_CONVERTED</code></td>\n<td>after a published page is converted (front matter and body)</td>\n<td><code translate=\"no\">PageEvent</code></td>\n</tr>\n<tr>\n<td><code translate=\"no\">page.rendered</code></td>\n<td><code translate=\"no\">BuildEvents::PAGE_RENDERED</code></td>\n<td>after a page is rendered in a format (after post-processors)</td>\n<td><code translate=\"no\">PageRenderedEvent</code></td>\n</tr>\n<tr>\n<td><code translate=\"no\">page.saved</code></td>\n<td><code translate=\"no\">BuildEvents::PAGE_SAVED</code></td>\n<td>after a rendered page is saved to a file</td>\n<td><code translate=\"no\">PageSavedEvent</code></td>\n</tr>\n</tbody>\n</table>\n<p>Every event gives access to the build context (<code translate=\"no\">getBuilder()</code>) and options (<code translate=\"no\">getOptions()</code>); <code translate=\"no\">StepEvent</code> adds <code translate=\"no\">getStep()</code>, <code translate=\"no\">PageEvent</code> adds <code translate=\"no\">getPage()</code>, <code translate=\"no\">PageRenderedEvent</code> adds <code translate=\"no\">getFormat()</code>, <code translate=\"no\">getOutput()</code> and <code translate=\"no\">setOutput()</code>, <code translate=\"no\">PageSavedEvent</code> adds <code translate=\"no\">getFormat()</code> and <code translate=\"no\">getPathname()</code>.</p>\n<p>Create an <a href=\"https://symfony.com/doc/current/components/event_dispatcher.html#using-event-subscribers\" target=\"_blank\" rel=\"noopener noreferrer\">event subscriber</a> extending <code translate=\"no\">Cecil\\Event\\AbstractSubscriber</code> (which gives access to <code translate=\"no\">$this-&gt;builder</code> and <code translate=\"no\">$this-&gt;config</code>), and add it to the <code translate=\"no\">extensions.subscribers</code> list.</p>\n<p><strong>Example:</strong></p>\n<p><em>/extensions/MySite/SearchIndex.php</em></p>\n<pre data-lang=\"php\"><code class=\"language-php hljs php\" translate=\"no\"><span class=\"hljs-meta\">&lt;?php</span>\n<span class=\"hljs-keyword\">namespace</span> <span class=\"hljs-title\">MySite</span>;\n\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Event</span>\\<span class=\"hljs-title\">AbstractSubscriber</span>;\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Event</span>\\<span class=\"hljs-title\">BuildEvent</span>;\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Event</span>\\<span class=\"hljs-title\">BuildEvents</span>;\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Event</span>\\<span class=\"hljs-title\">PageEvent</span>;\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class</span> <span class=\"hljs-title\">SearchIndex</span> <span class=\"hljs-keyword\">extends</span> <span class=\"hljs-title\">AbstractSubscriber</span>\n</span>{\n    <span class=\"hljs-keyword\">private</span> <span class=\"hljs-keyword\">array</span> $index = [];\n\n    <span class=\"hljs-keyword\">public</span> <span class=\"hljs-keyword\">static</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span> <span class=\"hljs-title\">getSubscribedEvents</span><span class=\"hljs-params\">()</span>: <span class=\"hljs-title\">array</span>\n    </span>{\n        <span class=\"hljs-keyword\">return</span> [\n            BuildEvents::PAGE_CONVERTED =&gt; <span class=\"hljs-string\">'onPageConverted'</span>,\n            BuildEvents::BUILD_FINISHED =&gt; <span class=\"hljs-string\">'onBuildFinished'</span>,\n        ];\n    }\n\n    <span class=\"hljs-keyword\">public</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span> <span class=\"hljs-title\">onPageConverted</span><span class=\"hljs-params\">(PageEvent $event)</span>: <span class=\"hljs-title\">void</span>\n    </span>{\n        $page = $event-&gt;getPage();\n        <span class=\"hljs-keyword\">$this</span>-&gt;index[] = [<span class=\"hljs-string\">'title'</span> =&gt; $page-&gt;getVariable(<span class=\"hljs-string\">'title'</span>), <span class=\"hljs-string\">'path'</span> =&gt; $page-&gt;getPath()];\n    }\n\n    <span class=\"hljs-keyword\">public</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span> <span class=\"hljs-title\">onBuildFinished</span><span class=\"hljs-params\">(BuildEvent $event)</span>: <span class=\"hljs-title\">void</span>\n    </span>{\n        <span class=\"hljs-keyword\">if</span> ($event-&gt;getOptions()[<span class=\"hljs-string\">'dry-run'</span>]) {\n            <span class=\"hljs-keyword\">return</span>;\n        }\n        file_put_contents(<span class=\"hljs-keyword\">$this</span>-&gt;config-&gt;getOutputPath() . <span class=\"hljs-string\">'/search.json'</span>, json_encode(<span class=\"hljs-keyword\">$this</span>-&gt;index));\n    }\n}</code></pre>\n<p><em>configuration</em></p>\n<pre data-lang=\"yaml\"><code class=\"language-yaml hljs yaml\" translate=\"no\"><span class=\"hljs-attr\">extensions:</span>\n  <span class=\"hljs-attr\">subscribers:</span>\n    <span class=\"hljs-attr\">SearchIndex:</span> <span class=\"hljs-string\">MySite\\SearchIndex</span></code></pre>\n<aside class=\"note note-tip\"><p>When using Cecil as a <a href=\"2-library.md\">PHP library</a>, listeners can also be added directly to the dispatcher before the build: <code translate=\"no\">$builder-&gt;getEventDispatcher()-&gt;addListener(BuildEvents::PAGE_SAVED, $callable)</code>.</p></aside>\n<h2 id=\"plugins\">Plugins<a class=\"heading-anchor\" href=\"#plugins\" aria-hidden=\"true\" tabindex=\"-1\"></a></h2>\n<p>A plugin is a single entry point that registers a set of extensions: generators, Twig extensions, post-processors, event subscribers and listeners, and default configuration. It's the recommended way to ship extensions with a theme: enabling the theme enables its plugin, with no other configuration.</p>\n<p>Create a PHP class extending <code translate=\"no\">Cecil\\Plugin\\AbstractPlugin</code> (which gives access to <code translate=\"no\">$this-&gt;builder</code> and <code translate=\"no\">$this-&gt;config</code>), and add it to the <code translate=\"no\">extensions.plugins</code> list.</p>\n<p><strong>Example:</strong></p>\n<p><em>/themes/example/extensions/Example/ExamplePlugin.php</em></p>\n<pre data-lang=\"php\"><code class=\"language-php hljs php\" translate=\"no\"><span class=\"hljs-meta\">&lt;?php</span>\n<span class=\"hljs-keyword\">namespace</span> <span class=\"hljs-title\">Example</span>;\n\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Event</span>\\<span class=\"hljs-title\">BuildEvents</span>;\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Plugin</span>\\<span class=\"hljs-title\">AbstractPlugin</span>;\n<span class=\"hljs-keyword\">use</span> <span class=\"hljs-title\">Cecil</span>\\<span class=\"hljs-title\">Plugin</span>\\<span class=\"hljs-title\">Registry</span>;\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class</span> <span class=\"hljs-title\">ExamplePlugin</span> <span class=\"hljs-keyword\">extends</span> <span class=\"hljs-title\">AbstractPlugin</span>\n</span>{\n    <span class=\"hljs-keyword\">public</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span> <span class=\"hljs-title\">register</span><span class=\"hljs-params\">(Registry $registry)</span>: <span class=\"hljs-title\">void</span>\n    </span>{\n        $registry\n            -&gt;config([<span class=\"hljs-string\">'example'</span> =&gt; [<span class=\"hljs-string\">'feed'</span> =&gt; [<span class=\"hljs-string\">'limit'</span> =&gt; <span class=\"hljs-number\">10</span>]]]) <span class=\"hljs-comment\">// default options</span>\n            -&gt;twigExtension(Twig\\ExampleExtension::class)\n            -&gt;generator(Generator\\Feed::class, priority: <span class=\"hljs-number\">35</span>)\n            -&gt;postProcessor(PostProcessor\\Minify::class)\n            -&gt;subscriber(SearchIndex::class)\n            -&gt;listen(BuildEvents::BUILD_FINISHED, fn () =&gt; <span class=\"hljs-keyword\">$this</span>-&gt;builder-&gt;getLogger()-&gt;notice(<span class=\"hljs-string\">'Example is ready'</span>));\n    }\n}</code></pre>\n<p><em>/themes/example/config.yml</em></p>\n<pre data-lang=\"yaml\"><code class=\"language-yaml hljs yaml\" translate=\"no\"><span class=\"hljs-attr\">extensions:</span>\n  <span class=\"hljs-attr\">plugins:</span>\n    <span class=\"hljs-attr\">Example:</span> <span class=\"hljs-string\">Example\\ExamplePlugin</span></code></pre>\n<p>Extensions registered by a plugin are named after their short class name (e.g.: <code translate=\"no\">Feed</code>), unless a <code translate=\"no\">name</code> is given, and use the default priority (<code translate=\"no\">100</code>) unless a <code translate=\"no\">priority</code> is given. The plugin configuration has the lowest precedence: the site (and themes) configuration can override its options, and disable (<code translate=\"no\">Feed: false</code>) or move (<code translate=\"no\">Feed: { priority: 45 }</code>) its extensions by name.</p>",
      "language": "en"
    }
  ]
}
