Skip to main content

Ralsina.Me — Roberto Alsina's website

Posts about nikola (old posts, page 4)

A Simple Nikola Link Checker

One of the most im­por­tant things when you are build­ing a stat­ic site gen­er­a­tor like Niko­la is that your site should not be bro­ken. So, I re­al­ly should have done this ear­li­er ;-)

This is a very sim­ple link check­er that en­sures the pages Niko­la gen­er­ates have no bro­ken links. I will make it part of Niko­la prop­er once it's more pol­ished and doit sup­ports get­ting a list of tar­gets

To try it, get it and run it from the same place where you have your conf.py, right after you run doit.

import os
import urllib
from urlparse import urlparse

import lxml.html

def analyze(filename):
    try:
        # Use LXML to parse the HTML
        d = lxml.html.fromstring(open(filename).read())
        for l in d.iterlinks():
            # Get the target link
            target = l[0].attrib[l[1]]
            if target == "#":  # These are always valid
                continue
            parsed = urlparse(target)
            # We only handle relative links.
            # TODO: check if the URL points to inside the generated
            # site and check it anyway
            if parsed.scheme:
                continue
            # Ignore the fragment, since the link will still work
            # TODO: check that the fragment is valid
            if parsed.fragment:
                target = target.split('#')[0]
            # Calculate what file or folder this points to
            target_filename = os.path.abspath(
                os.path.join(os.path.dirname(filename), urllib.unquote(target)))
            # Check if it exists, or report it
            if not os.path.exists(target_filename):
                print "In %s broken link: " % filename, target
    except Exception as exc:
        # Something bad happened, report
        print "Error with:", filename, exc

# This is hackish: we use doit to get a list of all
# generated files. Minor modifications would let you check
# the non-generated files as well.

for task in os.popen('doit list --all', 'r').readlines():
    task = task.strip()
    if task.split(':')[0] in (
        'render_tags',
        'render_archive',
        'render_galleries',
        'render_indexes',
        'render_pages',
        'render_site') and '.html' in task:
            # It looks like a generated HTML file
            analyze(task.split(":")[-1])

Nikola 3.0.1 Available for Testing

Ver­sion 3.0.1 of Niko­la my stat­ic site gen­er­a­tor is ready for ini­tial us­er test­ing.

I have merged a bunch of patch­es from Kay Hayen and Kade­for:

  • dis­­qus_de­vel­op­er is gone

  • ad­dthis but­­tons are op­­tion­al (con­trolled by a new op­­tion)

  • You can have more than one stat­ic files fold­er to be merged in­­­to out­­put.

  • Im­age gal­­leries sup­­port up­­per­­case ex­ten­­sion­s.

  • Tem­­plates can not link to CSS that is em­p­­ty/mis­s­ing

  • Bet­ter Google Sitemaps

  • Pre­serve (some) meta­­da­­ta when copy­­ing files, like time­s­tamps

  • Don't over­write ex­ist­ing posts with doit new_­­post

  • Gen­er­ate valid URLs from uni­­code ti­­tles

So, if you want to try it out:

http­s://github.­com/ralsi­na/niko­la/zip­bal­l/3.0.1

I will make it a re­al re­lease if noth­ing bad shows up be­fore sun­day or mon­day.

Now that's a nice theme.

I have been flood­ed by awe­some patch­es for Niko­la by dif­fer­ent con­trib­u­tors, so there will be a new re­lease very soon. In the mean­time, see what hap­pens if some­one with de­sign skills does a theme for it:

//ralsina.me/galleries/random/k4y.thumbnail.png

The au­thor says he's pol­ish­ing it and will be done in a few days.

Nikola is FAST.

A fast-load­ing site is a good thing. Your site's speed mat­ter­s. Which is why cre­at­ing fast sites is one of Niko­la's de­sign goals.

Sure, it's not meant to cre­ate e-­com­merce sites, but if you are do­ing just a sim­ple cor­po­rate site, or a per­son­al blog, why would you not make it as fast as pos­si­ble any­way?

So, here's one da­ta point, from Kay Hayen

http://www.nuitka.net/posts/images/nikola-speed-improvements.png

Guess when Kay switched to Niko­la.

But you don't have to just be­lieve that graph. Here's Ya­hoo's YS­low re­port on this blog, which is host­ed in a $5 VPS (as are oth­er sites, BTW. The same VP­S. As is a bunch of ser­vices. And my Quas­sel core)

http://ubuntuone.com/6Xsg1blhiJK7nEcnhPFOM7

It scores 94 on that test. That's 94 out of 100 pos­si­ble points in the "S­mall Site or Blog" rule­set.

How much serv­er tun­ing was need­ed? I added one line to the Apache con­fig:

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css

That makes it com­press those files be­fore send­ing it to the us­er and im­proved the third item from F to A.

So, when I say Niko­la makes your site fast, don't take my word for it, just check it out.

Nikola 3 is out and it is good.

I just re­leased ver­sion 3 of my stat­ic site gen­er­a­tor, Niko­la

It's a ma­jor re­lease, there is hard­ly any code from the pre­vi­ous ver­sion that was not moved, prod­ded, bro­ken or fixed!

The main fea­tures of Niko­la:

  • Blogs, with tags, feed­s, archives, com­­ments, etc.

  • Themable

  • Fast build­s, thanks to doit

  • Flex­i­ble

  • Small code­base (pro­­gram­mers can un­der­­s­tand all of Niko­la in a few hours)

  • re­Struc­­tured­­Text and Mark­­down as in­­put lan­guages

  • Easy im­age gal­­leries (just drop files in a fold­er!)

  • Syn­­tax high­­­light­ing for al­­most any pro­­gram­ming lan­guage or markup

  • Mul­ti­lin­gual sites

  • Does­n't rein­vent wheel­s, lev­er­ages ex­ist­ing tool­s.

Changes for this re­lease (not ex­haus­tive!):

  • New op­­tion­al tem­­plate ar­gu­­ment for "niko­la init"

  • New "in­stal­l_the­me" task

  • Op­­tion­al ad­­dress op­­tion for the "serve" task

  • Bet­ter look­ing code­blocks

  • Rus­sian tran­s­la­­tion

  • Use mark­­down/reSt com­pil­er based on post ex­ten­­sion

  • Don't fail when there are no post­s/s­­to­ries/­­gal­­leries/­­tags

  • Use con­­fig­u­ra­­tion op­­tions as de­pen­­den­­cies

  • Use more rel­a­­tive links for eas­i­er site rel­lo­ca­­tion

  • Syn­­tax high­­­light for mark­­down

  • Bet­ter mul­ti­­core builds (make the -n 2 or -n 4 op­­tions work)

  • Con­­fig­urable out­­put fold­er

  • Don't fail on posts with pe­ri­ods in the name

  • Dif­fer­­ent page names for dif­fer­­ent lan­guages

  • Rec­og­nize (some) Mako tem­­plate de­pen­­den­­cies

  • Is now a more "nor­­mal" python pack­­age.


Contents © 2000-2024 Roberto Alsina