Posts about nikola (old posts, page 6)

2013-03-26 12:34

The Password Is Password (follow the link to see what I mean)

I think this is a first in the world of static site generators :-)

Now Nikola supports password-protected pages. How does it work?

If you add a password metadata field, then it will "Just Work". Like this:

I think this is a first in the world of static site generators :-) And the result is what you are seeing now.

How is it implemented? Nikola will encrypt the content using RC4, then wrap it in a <div>, and tack a form at the end that triggers Javascript code to decrypt it, and show it.

Is it secure? Well, I am not a cryptographer, so assume no. Specifically, while RC4 is considered secure, I am not discarding the beginning of they keystream, and the implementations I am using are not audited.

So, don't use this for anything that could get you in trouble. Have fun!

UPDATE Remember when I asked "Is it secure?" well, really, no it's not. It's not stupid in the sense that decoding what's written in the post will require at least a modicum of effort by whoever is so interested in reading what you are posting in your site, but people with crypto chops will crack it like a WEP-secured AP, mmmmkay? It's also stupidly easy to bruteforce this, so be smart about passwords.

OTOH, it's more secure than HTTP simple auth, since you can't sniff it (not that simple auth is secure) and it can hide a piece of the page, which using server-based auth can't.

I may do a more secure version eventually, but this is not it. Therefore, use for fun stuff, not to hide important/illegal stuff.

2013-03-22 11:01

Nikola Internals Doc

Since Nikola, my static blog/website generator is getting a substantial amount of code from others, I thought it may be a good idea to roughly document how it works internally. So, here is Nikola internals which is very much a work in progress.

2013-03-15 00:39

Migrating from Wordpress to Nikola

Several people have migrated from Wordpress into Nikola, and here are some of their descriptions of the process:

In general, it seems to be working, but there's some work still to be done. Wordpress supports many different plugins and extensions which react to markup in their pages, and supporting that's almost an infinite task. Currently Nikola's importer handles a few of the more common. But if you try to import your blog and get less than ideal results, please file a bug and I'll do my best to fix it.

Usually the fixes are rather simple, it's just that I have never seen that specific thing ;-)

Have fun!

2013-03-12 20:09

Standalone Search in Nikola

This has been in the master branch of Nikola for a while but only now have I tried to fully integrate it, and polish all (most) of the rough edges.

By default, Nikola comes with support for search forms using Google and Duckduckgo. Some people disapprove of them for different reasons [1] so there was a request about supporting a standalone search engine.

The best of breed of those things seems to be Tipue so that's what I supported.

To use this, you need to enable a plugin, and do some configuration changes.

The plugin is called task_localsearch and you can find it in the Nikola source tree

Suppose your site is in a folder called mysite then to enable this plugin you need to create mysite/plugins and then copy task_localsearch.plugin and task_localsearch in there.

Then, in your site's conf.py find these options and change them accordingly:

SEARCH_FORM = """
<span class="navbar-form pull-left">
<input type="text" id="tipue_search_input">
</span>"""

ANALYTICS = """
<script type="text/javascript" src="/assets/js/tipuesearch_set.js"></script>
<script type="text/javascript" src="/assets/js/tipuesearch.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('#tipue_search_input').tipuesearch({
        'mode': 'json',
        'contentLocation': '/assets/js/tipuesearch_content.json',
        'showUrl': false
    });
});
</script>
"""

EXTRA_HEAD_DATA = """
<link rel="stylesheet" type="text/css" href="/assets/css/tipuesearch.css">
<div id="tipue_search_content" style="margin-left: auto; margin-right: auto; padding: 20px;"></div>
"""

How does it work? Here's a demo site for you to try!

I would not recommend doing this for a big site, since it may load a multi-megabyte javascript file when you search, but for small to medium sites, it may be ok.

[1] My own reason for disapproving of duckduckgo site search? It finds nothing.

2013-03-05 06:31

Twitter Card Support in Nikola

This feature for Nikola was implemented by @amokleben, and now, if you ask twitter your site can have it too.

What are Twitter Cards? Did you notice that for some sites, when you click on tweets that have links, you get a small preview of the content? Well, that's a twitter card.

This still needs a little improvement to support the richer "media" cards, but it does work:

//ralsina.me/galleries/random/twitter-card.png

Yes, that's a picture of the twitter card for this post. How meta, right?

You don't have to do anything in your site, but setting the "description" metadata to your posts helps make this more accurate (and it also works for google+)

2013-03-04 18:40

Nikola 5.4 is out!

I am thrilled to announce the release of version 5.4 of Nikola, a static site/blog generator

Here's the (incomplete!) changelog for this release [1]:

Features

  • Twitter Card / Open Graph support.
  • Smart math support
  • New soundcould directive
  • Custom "read more" links
  • Better time display, timezone support
  • Better doit integration (Issue #151)
  • Make the whole listings folder browsable (Issue #128)
  • New GZIP_FILES/GZIP_EXTENSIONS options to create gzipped copies of some files (Issue #348)
  • New optional path parameter to new_post command.
  • Wordpress importer: option to not download files
  • Wordpress importer: option to squash newlines
  • Separated BLOG_URL into SITE_URL and BASE_URL
  • Added DISABLED_PLUGINS option (Issue #354)

Bugfixes

  • Added missing </div> in default theme templates.
  • Wordpress import: Description is left empty if no description is found.
  • When running the build command it is now possible to get help.
  • Load jQuery before bootstrap in JS bundle (Issue #327)
  • Generate valid HTML5 for redirects (Issue #276)
  • Fixed "nikola check"
  • Fixed internationalized RSS links
  • Make commands that need to be run in a site fail gracefully (Issue #342)
  • Use localized links on lxml fixer
  • Redirections created during the import from wordpress are now written to conf.py
  • Stop parsing metadata in post file on first blank line
  • Metadata handling cleanups by Tordek
  • Fixed blockquote font size inconsistency
  • Wordpress Import: Do not break indentation (issue #189)
  • Make things work even if SITE_URL has a path (Fix #307)
[1] There are also some extra bits of documentation, and a awesome beta theme called "site-reveal" based on bootstrap and reveal.js!

2013-03-01 12:49

Creating a Site (Not a Blog) with Nikola

One of the most frequent questions I get about Nikola is "but how do I create a site that's not a blog?". And of course, that's because the documentation is heavily blog-oriented. This document will change that ;-)

Since it started, Nikola has had the capabilities to create generic sites. For example, Nikola's own site is a fairly generic one. Let's go step by step on how you can do something like that.

As usual when starting a nikola site, you start with nikola init which creates a empty semi-configured site:

$ nikola init mysite
Created empty site at mysite.

Then we go into the new mysite folder, and make the needed changes in the conf.py configuration file:

##############################################
# Configuration, please edit
##############################################


# Data about this site
BLOG_AUTHOR = "Roberto Alsina"
BLOG_TITLE = "Not a Blog"
# This is the main URL for your site. It will be used
# in a prominent link
SITE_URL = "http://notablog.ralsina.me"
BLOG_EMAIL = "[email protected]"
BLOG_DESCRIPTION = "This is a demo site (not a blog) for Nikola."

#
# Some things in the middle you don't really need to change...
#

post_pages = (
    ("pages/*.txt", "", "story.tmpl", False),
)

And now we are ready to create our first page:

$ nikola new_post -p
Creating New Post
-----------------

Enter title: index
Your post's text is at:  pages/index.txt

Note

The -p option in the nikola new_post command means we are creating a page and not a blog post.

We can now build and preview our site:

$ nikola build
Scanning posts.done!
.  render_site:output/categories/index.html
.  render_sources:output/index.txt
.  render_rss:output/rss.xml
:
:
: [Much more of the same]

$ nikola serve
Serving HTTP on 127.0.0.1 port 8000 ...

And you can see your (very empty) site in http://localhost:8000

So, what's in that pages/index.txt file?

.. title: index
.. slug: index
.. date: 2013/03/01 10:26:17
.. tags:
.. link:
.. description:


Write your post here.

Title is the page title, slug is the name of the generated HTML file (in this case it would be index.html) the date doesn't matter much in not-blogs, same for tags and link. Description is useful for SEO purposes if you care for that.

And below, the content. By default you are expected to use reStructured text but Nikola supports a ton of formats, including Markdown, plain HTML, BBCode, Wiki, and Textile.

So, let's give the page a nicer title, and some fake content. Since the default Nikola theme (called "site") is based on bootstrap you can use anything you like from it:

.. title: Welcome To The Fake Site
.. slug: index
.. date: 2013/03/01 10:26:17
.. tags:
.. link:
.. description: Fake Site version 1, welcome page!


.. class:: hero-unit span6

.. admonition:: This is a Fake Site

    It pretends to be about things, but is really just an example.
    So, don't click this button, it leads nowhere.

    .. class:: btn

    Click Me!


.. class:: span5

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris non nunc turpis.
Phasellus a ullamcorper leo. Sed fringilla dapibus orci eu ornare. Quisque
gravida quam a mi dignissim consequat. Morbi sed iaculis mi. Vivamus ultrices
mattis euismod. Mauris aliquet magna eget mauris volutpat a egestas leo rhoncus.
In hac habitasse platea dictumst. Ut sed mi arcu. Nullam id massa eu orci
convallis accumsan. Nunc faucibus sodales justo ac ornare. In eu congue eros.
Pellentesque iaculis risus urna. Proin est lorem, scelerisque non elementum at,
semper vel velit. Phasellus consectetur orci vel tortor tempus imperdiet. Class
aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos
himenaeos.

[And more in the same vein]

TIP: Nice URLs

If you like your URLs without the ".html" then you want to create folders and put the pages in index.html inside them. Example:

nikola new_post -p pages/foo/index.txt

which will create a page you could access as "http://yoursite.com/foo"

And that's it. You will want to change the SIDEBAR_LINKS option to create a reasonable "menu" for your site, you will want to hack the theme (check nikola help bootswatch_theme for a quick & dirty solution), and you may want to add a blog later on, for company news or whatever.

TIP: So, how do I add a blog now?

First, change the post_pages option like this:

post_pages = (
    ("pages/*.txt", "", "story.tmpl", False),
    ("posts/*.txt", "blog", "post.tmpl", True),
)

And to avoid a conflict (because blogs try to generate /index.html:

INDEX_PATH = "blog"

Create a post with nikola new_post and that's it, you now have a blog in http://yoursite.com/blog (you may want to add links to it in SIDEBAR_LINKS of course).

You can see the finished site in http://notablog.ralsina.me and its full configuration in //ralsina.me/listings/notablog/conf.py.html

I hope this was helpful!

2013-02-25 17:34

Load Testing Nikola

Nikola generates static sites, so load testing it is not very interesting, except as a benchmark for the difference between static and dynamic sites.

Today I was told about blitz.io and since a quick test is free, I thought, why not? The result is quite impressive: a cheap VPS, using gatling as a web server, which is almost configuration-free and not meant for extremely high loads, can handle roughly 9 million daily hits.

Let me say that again: 9 million hits. On a unconfigured $5 server. Here's the report

How much tuning does it take for a wordpress instance to serve that? On what hardware?

And that's only half the picture. Not only are Nikola's static pages incredibly light on your server, we have also spent a lot of effort trying to make individual pages load fast, for a better user experience. Some of the techniques used for fast-loading sites are:

  • Using webassets to bundle CSS and JS into single files.
  • Automatic support for CDNs for the common JS libraries
  • Support for transparently using HTML/CSS/JS/Image compression tools

So, if you try something like YSlow! on a Nikola site, it will give you a score of roughly 93 up to 98 (out of 100) depending on your webserver configuration.

BTW: I really want to get that up to 100. Really want it

So, remember, if your site can be served statically, it's going to be cheaper, faster, safer. And if you ever get 9 million hits a day, it will be available.

Disclaimer:
Blitz.io is sending me a t-shirt ;-)

2013-02-21 17:41

New Nikola Tutorial

Tim van der Linden has written a impressive tutorial about how he used Nikola to create his new site shisaa.jp

It documents the whole process from scratch, starting by downloading Nikola up to building your own theme.

Even if you are already using Nikola you may find some new stuff there, so take a read (also, his theme is so pretty :-)

Contents © 2000-2019 Roberto Alsina