File: manual.md

package info (click to toggle)
blag 2.3.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 520 kB
  • sloc: python: 1,037; makefile: 71
file content (264 lines) | stat: -rw-r--r-- 6,442 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# Manual


## Quickstart

Install blag from [PyPI][]

```sh
$ pip install blag
```

[pypi]: https://pypi.org/project/blag/

Run blag's quickstart command to create the configuration, templates and some
initial content.

```sh
$ blag quickstart
```

Create some content

```sh
$ edit content/hello-world.md
```

Generate the website

```sh
$ blag build
```

By default, blag will search for content in `content` and the output will be
generated in `build`. All markdown files in `content` will be converted to
html, all other files (i.e. static files) will be copied over).

If you want more separation between the static files and the markdown content,
you can put all static files into the `static` directory. Blag will copy them
over to the `build` directory.

If you want to customize the look of the generated site, visit the `template`
directory. It contains jinja2 templates and can be modified as needed.

Those directories can be changed via command line arguments. See

```sh
$ blag --help
```


## Manual

### Pages and Articles

Internally, blag differentiates between **pages** and **articles**.
Intuitively, pages are simple pages and articles are blog posts. The decision
whether a document is a page or an article is made depending on the presence of
the `date` metadata element: Any document that contains the `date` metadata
element is an article, everything else a page.

This differentiation has consequences:

* blag uses different templates: `page.html` and `article.html`
* only articles are collected in the Atom feed
* only articles are aggregated in the tag pages

blag does **not** enforce a certain directory structure for pages and articles.
You can mix and match them freely or structure them in different directories.
blag will mirror the structure found in the `content` directory

```
content/
    article1.md
    article2.md
    page1.md
```

results in:

```
build/
    article1.html
    article2.html
    page1.html
```

Arbitrary complex structures are possible too:

```
content/
    posts/
        2020/
            2020-01-01-foo.md
            2020-02-01-foo.md
    pages/
        foo.md
        bar.md
```

results in:

```
build/
    posts/
        2020/
            2020-01-01-foo.html
            2020-02-01-foo.html
    pages/
        foo.html
        bar.html
```


### Static Files

Static files can be put into the `content` directory and will be copied over to
the `build` directory as well. If you want better separation between content
and static files, you can use the `static` directory and put the files there.
All files and directories found in the `static` directory will be copied over
to `build`.

```
content/
    foo.md
    bar.md
    kitty.jpg
```

results in:

```
build/
    foo.html
    bar.html
    kitty.jpg
```

Alternatively:

```
content/
    foo.md
    bar.md
static/
    kitty.jpg
```

results in:

```
build/
    foo.html
    bar.html
    kitty.jpg
```


### Internal Links

In contrast to most other static blog generators, blag will automatically
convert **relative** markdown links. That means you can link you content using
relative markdown links and blag will convert them to html automatically. The
advantage is that your content tree in markdown is consistent and
self-contained even if you don't generate html from it.


```markdown
[...]
this is a [link](foo.md) to an internal page foo.
```

becomes

```html
<p>this is a <a href="foo.html">link</a> to an internal page foo.</p>
```

```python
def this_is_a(test):
    pass
```

### Templating

Templates are stored by default in the `templates` directory.

Template     | Used For                               | Variables
------------ | -------------------------------------- | -------------------
page.html    | pages (i.e. non-articles)              | site, content, meta
article.html | articles (i.e. blog posts)             | site, content, meta
index.html   | landing page of the blog               | site, archive
archive.html | archive page of the blog               | site, archive
tags.html    | list of tags                           | site, tags
tag.html     | archive of Articles with a certain tag | site, archive, tag

If you make use of Jinja2's template inheritance, you can of course have more
template files in the `templates` directory.


#### Variables

* `site`: This dictionary contains the site configuration, namely: `base_url`,
  `title`, `description` and `author`. Don't confuse the site-title and
  -description with the title and description of individual pages or articles.

* `content`: HTML, converted from markdown.

* `meta`: stands for all metadata elements available in the article or page.
  Please be aware that those are not wrapped in a dictionary, but **directly**
  available as variables.

* `archive`: A list of `[destination path, context]` tuples, where the context
  are the respective variables that would be provided to the individual page or
  article.

* `tags`: List of tags.

* `tag`: A tag.


### Metadata

blag supports metadata elements in the markdown files. They must come before
the content and should be separated from the content with a blank line:

```markdown
title: foo
date: 2020-02-02
tags: this, is, a, test
description: some subtitle

this is my content.
[...]
```

blag supports *arbitrary* metadata in your documents, and you can use them
freely in you templates. However, some metadata elements are treated special:

* `date`: If a document contains the `date` element, it is treated as an
  **article**, otherwise as a **page**. Additionally, `date` elements are
  expected to be in ISO format (e.g. `1980-05-09 21:58`). They are
  automatically converted into `datetime` objects with the local timezone
  attached.

* `tags`: Tags are interpreted as a comma separated list. All elements are
  stripped and converted to lower-case: `tags: foo, Foo Bar, BAZ` becomes:
  `[foo, foo bar, baz]`. Tags in **articles** are also used to generate the
  tag-pages, that aggregate all articles per tag.

* `title` and `description`: The title and description are used in the html
  header and in the atom feed.


## Devserver

blag provides a devserver which you can use for local web-development. The
devserver provides a simple web server, serving your site in
http://localhost:8000 and will automatically rebuild the project when it
detects modifications in one of the `content`, `static` and `templates`
directories.

```sh
$ blag serve
```