

How to Add Custom HTML Pages to a Pelican Site
How to Add Custom HTML Pages to a Pelican Site
Introduction
Pelican is a powerful static site generator written in Python, primarily designed for blogs. However, sometimes you need to include custom HTML pages that don't fit into Pelican's standard content model. This guide explains how to add standalone HTML pages to your Pelican site while preserving their exact formatting and functionality.
Method: Using Static Files
The most reliable method for adding custom HTML pages to a Pelican site is to use the static files approach. This method bypasses Pelican's content processing system and treats your HTML file as a static asset.
Step 1: Create a Static Directory
First, create a static
directory inside your Pelican project's content
folder:
mkdir -p content/static
Step 2: Add Your HTML File
Copy your custom HTML file to the static directory:
cp your-custom-page.html content/static/
Step 3: Configure Pelican
Edit your pelicanconf.py
file to include the following settings:
# Include static directory in static paths
STATIC_PATHS = ['images', 'static'] # Add other paths as needed
# Exclude static directory from content processing
ARTICLE_EXCLUDES = ['static']
PAGE_EXCLUDES = ['static']
# Optional: Configure a specific URL for your page
EXTRA_PATH_METADATA = {
'static/your-custom-page.html': {'path': 'custom-page/index.html'},
}
This configuration does three important things:
STATIC_PATHS
tells Pelican to copy files from thestatic
directory to the outputARTICLE_EXCLUDES
andPAGE_EXCLUDES
prevent Pelican from trying to process the files as contentEXTRA_PATH_METADATA
allows you to specify a custom output path for your HTML file
Step 4: Build Your Site
Now when you build your Pelican site, your custom HTML page will be copied to the output directory:
pelican content
Your page will be accessible at yourblog.com/custom-page/
.
Why This Works
This approach works because:
-
Bypasses Content Processing: By excluding the static directory from content processing, Pelican won't try to parse your HTML file for metadata or apply templates to it.
-
Preserves Original HTML: Your HTML file is copied as-is to the output directory, preserving all styling, scripts, and functionality.
-
Custom URL Structure: Using
EXTRA_PATH_METADATA
allows you to place the file at any URL path you want, creating clean URLs without the.html
extension.
Common Issues and Solutions
Issue: Pelican tries to process HTML as content
Solution: Make sure you've added the static directory to both ARTICLE_EXCLUDES
and PAGE_EXCLUDES
.
Issue: CSS or JavaScript paths are broken
Solution: If your HTML file references relative paths for CSS or JavaScript, you may need to adjust them to work with your site's URL structure.
Issue: HTML file not showing up in output
Solution: Verify that you've added the static directory to STATIC_PATHS
and that the file exists in the correct location.
Advanced: Linking to Your Custom Page
To link to your custom page from your Pelican site's navigation menu, you'll need to modify your theme's templates. Most themes use a variable like MENUITEMS
in the pelicanconf.py
file:
MENUITEMS = [
('Home', '/'),
('Blog', '/blog/'),
('Custom Page', '/custom-page/'),
]
Conclusion
Using the static files approach is the most straightforward way to add custom HTML pages to your Pelican site. It preserves the original HTML without modification, allows for custom URL structures, and integrates seamlessly with the rest of your site.
This method is particularly useful for: - Interactive pages with complex JavaScript - HTML generated by other tools - Pages with custom styling that shouldn't be affected by your site's theme - Embedding third-party applications or widgets
By following these steps, you can extend your Pelican site beyond its standard blog functionality while maintaining full control over your custom HTML content.
Feature Image Prompt:
Generate an image. The aesthetic should be cyberpunk with colors of neon pink, blue and purple. Do not add any people. Imagine a futuristic digital workspace where sleek holographic panels display lines of glowing HTML code and static web assets, symbolizing custom HTML pages for a Pelican site. The background features a neon-lit cityscape with pulsating grids and cybernetic data streams flowing through an atmospheric digital environment. The scene exudes high-tech energy and the seamless integration of traditional web development with a modern, cyberpunk twist.