Migrating blog to nikola + GAE

This blog has been in deep lethar­gy for sev­er­al years. I’m not sure I can make it come back to life, but I’ll try, first of all by ex­plain­ing how I man­aged to mi­grate it from blog­ger to stat­ic site host­ing gen­er­at­ed by niko­la and host­ed on GAE (Google app en­gine).

Import in Nikola

Nikola proposes the plugin import_blogger which allows you to import an XML export file of blogger into the nikola file structure. You may install it with:

nikola plugin -i import_blogger

A niko­la project is then cre­at­ed with the com­mand:

nikola import_blogger -o name_of_blog blogger_export. xml

Then copy the generated configuration file (e.g. conf. py. import_blogger-20171228_142937) to the file conf. py and modify the configuration according to your wishes.

Blog ar­ti­cle files are gen­er­at­ed in html for­mat with a . meta file in re­struc­tured­text for­mat con­tain­ing the ar­ti­cle’s meta­da­ta.

Overall the conversion goes well and the rendering is acceptable. However, some articles require some tweaking. I get them through the tools: pandoc and html2text2 to get a version of the article in restructuredtext format to be taken up and modified by hand:

html2text2 article. html | pandoc -f markdown -t rst > article. rst
mv article. html article. html article. bak

Hosting on GAE

Google pro­vides pret­ty de­tailed ex­pla­na­tions for host­ing a stat­ic blog on GAE. Ap­plied to a stat­ic blog gen­er­at­ed by Niko­la, you need to:

  1. Cre­ate a project on the con­­sole google cloud.

  2. Put the file ap­p. yaml in the fol­low­ing di­rec­to­ry files at the root of the pro­jec­t:

    run­time:   python27  api_ver­sion:   1  thread­safe:   true    han­dlers:  -   url:   /      stat­ic_­files:   in­dex.html      up­load:   in­dex.html    -   url:   /en/      stat­ic_­files:   en/in­dex.html      up­load:   en/in­dex.html    -   url:   /(.*)      stat­ic_­files:   \1      up­load:   (.*)  
  3. Change the pa­ram­e­ter DE­PLOY_­COM­MANDS in the file con­f. py as fol­lows (re­plac­ing gae_pro­jec­t_id with the iden­ti­fi­er of the project cre­at­ed in 1.:

    STRIP_IN­DEX­ES   =   False  PRET­TY_URLS   =   False  DE­PLOY_­COM­MANDS   =   {        'de­fault':   [            "cd out­put && gcloud app de­ploy --pro­ject gae_pro­jec­t_id"        ]  }  

It is probably possible to use PRETTY_URLS by modifying the file app. yaml to take by default the files index. html, but this configuration allows to keep the same URLs as on blogger if you configure the redirection for the old URLs:

REDIRECTIONS = [
    ('2012/04/lettre-eva-joly.html', '/posts/2012/04/lettre-eva-joly.html'),
    ]

Or even more simply, as @GetNikola very kindly pointed out to me on twitter, by replacing posts with "" in the variable POSTS:

POSTS = (
            ("posts/*.txt", "", "post.tmpl"),
            ("posts/*.rst", "", "post.tmpl"),
            ("posts/*.html", "", "post.tmpl"),
            )

Then a simple nikola build && nikola deploy will make the site accessible on the URL https://gae_project_id. appspot. com. You are free to configure your DNS registration so that your domain name redirects to this page. You can also configure the automatic generation and renewal of certificates to make your site accessible in HTTPS. This is easily done on the google cloud console.

Comments