or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

cli-tools.mdcontent-generation.mdcontent-management.mdcontent-reading.mdindex.mdmain-application.mdplugin-system.mdsettings-configuration.mdutilities.md

content-management.mddocs/

0

# Content Management

1

2

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.

3

4

## Capabilities

5

6

### Base Content Class

7

8

Foundation class for all content types providing common functionality for metadata handling, URL generation, and template processing.

9

10

```python { .api }

11

class Content:

12

"""

13

Base class for all content types.

14

15

Parameters:

16

- content (str): Raw content string to parse

17

- metadata (dict, optional): Content metadata dictionary

18

- settings (dict, optional): Site settings dictionary

19

- source_path (str, optional): Path to source file

20

- context (dict, optional): Shared context between generators

21

"""

22

def __init__(

23

self,

24

content: str,

25

metadata: Optional[dict[str, Any]] = None,

26

settings: Optional[Settings] = None,

27

source_path: Optional[str] = None,

28

context: Optional[dict[Any, Any]] = None,

29

): ...

30

31

# Core attributes available after initialization

32

content: str # Processed HTML content

33

metadata: dict # Content metadata

34

settings: dict # Site settings

35

source_path: str # Source file path

36

template: str # Template name for rendering

37

translations: list # List of translation objects

38

39

# URL and path attributes (generated automatically)

40

url: str # Content URL

41

save_as: str # Output file path

42

slug: str # URL slug

43

44

# Optional metadata attributes (may be present based on content)

45

title: str # Content title

46

date: datetime # Publication date

47

author: Author # Content author

48

authors: list[Author] # Multiple authors

49

category: Category # Content category

50

tags: list[Tag] # Content tags

51

summary: str # Content summary

52

lang: str # Content language

53

status: str # Content status (published, draft, hidden)

54

```

55

56

### Article Content

57

58

Blog article content type with date-based organization, categorization, and tagging support.

59

60

```python { .api }

61

class Article(Content):

62

"""

63

Blog article content type.

64

65

Extends Content with article-specific functionality including:

66

- Date-based URL generation

67

- Category and tag management

68

- Archive organization

69

- RSS/Atom feed integration

70

"""

71

# Inherited from Content plus article-specific attributes

72

date: datetime # Publication date (required for articles)

73

category: Category # Article category

74

tags: list[Tag] # Article tags

75

76

# Article-specific URL patterns (configurable via settings)

77

# Default patterns: {slug}.html, {slug}-{lang}.html for translations

78

```

79

80

### Page Content

81

82

Static page content type for non-blog content like about pages, contact forms, and other standalone pages.

83

84

```python { .api }

85

class Page(Content):

86

"""

87

Static page content type.

88

89

Extends Content for standalone pages that are not part of the blog timeline.

90

Pages have different URL patterns and are not included in archives or feeds.

91

"""

92

# Inherited from Content

93

# Page-specific URL patterns (configurable via settings)

94

# Default patterns: pages/{slug}.html, pages/{slug}-{lang}.html for translations

95

```

96

97

### Static Content

98

99

Static file content type for images, CSS, JavaScript, and other assets that should be copied to output without processing.

100

101

```python { .api }

102

class Static(Content):

103

"""

104

Static file content type for assets.

105

106

Represents files that should be copied to output directory without markup processing.

107

Includes images, CSS, JavaScript, fonts, and other static assets.

108

"""

109

# Static files maintain original paths and are copied as-is

110

# No content processing or template rendering applied

111

```

112

113

### URL Wrapper Classes

114

115

Classes that represent categorical organization of content with URL generation and linking capabilities.

116

117

```python { .api }

118

class URLWrapper:

119

"""Base class for URL-mapped content categories."""

120

def __init__(self, name: str, settings: dict): ...

121

122

name: str # Display name

123

slug: str # URL slug

124

url: str # Generated URL

125

save_as: str # Output file path

126

127

class Category(URLWrapper):

128

"""Article category wrapper with URL generation."""

129

130

class Tag(URLWrapper):

131

"""Article tag wrapper with URL generation."""

132

133

class Author(URLWrapper):

134

"""Article author wrapper with URL generation."""

135

```

136

137

## Content Metadata

138

139

### Common Metadata Fields

140

141

All content types support these metadata fields in their source files:

142

143

- `Title`: Content title (required for most content types)

144

- `Date`: Publication date (required for articles)

145

- `Modified`: Last modification date

146

- `Category`: Content category (articles only)

147

- `Tags`: Comma-separated list of tags (articles only)

148

- `Slug`: Custom URL slug (auto-generated if not provided)

149

- `Author`: Content author name

150

- `Authors`: Multiple authors (comma-separated)

151

- `Summary`: Content summary/description

152

- `Lang`: Content language code

153

- `Translation`: Link to other language versions

154

- `Status`: Content status (published, draft, hidden)

155

- `Template`: Custom template name

156

- `Save_as`: Custom output path

157

- `Url`: Custom URL

158

159

### Metadata Processing

160

161

Metadata is extracted from content source files and processed into content attributes:

162

163

```python

164

# Example article with metadata

165

"""

166

Title: My First Post

167

Date: 2023-01-15 10:30

168

Category: Python

169

Tags: tutorial, beginner

170

Author: John Doe

171

Summary: A comprehensive introduction to Python programming.

172

173

Content of the article goes here...

174

"""

175

```

176

177

## Usage Examples

178

179

### Creating Content Programmatically

180

181

```python

182

from pelican.contents import Article, Page

183

from pelican.settings import read_settings

184

from datetime import datetime

185

186

# Load settings

187

settings = read_settings('pelicanconf.py')

188

189

# Create an article

190

article_metadata = {

191

'title': 'My Article',

192

'date': datetime.now(),

193

'category': 'Python',

194

'tags': ['tutorial', 'programming'],

195

'author': 'John Doe'

196

}

197

198

article = Article(

199

content="<p>Article content here</p>",

200

metadata=article_metadata,

201

settings=settings,

202

source_path='content/my-article.md'

203

)

204

205

# Create a page

206

page = Page(

207

content="<p>Page content here</p>",

208

metadata={'title': 'About Me'},

209

settings=settings,

210

source_path='content/pages/about.md'

211

)

212

```

213

214

### Accessing Content Attributes

215

216

```python

217

# Article attributes

218

print(article.title) # "My Article"

219

print(article.date) # datetime object

220

print(article.category) # Category object

221

print(article.tags) # List of Tag objects

222

print(article.url) # Generated URL

223

print(article.save_as) # Output file path

224

print(article.slug) # URL slug

225

226

# URL wrapper attributes

227

print(article.category.name) # Category name

228

print(article.category.url) # Category page URL

229

print(article.tags[0].name) # First tag name

230

```

231

232

### Content Translation Support

233

234

```python

235

# Original article

236

original = Article(content="English content", metadata={

237

'title': 'My Post',

238

'lang': 'en'

239

}, settings=settings)

240

241

# Translation

242

translation = Article(content="Contenu français", metadata={

243

'title': 'Mon Article',

244

'lang': 'fr',

245

'translation': True

246

}, settings=settings)

247

248

# Link translations

249

original.translations.append(translation)

250

```

251

252

### Custom Content Processing

253

254

```python

255

from pelican.contents import Content

256

257

class CustomContent(Content):

258

"""Custom content type with special processing."""

259

260

def __init__(self, *args, **kwargs):

261

super().__init__(*args, **kwargs)

262

self.process_custom_metadata()

263

264

def process_custom_metadata(self):

265

# Custom metadata processing logic

266

if 'custom_field' in self.metadata:

267

self.custom_attribute = self.metadata['custom_field'].upper()

268

```