Purpose
Render plugins are responsible for:- Transforming HTML content after rendering
- Injecting scripts, styles, or meta tags
- Modifying DOM structure or attributes
- Adding analytics, SEO enhancements, or accessibility features
- Cleaning up or optimizing the rendered output
Plugin Types
HTML String Plugins (postProcessByHtml)
Process HTML as a string - useful for simple text replacements and injections.
DOM Plugins (postProcessByDom)
Process HTML using JSDOM - useful for complex DOM manipulations.
Lifecycle
- Scully renders the route using Puppeteer (or configured renderer)
- The initial HTML is captured
- DOM plugins run first in registration order
- JSDOM is created from the HTML
- Each DOM plugin receives and modifies the JSDOM object
- JSDOM is converted back to HTML string
- HTML plugins run next in registration order
- Each HTML plugin receives and modifies the HTML string
- The final HTML is written to the output file
When to Use
Use HTML String Plugins When:
- Making simple text replacements
- Injecting snippets at specific locations
- Performing regex-based transformations
- You need maximum performance
Use DOM Plugins When:
- Manipulating DOM structure (adding/removing elements)
- Working with attributes or classes
- Traversing or querying the DOM
- You need reliable HTML parsing
Implementation Examples
Basic HTML String Plugin
Analytics Injection Plugin
DOM Manipulation Plugin
Content Injection Plugin
This is how Scully’s built-incontentFolder plugin injects content:
SEO Enhancement Plugin
Configuration
Global Post Renderers
Apply plugins to all routes:Route-Specific Post Renderers
Apply plugins to specific routes:Plugin Order
Plugins run in this order:- Route
typeplugin (if it’s a render plugin) - Route-specific
postRenderers - Global
defaultPostRenderers
Working with JSDOM
Accessing the Document
Creating Elements
Modifying Attributes
Serializing Back to HTML
Scully handles this automatically - just return the modified JSDOM object:Best Practices
- Choose the right plugin type: Use HTML plugins for simple tasks, DOM plugins for complex ones
- Handle missing elements gracefully: Always check if elements exist before manipulating
- Avoid blocking operations: Use async/await for I/O operations
- Log errors: Use Scully’s logging utilities for consistent output
- Test thoroughly: Plugins run on every route, so bugs multiply
- Keep it fast: Render plugins can significantly impact build time
- Be idempotent: Plugins may run multiple times during development
- Use route data: Access
route.datafor metadata from frontmatter or router plugins
Error Handling
Built-in Render Plugins
Scully includes several built-in render plugins:contentFolder: Injects content from markdown/content filescontentTextRender: Alternative content renderingseoHrefCompletion: Completes relative URLs for SEO
Related
- Router Plugins - Discover and generate routes
- File Handler Plugins - Transform content files
- Route Process Plugins - Modify the route list

