Migrating blog to nikola + GAE
This blog has been in deep lethargy for several years. I’m not sure I can make it come back to life, but I’ll try, first of all by explaining how I managed to migrate it from blogger to static site hosting generated by nikola and hosted on GAE (Google app engine).
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 nikola project is then created with the command:
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 article files are generated in html format with a . meta file in restructuredtext format containing the article’s metadata.
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 provides pretty detailed explanations for hosting a static blog on GAE. Applied to a static blog generated by Nikola, you need to:
Create a project on the console google cloud.
-
Put the file
app. yaml
in the following directoryfiles
at the root of the project:runtime: python27 api_version: 1 threadsafe: true handlers: - url: / static_files: index.html upload: index.html - url: /en/ static_files: en/index.html upload: en/index.html - url: /(.*) static_files: \1 upload: (.*)
-
Change the parameter
DEPLOY_COMMANDS
in the fileconf. py
as follows (replacinggae_project_id
with the identifier of the project created in 1.:STRIP_INDEXES = False PRETTY_URLS = False DEPLOY_COMMANDS = { 'default': [ "cd output && gcloud app deploy --project gae_project_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.