ursus-ssg 1.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. ursus_ssg-1.3.0/PKG-INFO +447 -0
  2. ursus_ssg-1.3.0/README.md +420 -0
  3. ursus_ssg-1.3.0/bin/ursus +80 -0
  4. ursus_ssg-1.3.0/setup.cfg +4 -0
  5. ursus_ssg-1.3.0/setup.py +46 -0
  6. ursus_ssg-1.3.0/ursus/__init__.py +64 -0
  7. ursus_ssg-1.3.0/ursus/config.py +155 -0
  8. ursus_ssg-1.3.0/ursus/context_processors/__init__.py +29 -0
  9. ursus_ssg-1.3.0/ursus/context_processors/get_entries.py +74 -0
  10. ursus_ssg-1.3.0/ursus/context_processors/git_date.py +39 -0
  11. ursus_ssg-1.3.0/ursus/context_processors/image.py +19 -0
  12. ursus_ssg-1.3.0/ursus/context_processors/markdown.py +320 -0
  13. ursus_ssg-1.3.0/ursus/context_processors/related.py +33 -0
  14. ursus_ssg-1.3.0/ursus/context_processors/stale.py +18 -0
  15. ursus_ssg-1.3.0/ursus/generators/__init__.py +62 -0
  16. ursus_ssg-1.3.0/ursus/generators/static.py +66 -0
  17. ursus_ssg-1.3.0/ursus/linters/__init__.py +46 -0
  18. ursus_ssg-1.3.0/ursus/linters/footnotes.py +41 -0
  19. ursus_ssg-1.3.0/ursus/linters/images.py +29 -0
  20. ursus_ssg-1.3.0/ursus/linters/markdown.py +161 -0
  21. ursus_ssg-1.3.0/ursus/renderers/__init__.py +16 -0
  22. ursus_ssg-1.3.0/ursus/renderers/image.py +53 -0
  23. ursus_ssg-1.3.0/ursus/renderers/jinja.py +281 -0
  24. ursus_ssg-1.3.0/ursus/renderers/lunr.py +78 -0
  25. ursus_ssg-1.3.0/ursus/renderers/sass.py +31 -0
  26. ursus_ssg-1.3.0/ursus/renderers/static.py +67 -0
  27. ursus_ssg-1.3.0/ursus/server.py +48 -0
  28. ursus_ssg-1.3.0/ursus/utils.py +342 -0
  29. ursus_ssg-1.3.0/ursus_ssg.egg-info/PKG-INFO +447 -0
  30. ursus_ssg-1.3.0/ursus_ssg.egg-info/SOURCES.txt +33 -0
  31. ursus_ssg-1.3.0/ursus_ssg.egg-info/dependency_links.txt +1 -0
  32. ursus_ssg-1.3.0/ursus_ssg.egg-info/entry_points.txt +6 -0
  33. ursus_ssg-1.3.0/ursus_ssg.egg-info/not-zip-safe +1 -0
  34. ursus_ssg-1.3.0/ursus_ssg.egg-info/requires.txt +16 -0
  35. ursus_ssg-1.3.0/ursus_ssg.egg-info/top_level.txt +1 -0
@@ -0,0 +1,447 @@
1
+ Metadata-Version: 2.1
2
+ Name: ursus_ssg
3
+ Version: 1.3.0
4
+ Summary: Static site generator
5
+ Home-page: http://github.com/all-about-berlin/ursus
6
+ Author: Nicolas Bouliane
7
+ Author-email: contact@nicolasbouliane.com
8
+ License: MIT
9
+ Requires-Python: >=3.11
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: coloredlogs==15.0.1
12
+ Requires-Dist: GitPython==3.1.43
13
+ Requires-Dist: imagesize==1.4.1
14
+ Requires-Dist: Jinja2==3.1.4
15
+ Requires-Dist: jinja2-simple-tags==0.6.1
16
+ Requires-Dist: libsass==0.23.0
17
+ Requires-Dist: lunr==0.7.0
18
+ Requires-Dist: Markdown==3.5.2
19
+ Requires-Dist: MarkupSafe==2.1.5
20
+ Requires-Dist: ordered-set==4.1.0
21
+ Requires-Dist: PyMuPDF==1.24.5
22
+ Requires-Dist: Pillow==10.3.0
23
+ Requires-Dist: watchdog==4.0.1
24
+ Requires-Dist: requests==2.32.3
25
+ Requires-Dist: rjsmin==1.2.2
26
+ Requires-Dist: rcssmin==1.1.2
27
+
28
+ # Ursus
29
+
30
+ Ursus is the static site generator used by [All About Berlin](https://allaboutberlin.com) and my [personal website](https://nicolasbouliane.com). It turns Markdown files and [Jinja](https://jinja.palletsprojects.com/) templates into a static website.
31
+
32
+ It also renders images in different sizes, renders SCSS, minifies JS and generates Lunr.js search indexes.
33
+
34
+ This project is in active use and development.
35
+
36
+ ## Setup
37
+
38
+ ### Installation
39
+
40
+ Install Ursus with pip:
41
+
42
+ ```bash
43
+ pip install ursus-ssg
44
+ ```
45
+
46
+ ### Getting started
47
+
48
+ Call `ursus` to generate a static website. Call `ursus --help` to see the command line options it supports.
49
+
50
+ By default, Ursus looks for 3 directories, relative to the current directory:
51
+
52
+ - It looks for content in `./content`
53
+ - It looks for page templates in `./templates`
54
+ - It generates a static website in `./output`
55
+
56
+ For example, create a markdown file and save it as `./content/posts/first-post.md`.
57
+
58
+ ```markdown
59
+ ---
60
+ title: Hello world!
61
+ description: This is an example page
62
+ date_created: 2022-10-10
63
+ ---
64
+
65
+ ## Hello beautiful world
66
+
67
+ *This* is a template. Pretty cool eh?
68
+ ```
69
+
70
+ Then, create a page template and save it as `./templates/posts/entry.html.jinja`.
71
+
72
+ ```
73
+ <!DOCTYPE html>
74
+ <html>
75
+ <head>
76
+ <title>{{ entry.title }}</title>
77
+ <meta name="description" content="{{ entry.description }}">
78
+ </head>
79
+ <body>
80
+ {{ entry.body }}
81
+
82
+ Created on {{ entry.date_created }}
83
+ </body>
84
+ </html>
85
+ ```
86
+
87
+ Your project should now look like this:
88
+
89
+ ```
90
+ my-website/ <- You are here
91
+ ├─ content/
92
+ │ └─ posts/
93
+ │ └─ first-post.md
94
+ └─ templates/
95
+ └─ posts/
96
+ └─ entry.html.jinja
97
+ ```
98
+
99
+ Call `ursus` to generate a statuc website. It will create `./output/posts/first-post.html`.
100
+
101
+ ### Configuring Ursus
102
+
103
+ To configure Ursus, create a configuration file.
104
+
105
+ ```python
106
+ # Example Ursus config file
107
+ # Find all configuration options in `ursus/config.py`.
108
+ from ursus.config import config
109
+
110
+ config.content_path = Path(__file__).parent / 'blog'
111
+ config.templates_path = Path(__file__).parent / 'templates'
112
+ config.output_path = Path(__file__).parent.parent / 'dist'
113
+
114
+ config.site_url = 'https://allaboutberlin.com'
115
+
116
+ config.minify_js = True
117
+ config.minify_css = True
118
+ ```
119
+
120
+ If you call your configuration file `ursus_config.py`, Ursus loads it automatically.
121
+
122
+ ```
123
+ my-website/
124
+ ├─ ursus_config.py
125
+ ├─ content/
126
+ └─ templates/
127
+ ```
128
+
129
+ You can also load a configuration file with the `-w` argument.
130
+
131
+ ```bash
132
+ ursus -c /path/to/config.py
133
+ ```
134
+
135
+ ### Watching for changes
136
+
137
+ Ursus can rebuild your website when the content or templates change.
138
+
139
+ ```bash
140
+ # Rebuild when content or templates change
141
+ ursus -w
142
+ ursus --watch
143
+ ```
144
+
145
+ It can only rebuild the pages that changed. This is much faster, but it does not work perfectly.
146
+
147
+ ```bash
148
+ # Only rebuild the pages that changed
149
+ ursus -wf
150
+ ursus --watch --fast
151
+ ```
152
+
153
+ ### Serving the website
154
+
155
+ Ursus can serve the website it generates. This is useful for testing.
156
+
157
+ ```bash
158
+ # Serve the static website on port 80
159
+ ursus -s
160
+ ursus --serve 80
161
+ ```
162
+
163
+ This is not meant for production. Use nginx, Caddy or some other static file server for that.
164
+
165
+ ## How Ursus works
166
+
167
+ 1. **Context processors** generate the context used to render templates. The context is just a big dictionary.
168
+ 2. **Renderers** use the context and the templates to render the parts of the final website: pages, thumbnails, static assets, etc.
169
+
170
+ ### Content
171
+
172
+ **Content** is what fills your website: text, images, videos, PDFs. Content is usually *rendered* to create a working website. Some content (like Markdown files) is rendered with Templates, and other (like images) is converted to a different file format.
173
+
174
+ Ursus looks for content in `./content`, unless you change `config.content_path`.
175
+
176
+ ### Entries
177
+
178
+ A single piece of content is called an **Entry**. This can be a single image, a single markdown file, etc.
179
+
180
+ Each Entry has a **URI**. This is the Entry's unique identifier. The URI is the Entry's path relative to the content directory. For example, the URI of `./content/posts/first-post.md` is `posts/first-post.md`.
181
+
182
+ ### Context
183
+
184
+ The **Context** contains the information needed to render your website. It's just a big dictionary, and you can put anything in it.
185
+
186
+ `context['entries']` contains is a dictionary of all your entries. The key is the Entry URI.
187
+
188
+ **Context processors** each add specific data to the context. For example, `MarkdownProcessor` adds your `.md` content to `context.entries`.
189
+
190
+ ```python
191
+ # Example context
192
+ {
193
+ 'entries': {
194
+ 'posts/first-post.md': {
195
+ 'title': 'Hello world!',
196
+ 'description': 'This is an example page',
197
+ 'date_created': datetime(2022, 10, 10),
198
+ 'body': '<h2>Hello beautiful world</h2><p>...',
199
+ },
200
+ 'posts/second-post.md': {
201
+ # ...
202
+ },
203
+ },
204
+ # Context processors can add more things to the context
205
+ 'blog_title': 'Example blog',
206
+ 'site_url': 'https://example.com/blog',
207
+ }
208
+ ```
209
+
210
+ ### Templates
211
+
212
+ **Templates** are used to render your Content. They are the theme of your website. Jinja templates, Javascript, CSS and theme images belong in the templates directory.
213
+
214
+ Ursus looks for templates in `./templates`, unless you change `config.templates_path`.
215
+
216
+ ### Renderers
217
+
218
+ **Renderers** use the Context and the Templates to generate parts of your static website. For example, `JinjaRenderer` renders Jinja templates, `ImageTransformRenderer` converts and resizes your images, and `StaticAssetRenderer` copies your static assets.
219
+
220
+ ### Output
221
+
222
+ This is the final static website generated by Ursus. Ursus generates a static website in `./output`, unless you change `config.output_path`.
223
+
224
+ The content of the output directory is ready to be served by any static file server.
225
+
226
+ ## How context processors work
227
+
228
+ Context processors transform the context, which is a dict with information about each of your Entries.
229
+
230
+ Context processors ignore file and directory names that start with `.` or `_`. For example, `./content/_drafts/hello.md` and `./content/posts/_post-draft.md` are ignored.
231
+
232
+ ### MarkdownProcessor
233
+
234
+ The `MarkdownProcessor` creates context for all `.md` files in `content_path`. The markdown content is in the `body` attribute.
235
+
236
+ ```python
237
+ {
238
+ 'entries': {
239
+ 'posts/first-post.md': {
240
+ 'title': 'Hello world!',
241
+ 'description': 'This is an example page',
242
+ 'date_created': datetime(2022, 10, 10),
243
+ 'body': '<h2>Hello beautiful world</h2><p>...',
244
+ },
245
+ # ...
246
+ },
247
+ }
248
+ ```
249
+
250
+ It makes a few changes to the default markdown output:
251
+
252
+ - Put the front matter in the context
253
+ - `related_*` keys are replaced by a list of related entry dicts
254
+ - `date_` keys are converted to `datetime` objects
255
+ - Other attributes are added to the entry object.
256
+ - Use responsive images based on `config.image_transforms` settings.
257
+ - `<img>` are converted to `<figure>` or `<picture>` tags when appropriate.
258
+ - Images are lazy-loaded with the `loading=lazy` attribute.
259
+ - Jinja tags (`{{ ... }}` and `{% ... %}`) are rendered as-is. You can use `{% include %}` and `{{ variables }}` in your content.
260
+
261
+ ### GetEntriesProcessor
262
+
263
+ The `GetEntriesProcessor` adds a `get_entries` method to the context. It's used to get a list of entries of a certain type, and sort it.
264
+
265
+ ```jinja
266
+ {% set posts = get_entries('posts', filter_by=filter_function, sort_by='date_created', reverse=True) %}
267
+
268
+ {% for post in posts %}
269
+ ...
270
+ ```
271
+
272
+ ### GitDateProcessor
273
+
274
+ Adds the `date_updated` attribute to all Entries. It uses the file's last commit date.
275
+
276
+ ```python
277
+ {
278
+ 'entries': {
279
+ 'posts/first-post.md': {
280
+ 'date_updated': datetime(2022, 10, 10),
281
+ # ...
282
+ },
283
+ # ...
284
+ },
285
+ }
286
+ ```
287
+
288
+ ### ImageProcessor
289
+
290
+ Adds images and PDFs Entries to the context. Dimensions and image transforms are added to each Entry. Use in combination with `config.image_transforms`.
291
+
292
+ ```python
293
+ {
294
+ 'entries': {
295
+ 'images/hello.jpg': {
296
+ 'width': 320,
297
+ 'height': 240,
298
+ 'image_transforms': [
299
+ {
300
+ 'is_default': True,
301
+ 'input_mimetype': 'image/jpeg',
302
+ 'output_mimetype': 'image/webp',
303
+ # ...
304
+ },
305
+ # ...
306
+ ]
307
+ },
308
+ # ...
309
+ },
310
+ }
311
+ ```
312
+
313
+ ## How renderers work
314
+
315
+ Renderers use context and templates to generate parts of the static website.
316
+
317
+ A **Generator** takes your Content and your Templates and produces an Output. It's a recipe to turn your content into a final result. The default **StaticSiteGenerator** generates a static website. You can write your own Generator to output an eBook, a PDF, or anything else.
318
+
319
+ ### ImageTransformRenderer
320
+
321
+ Renders images in your content directory.
322
+
323
+ - Images are converted and resized according to `config.image_transforms`.
324
+ - Files that can't be transformed (PDF to PDF) are copied as-is to the output directory.
325
+ - Images that can't be resized (SVG to anything) are copied as-is to the output directory.
326
+ - Image EXIF data is removed.
327
+
328
+ This renderer does nothing unless `config.image_transforms` is set:
329
+
330
+ ```python
331
+ from ursus.config import config
332
+
333
+ config.image_transforms = {
334
+ # ./content/images/test.jpg
335
+ # ---> ./output/images/test.jpg
336
+ # ./content/images/test.pdf
337
+ # ---> ./output/images/test.pdf
338
+ '': {
339
+ 'include': ('images/*', 'documents/*'),
340
+ 'output_types': ('original'),
341
+ },
342
+ # ./content/images/test.jpg
343
+ # ---> ./output/images/content2x/test.jpg
344
+ # ---> ./output/images/content2x/test.webp
345
+ 'content2x': {
346
+ 'include': ('images/*', 'illustrations/*'),
347
+ 'exclude': ('*.pdf', '*.svg'),
348
+ 'max_size': (800, 1200),
349
+ 'output_types': ('webp', 'original'),
350
+ },
351
+ # ./content/documents/test.pdf
352
+ # ---> ./output/documents/pdfPreviews/test.png
353
+ # ---> ./output/documents/pdfPreviews/test.webp
354
+ 'pdfPreviews': {
355
+ 'include': 'documents/*',
356
+ 'max_size': (300, 500),
357
+ 'output_types': ('webp', 'png'),
358
+ },
359
+ }
360
+ ```
361
+
362
+ ### JinjaRenderer
363
+
364
+ Renders `*.jinja` files in the templates directory.
365
+
366
+ The output file has the same name and relative path as the template, but the `.jinja` extension is removed.
367
+
368
+ ```
369
+ my-website/
370
+ ├─ templates/
371
+ │ ├─ contact.html.jinja
372
+ │ ├─ sitemap.xml.jinja
373
+ │ └─ posts/
374
+ │ └─ index.html.jinja
375
+ └─ output/
376
+ ├─ contact.html
377
+ ├─ sitemap.xml
378
+ └─ posts/
379
+ └─ index.html
380
+ ```
381
+
382
+ Files named `entry.*.jinja` will render every entry with the same relative path.
383
+
384
+ ```
385
+ my-website/
386
+ ├─ content/
387
+ │ └─ posts/
388
+ │ ├─ first-post.md
389
+ │ ├─ second-post.md
390
+ │ └─ _draft.md
391
+ ├─ templates/
392
+ │ └─ posts/
393
+ │ └─ entry.html.jinja
394
+ └─ output/
395
+ └─ posts/
396
+ ├─ first-post.html
397
+ └─ second-post.html
398
+ ```
399
+
400
+ Files or directory names that start with `.` or `_` are not rendered.
401
+
402
+ ```
403
+ my-website/
404
+ ├─ content/
405
+ │ └─ posts/
406
+ │ ├─ hello-world.md
407
+ │ ├─ .hidden.md
408
+ │ └─ _drafts
409
+ │ └─ not-rendered.md
410
+ ├─ templates/
411
+ │ └─ posts/
412
+ │ └─ entry.html.jinja
413
+ └─ output/
414
+ └─ posts/
415
+ └─ hello-world.html
416
+ ```
417
+
418
+ ### StaticAssetRenderer
419
+
420
+ Copies all files under `./templates` except `.jinja` files to the same subdirectory in `./output`. Files starting with `.` are ignored. Files and directories starting with `_` are ignored.
421
+
422
+ ```
423
+ my-website/
424
+ ├─ templates/
425
+ │ ├─ _ignored.jpg
426
+ │ ├─ styles.css
427
+ │ ├─ images/
428
+ │ │ └─ hello.png
429
+ │ └─ js/
430
+ │ └─ test.js
431
+ └─ output/
432
+ ├─ styles.css
433
+ ├─ images/
434
+ │ └─ hello.png
435
+ └─ js/
436
+ └─ test.js
437
+ ```
438
+
439
+ It uses hard links instead of copying files, so it does not use extra disk space.
440
+
441
+ ## How generators work
442
+
443
+ Generators bring it all together. A generator takes all of your files, and generates some final product. There is only `StaticSiteGenerator`, which generates a static website. Custom generators could generate a book or a slideshow from the same content and templates.
444
+
445
+ ## How linters work
446
+
447
+ Ursus supports linter. They verify the content when `ursus lint` is called. You can find examples in `ursus/linters`.