You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -20,8 +20,14 @@ with existing files rather than executing any code on the server during
20
20
the HTTP request-response cycle.
21
21
22
22
In this tutorial you will learn how to create a
23
-
[basic static website](/static-site-generator.html) that you can further
24
-
customize and expand with your own design and content.
23
+
[static website](/static-site-generator.html) from scratch
24
+
using [Pelican](/pelican.html).
25
+
26
+
<imgsrc="/img/170605-static-sites-pelican/gunship-bootstrap-css.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Articles page after Bootstrap CSS has been added.">
27
+
28
+
Our simple static site will have pages that look like the above screenshot
29
+
but the entire site can be easily customized and expanded with your own design
30
+
and content.
25
31
26
32
27
33
## Our Tools
@@ -212,6 +218,9 @@ Use the `ps` and `grep` commands to view the process then stop the process
212
218
with the `kill` command as follows. Remember that your process ID will almost
213
219
definitely be different from the `1365` ID for my process.
214
220
221
+
Kill the development server now so that we can use different commands to
222
+
serve our site after we create our initial content.
Done: Processed 0 articles, 0 drafts, 0 pages and 0 hidden pages in 0.07 seconds.
321
+
Done: Processed 1 article, 0 drafts, 0 pages and 0 hidden pages in 0.14 seconds.
286
322
```
287
323
288
-
If you used the `make devserver` command earlier then give Python's built-in
289
-
HTTP server a shot with the following command.
324
+
Our site has been regenerated and placed in the `output` directory.
325
+
326
+
If you used the `make devserver` command earlier then change into the `output`
327
+
directory and give Python's built-in HTTP server a shot with the following
328
+
command.
290
329
291
330
```
331
+
cd output
292
332
python -m http.server
293
333
```
294
334
295
-
You can change the port binding by adding a number after the command, if you
296
-
want to serve more than one static site at a time or you already have an
297
-
application bound to port 8000.
335
+
Our first post in all its glory...
336
+
337
+
<imgsrc="/img/170605-static-sites-pelican/gunship-first-post.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Gunship as our first band post on retro synthwave static site.">
338
+
339
+
You can change the HTTP server port binding by adding a number after the
340
+
command, if you want to serve more than one static site at a time or you
341
+
already have an application bound to port 8000.
298
342
299
343
```
300
344
python -m http.server 8005
@@ -303,30 +347,184 @@ python -m http.server 8005
303
347
Note that if you are using Python 2 the equivalent HTTP server command is
304
348
`python -m SimpleHTTPServer`.
305
349
350
+
We now have some very basic site content. We could expand this start into many
351
+
more posts and pages but let's learn how to modify the site configuration.
306
352
307
353
308
-
## Edit the Configuration
309
-
Pelican's quickstart assumes a bunch of defaults that may or may not be
354
+
## Edit Site Configuration
355
+
Pelican's quickstart assumed a bunch of defaults that may or may not be
310
356
applicable to your site. Open up the `pelicanconf.py` file to change some
311
357
of the defaults.
312
358
313
359
Look for the `TIMEZONE` variable. If it's not right for your location
314
360
then modify it to your zone. Wikipedia has a handy
315
361
[table of valid time zones values](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
316
362
363
+
Also modify the `LINKS` tuple to include your site (or Full Stack Python!)
364
+
instead of including the "you can modify those links" link. Change the
365
+
last line of `LINKS` so it looks like the following tuple of tuples.
Instead of using the `make html` file, this time we will invoke the
376
+
`pelican` command directly from the command line. There is nothing wrong
377
+
with the `Makefile`, but it is a good idea to get comfortable with Pelican
378
+
directly instead of only through build files.
379
+
380
+
```bash
381
+
pelican -s pelicanconf.py -o output content
382
+
```
383
+
384
+
Now run the HTTP server if you do not already have it running in another
385
+
terminal window.
386
+
387
+
```
388
+
cd output
389
+
python -m http.server
390
+
```
391
+
392
+
Head back to the browser and refresh to view the updated configuration.
393
+
394
+
<imgsrc="/img/170605-static-sites-pelican/updated-configuration.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="New links created by the pelicanconf.py configuration settings file.">
395
+
396
+
What happens when we click on the blog post title? It takes us to a
<imgsrc="/img/170605-static-sites-pelican/gunship-post.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Gunship subpage for the site.">
401
+
402
+
Alright, we updated some basic site-wide data, but our site really could
403
+
use a change of paint.
404
+
405
+
406
+
## Modify Site Theme
407
+
Changing the site theme is really where you can turn a standard blog into
408
+
whatever type of site you want to build. While the default Pelican
409
+
configuration creates a blog template, you do not need to have a
410
+
chronological structure if it is not right for your website.
411
+
412
+
Create a new directory under your project directory that is named
413
+
`theme`. Within `theme` create another directory named `templates`.
414
+
`templates` is where our [Jinja2](/jinja2.html) templates will be stored and
415
+
can override the default theme.
416
+
417
+
...base.html...
418
+
419
+
```jinja2
420
+
```
421
+
422
+
Within `theme/templates` create a file named `article.html` that will have a
423
+
different theme for blog posts than the rest of the site. Fill `article.html`
424
+
with the following Jinja2 markup.
425
+
426
+
```jinja2
427
+
<!DOCTYPE html>
428
+
<html lang="en">
429
+
<head>
430
+
<title>{{ article.title }}</title>
431
+
</head>
432
+
<body>
433
+
<div class="container">
434
+
<div class="row">
435
+
<div class="col-md-8">
436
+
<h1>{{ article.title }}</h1>
437
+
<label>Posted on <strong>{{ article.date }}</strong></label>
438
+
{{ article.content }}
439
+
</div>
440
+
</div>
441
+
</div>
442
+
</body>
443
+
</html>
444
+
```
445
+
446
+
Next we will use a Jinja2 template to override the default `index.html` main
447
+
page. Again within the `theme/templates` directory, create a file named
448
+
`index.html` with the following markup.
449
+
450
+
```jinja2
451
+
<!DOCTYPE html>
452
+
<html lang="en">
453
+
<head>
454
+
<title>{{ SITENAME }}</title>
455
+
<!-- Latest compiled and minified Bootstrap CSS -->
Click on the Gunship post however and we see that the `article.html`
494
+
"styling" has been applied to the page.
495
+
496
+
<imgsrc="/img/170605-static-sites-pelican/gunship-no-styling.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Articles have an entirely different theme based on article.html markup.">
497
+
498
+
Pretty sparse! We can at least add the Bootstrap CSS to the HTML to
499
+
align our content.
500
+
501
+
Within `article.html`, add the following line for Bootstrap under
502
+
`<title>{{ article.title }}</title>`.
503
+
504
+
```jinja2
505
+
<!-- Latest compiled and minified Bootstrap CSS -->
<imgsrc="/img/170605-static-sites-pelican/gunship-bootstrap-css.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Articles page after Bootstrap CSS has been added.">
317
512
318
-
## Modify the Site Theme
513
+
Well at least our design has moved from 1996 to 2001. I am sure you can
514
+
do a whole lot more to improve your own site's design.
319
515
516
+
The new `article.html` is not much of a theme for now but it at least
517
+
provides a fresh start for completely customized blog posts.
320
518
321
519
322
520
## What's next?
323
521
You generated your first [Pelican](/pelican.html) static website using
324
-
[Markdown](/markdown.html) and [Jinja2](/jinja2.html). You can
325
-
now make additional modifications to the Jinja2 templates, build new pages
326
-
and add more content via Markdown files.
522
+
[Markdown](/markdown.html) and [Jinja2](/jinja2.html). Additional modifications
523
+
can be made to the Jinja2 templates and the content contained in the Markdown
524
+
files.
327
525
328
526
Do you want to deploy your new static website to GitHub Pages or an S3 bucket?
329
-
Well, that's a story for another Full Stack Python tutorial...
527
+
Well, that's a story for another [Full Stack Python tutorial](/blog.html)...
330
528
331
529
Questions? Let me know via
332
530
[a GitHub issue ticket on the Full Stack Python repository](https://github.com/mattmakai/fullstackpython.com/issues),
0 commit comments