Static site generator supporting Markdown and reStructuredText
—
Content classes that represent different types of site content including articles, pages, and static files. These classes handle metadata processing, URL generation, template assignment, and content rendering.
Foundation class for all content types providing common functionality for metadata handling, URL generation, and template processing.
class Content:
"""
Base class for all content types.
Parameters:
- content (str): Raw content string to parse
- metadata (dict, optional): Content metadata dictionary
- settings (dict, optional): Site settings dictionary
- source_path (str, optional): Path to source file
- context (dict, optional): Shared context between generators
"""
def __init__(
self,
content: str,
metadata: Optional[dict[str, Any]] = None,
settings: Optional[Settings] = None,
source_path: Optional[str] = None,
context: Optional[dict[Any, Any]] = None,
): ...
# Core attributes available after initialization
content: str # Processed HTML content
metadata: dict # Content metadata
settings: dict # Site settings
source_path: str # Source file path
template: str # Template name for rendering
translations: list # List of translation objects
# URL and path attributes (generated automatically)
url: str # Content URL
save_as: str # Output file path
slug: str # URL slug
# Optional metadata attributes (may be present based on content)
title: str # Content title
date: datetime # Publication date
author: Author # Content author
authors: list[Author] # Multiple authors
category: Category # Content category
tags: list[Tag] # Content tags
summary: str # Content summary
lang: str # Content language
status: str # Content status (published, draft, hidden)Blog article content type with date-based organization, categorization, and tagging support.
class Article(Content):
"""
Blog article content type.
Extends Content with article-specific functionality including:
- Date-based URL generation
- Category and tag management
- Archive organization
- RSS/Atom feed integration
"""
# Inherited from Content plus article-specific attributes
date: datetime # Publication date (required for articles)
category: Category # Article category
tags: list[Tag] # Article tags
# Article-specific URL patterns (configurable via settings)
# Default patterns: {slug}.html, {slug}-{lang}.html for translationsStatic page content type for non-blog content like about pages, contact forms, and other standalone pages.
class Page(Content):
"""
Static page content type.
Extends Content for standalone pages that are not part of the blog timeline.
Pages have different URL patterns and are not included in archives or feeds.
"""
# Inherited from Content
# Page-specific URL patterns (configurable via settings)
# Default patterns: pages/{slug}.html, pages/{slug}-{lang}.html for translationsStatic file content type for images, CSS, JavaScript, and other assets that should be copied to output without processing.
class Static(Content):
"""
Static file content type for assets.
Represents files that should be copied to output directory without markup processing.
Includes images, CSS, JavaScript, fonts, and other static assets.
"""
# Static files maintain original paths and are copied as-is
# No content processing or template rendering appliedClasses that represent categorical organization of content with URL generation and linking capabilities.
class URLWrapper:
"""Base class for URL-mapped content categories."""
def __init__(self, name: str, settings: dict): ...
name: str # Display name
slug: str # URL slug
url: str # Generated URL
save_as: str # Output file path
class Category(URLWrapper):
"""Article category wrapper with URL generation."""
class Tag(URLWrapper):
"""Article tag wrapper with URL generation."""
class Author(URLWrapper):
"""Article author wrapper with URL generation."""All content types support these metadata fields in their source files:
Title: Content title (required for most content types)Date: Publication date (required for articles)Modified: Last modification dateCategory: Content category (articles only)Tags: Comma-separated list of tags (articles only)Slug: Custom URL slug (auto-generated if not provided)Author: Content author nameAuthors: Multiple authors (comma-separated)Summary: Content summary/descriptionLang: Content language codeTranslation: Link to other language versionsStatus: Content status (published, draft, hidden)Template: Custom template nameSave_as: Custom output pathUrl: Custom URLMetadata is extracted from content source files and processed into content attributes:
# Example article with metadata
"""
Title: My First Post
Date: 2023-01-15 10:30
Category: Python
Tags: tutorial, beginner
Author: John Doe
Summary: A comprehensive introduction to Python programming.
Content of the article goes here...
"""from pelican.contents import Article, Page
from pelican.settings import read_settings
from datetime import datetime
# Load settings
settings = read_settings('pelicanconf.py')
# Create an article
article_metadata = {
'title': 'My Article',
'date': datetime.now(),
'category': 'Python',
'tags': ['tutorial', 'programming'],
'author': 'John Doe'
}
article = Article(
content="<p>Article content here</p>",
metadata=article_metadata,
settings=settings,
source_path='content/my-article.md'
)
# Create a page
page = Page(
content="<p>Page content here</p>",
metadata={'title': 'About Me'},
settings=settings,
source_path='content/pages/about.md'
)# Article attributes
print(article.title) # "My Article"
print(article.date) # datetime object
print(article.category) # Category object
print(article.tags) # List of Tag objects
print(article.url) # Generated URL
print(article.save_as) # Output file path
print(article.slug) # URL slug
# URL wrapper attributes
print(article.category.name) # Category name
print(article.category.url) # Category page URL
print(article.tags[0].name) # First tag name# Original article
original = Article(content="English content", metadata={
'title': 'My Post',
'lang': 'en'
}, settings=settings)
# Translation
translation = Article(content="Contenu français", metadata={
'title': 'Mon Article',
'lang': 'fr',
'translation': True
}, settings=settings)
# Link translations
original.translations.append(translation)from pelican.contents import Content
class CustomContent(Content):
"""Custom content type with special processing."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.process_custom_metadata()
def process_custom_metadata(self):
# Custom metadata processing logic
if 'custom_field' in self.metadata:
self.custom_attribute = self.metadata['custom_field'].upper()Install with Tessl CLI
npx tessl i tessl/pypi-pelican