Pelican - Flat CMS

Posted on lun. 23 novembre 2015 in Hosting,

Je viens de découvrir ce projet, et j'avoue j'adore le principe.
Il s'agit d'un projet python, permettant de publier un site statique à partir de contenu écrit en Markdown.

Source :
http://docs.getpelican.com/en/stable/quickstart.html
http://huynen.fr/pelican.html


Installation des pré-requis

L'installation est assez simple, il s'agit d'un paquet python présent dans les dépôts.

$ aptitude install python-pelican

Une fois installé, il est nécessaire de préparer l'arborescence qui servira à générer notre site

$ mkdir -p /var/www/monblog/
$ cd /var/www/monblog/


Récupération des plugins

$ git clone https://github.com/getpelican/pelican-plugins.git /var/www/monblog/pelican-plugins

Récupération des thèmes

$ git clone https://github.com/getpelican/pelican-themes.git /var/www/monblog/themes


Initialisation

$ pelican-quickstart

Welcome to pelican-quickstart v3.3.0.

This script will help you create a new Pelican-based website.

Please answer the following questions so this script can generate the files
needed by Pelican.


> Where do you want to create your new web site? [.]
> What will be the title of this web site? monblog
> Who will be the author of this web site? monblog
> What will be the default language of this web site? [en] en
> Do you want to specify a URL prefix? e.g., http://example.com   (Y/n) Y
> What is your URL prefix? (see above example; no trailing slash) 
> Do you want to enable article pagination? (Y/n) Y
> How many articles per page do you want? [10] 10
> Do you want to generate a Fabfile/Makefile to automate generation and publishing? (Y/n) Y
> Do you want an auto-reload & simpleHTTP script to assist with theme and site development? (Y/n) Y
> Do you want to upload your website using FTP? (y/N) N
> Do you want to upload your website using SSH? (y/N) N
> Do you want to upload your website using Dropbox? (y/N) N
> Do you want to upload your website using S3? (y/N) N
> Do you want to upload your website using Rackspace Cloud Files? (y/N) N
Done. Your new project is available at /var/www/monblog/


Configuration

voici un exemple de configuration de l'instance de pelican.

$ vi /var/www/monblog/pelicanconf.py



#!/usr/bin/env python
 # -*- coding: utf-8 -*- #
 from __future__ import unicode_literals

 AUTHOR = u'admin'
 SITENAME = u"Monblog"
 SITEURL = 'http://monblog.fr'

 ## Theme
 THEME = './themes/Flex'
 ## Theme - Options
 SITETITLE = "monblog"
 SITESUBTITLE = "mon soustitre"
 COPYRIGHT_YEAR = "2015"
 MAIN_MENU = True
 GOOGLE_ANALYTICS = ''

 PATH = 'content'

 TIMEZONE = 'Europe/Paris'

 DEFAULT_LANG = u'en'

 # Feed generation is usually not desired when developing
 FEED_ALL_ATOM = None
 CATEGORY_FEED_ATOM = None
 TRANSLATION_FEED_ATOM = None

 PLUGIN_PATHS = ['./pelican-plugins']
 PLUGINS=['sitemap', 'gzip_cache']

 SITEMAP = {
     'format': 'xml',
     'priorities': {
         'articles': 0.5,
         'indexes': 0.5,
         'pages': 0.5
     },
     'changefreqs': {
         'articles': 'monthly',
         'indexes': 'daily',
         'pages': 'monthly'
     }
 }

 # Blogroll
 LINKS = (('Pelican', 'http://getpelican.com/'),
          ('Python.org', 'http://python.org/')
          )

 # Social widget
 SOCIAL = (('You can add links in your config file', '#'),
           ('Another social link', '#'),)

 DEFAULT_PAGINATION = 10

 # Uncomment following line if you want document-relative URLs when developing
 RELATIVE_URLS = True


Mon premier post

Les articles doivent être écrits dans le répertoire content.

$ cd /var/www/monblog/content
$ vi monpremier_post.md

Title: Pelican
Date: 2015-11-23 22:00
Category: Pelican
Tags: pelican, python
Slug: monpremier_post
Author: kidrek
Summary: 

- SyntaxHighlit

 ```python
 print "Hello World!!"
 ```

Une fois l'article écrit, il ne reste plus qu'à le publier.

$ make html
pelican /var/www/monblog/content -o /var/www/monblog/output -s /var/www/monblog/pelicanconf.py
Done: Processed 1 articles and 0 pages in 0.30 seconds.


Publication des articles

Il existe 2 possibilités pour publier ses articles sur le web.
Soit, via un serveur web (apache2, nginx) ou via pelican.

via Pelican

$ make serve
cd /var/www/monblog/output && python -m pelican.server 8000

Le blog est accessible via le navigateur à l'url : http://localhost:8000

via nginx

$ vi /etc/nginx/sites-enabled/monblog.conf

server {
    listen 80;
    root /var/www/monblog/output;
    server_name monblog.fr;


    index index.html;

    access_log /var/www/monblog.fr/logs/access_log;
    error_log /var/www/monblog.fr/logs/error_log;


    ## CSS/JS
    location ~* \.(?:ico|css|js)$ {
     expires 30d;
     add_header Pragma public;
     add_header Cache-Control "public";
    }

    location ^~ /theme {
    # This content should very rarely, if ever, change
    expires 1y;
    }               
 }

$ /etc/init.d/nginx restart