Pelican

Now how did I miss Pelican in my quest for the perfect static blog generator? Maybe because it’s not perfect either but  certainly deserves to be ranked alongside Jekyll and Punch. Since it’s written in Python, which means my religious beliefs are not offended.

When trying to import my blog into one of the static generators, the output from WP to jekyll exporter has always been the input. So that same thing was tried with Pelican but it didn’t work out too well. The issue seemed trivial however.  Pelican doesn’t like the YAML front matter block in each post. Before trying to create a regext to eliminate it,  I looked around for options and was quite pleased to find that pelican can import directly from WordPress as long as you have something called pandoc installed. Absolutely kicking myself for not knowing about pandoc till now. It looks like a really useful tool.

However the importer had it’s fair share of problems producing errors like these:

/home/raditha/django/pelican/content/the-colombo-fort-stolen.rst:41: (WARNING/2) malformed substitution definition.
/home/raditha/django/pelican/content/the-colombo-fort-stolen.rst:42: (WARNING/2) Explicit markup ends without a blank line; unexpected unindent.
/home/raditha/django/pelican/content/the-colombo-fort-stolen.rst:42: (ERROR/3) Undefined substitution referenced: "image2".
/home/raditha/django/pelican/content/the-colombo-fort-stolen.rst:42: (ERROR/3) Undefined substitution referenced: "image3".
/home/raditha/django/pelican/content/the-colombo-fort-stolen.rst:8: (ERROR/3) Unknown target name: "|colombo|".
/home/raditha/django/pelican/content/the-colombo-fort-stolen.rst:31: (ERROR/3) Unknown target name: "|government ad with stolen photo|".

The importer produces reStructuredText and putting that through the generator resulted in weird stuff popping up all over the place in the HTML like this:

System Message: ERROR/3 (/home/raditha/django/pelican/content/the-giant-tea-boiler.rst, line 29); backlink

Undefined substitution referenced: "image1".

System Message: ERROR/3 (/home/raditha/django/pelican/content/the-giant-tea-boiler.rst, line 8); backlink

Unknown target name: "|giant tea boiler at devon|".
System Message: ERROR/3 (/home/raditha/django/pelican/content/the-giant-tea-boiler.rst, line 14); backlink

Unknown target name: "picture of the modern variant".

The default format used by pelican-importer is rst but it has the capability to produce markdown as well. Quite interestingly, make html produced no errors at all for the markdown version. Where as rst produced at least one error or warning for each post (more than 200 in total in the blog being imported). The markdown version had only these two errors plus three warnings

ERROR: Skipping /home/raditha/django/pelican/content/dew-on-flower.md: impossible to find informations about'date'
ERROR: Skipping /home/raditha/django/pelican/content/pruned.md: impossible to find informations about'date'
A screen shot with the default template

Using the default template, can you see the weird characters?

But it’s too early to celebrate, there are still a few strange [ and ] characters scattered all over the HTML. It looks like the markdown produced by the pelican-importer has it’s own share or problems though no errors are reported.

Feb 13th, 2013 | Filed under Uncategorized

The trouble with mynt

Even though I resolved to move away from wordpress late December, here I am typing yet another post into wordpress’s all too familiar textbox. This is not the first time that I promised myself to ditch WP but this definitely will be the last. The reason that I am still stuck here is not for the want of effort.

After a long journey fraught with pitfalls, during which I looked at many different static blog generators ranging from Punch to Jekyll, I settled on Mynt. It’s pitfalls were craftily hidden. The first problem is that mynt does not allow you to use the archive in anything other than the archive template. What the heck exactly does that mean? Well, can you see the archives side bar on the right hand side? that sort of thing is generated using the archive object in mynt. The trouble is that an individual post template does not have access to that object.

A temporary solution to the problem was to copy paste the html from the existing sidebar into the template, yes, that is hard coding, yes it will have to be manually edited once a month, and after a couple of months, I am going to tire of it completely. Even so I used this approach so that I can try to move forward, but after a few steps, I was in deeper. The new problem is that you cannot easily generate a monthly archive with mynt. It’s capabilities are limited to generating yearly archives only.

Feb 12th, 2013 | Filed under Uncategorized

Being found out.

The most under reported event of the year is the attack by Iranian hackers on nic.lk using an SQL injection. It shouldn’t even be called hack because the security loop hole that was exploited was as big as a football field. They had an opportunity to cause some pretty serious damage but it seems like they were satisfied with taking a database dump of all the .lk domain names and placing it online. That lead to an epic tumbler post by Rukshan

Road.LK and Traffic.LK – Something I wanted to know for a long time, who owns this ;)

        <row>
		<d_domain>road.lk</d_domain>
		<d_admincont>Raditha Dissanayake</d_admincont>
		<d_aemail>[email protected]</d_aemail>
	</row>
        <row>
		<d_domain>traffic.lk</d_domain>
		<d_admincont>Raditha Dissanayake</d_admincont>
		<d_aemail>[email protected]</d_aemail>
	</row>

Yes, folks, i am the owner of the road.lk and traffic.lk domains. Thanks Ruckshan for mentioning us on the same page as Apple and Google. My being a founder of road.lk was never meant to be a secret but I didn’t make a public announcement about it either.  I had spoken with a few friends before the project started and they knew about it prior to the launch. Many of the active users in my rather short friend list on Facebook probably guessed it too. On those rare occasions when  someone asked me whether I do in fact own the domain, I quite readily said yes.

The reason that I have not gone public with this information is that I am a hermit and very shy of publicity. I haven’t had my name featured in any print media since I gave up playing chess many years ago. But now I have been outed, and I guess it’s time for me to start talking a lot more about road.lk. For a shy guy, once I start talking, it’s rather difficult to make me stop.

 

 

Feb 5th, 2013 | Filed under Uncategorized

mynt

The hell with Jekyll and Hyde and Cactus. There is something far better. Too bad they couldn’t pick a cool name for it. It’s called mynt. From what I have seen of it so far, the only thing that sucks about it is the name.

None of the big names mentioned above worked out of the box when used with the dump of my photo blog’s posts. The dump was generated with the WP to Jekyll exporter. Mynt on the other hand had no problems and even processed the whole set of files rather quickly without any complaints.

Another plus point is that that their template language is Jinja which is an even more powerfull system than the default template engine for  Django. Now after a lengthy delay, I am finally one step closer to getting rid of WordPress.

Jan 26th, 2013 | Filed under Uncategorized

django.template.base.TemplateSyntaxError: ‘block’ tag takes only one argument

Update Feb 16: If you came looking for a solution to a template error in the title;  see this link for the solution. This post is about static blog generators.

Still blogging with wordpress despite my repeated assurances that I am moving away from it. This time my excuse is the error message in the title. In the previous post, we talked about Cactus, Volt and Cactus blog. That discussion was left off with a character encoding error.

UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe2 in position 772: ordinal not in range(128). — Note: Markdown only accepts unicode input!

This is becuase “Python-Markdown expects Unicode as input (although a simple ASCII string may work) and returns output as Unicode.” (python markdown docs). Less said about unicode support in PHP 5 and wordpress the better. So let’s talk about adapting our input. That can be managed by a slight mod to the markdown.py file. Here is the diff:

4d3
< import codecs
28d26
<       print path
31,34c29,30
<       with codecs.open(path, mode="r", encoding="utf-8") as f:
<          
<          text = f.read()
<          html = md.convert(text) --- >               with open(path, 'r') as f:
>                       html = md.convert(f.read())
43,44c39
<         
<       with codecs.open(outPath, "w", encoding="utf-8", errors="xmlcharrefreplace") as f: --- >               with open(outPath, 'w') as f:
47c42,44
<             '\n'.join(metadata),"","", --- >                               '\n'.join(metadata),
>                               md.Meta['extends'][0],
>                               md.Meta['block'][0],
52c49
<       md.reset(); --- >

The diff is against the 18131bc2d3b03ca8ace59ec3f7ae43e8073439e3 commit. This took me a few steps forward. And then:

Traceback (most recent call last):
  File "/usr/local/bin/cactus", line 9, in 
    load_entry_point('Cactus==2.1.3', 'console_scripts', 'cactus')()
  File "/usr/local/lib/python2.7/dist-packages/cactus/cli.py", line 75, in main
    build(os.getcwd())
  File "/usr/local/lib/python2.7/dist-packages/cactus/cli.py", line 28, in build
    site.build()
  File "/usr/local/lib/python2.7/dist-packages/cactus/site.py", line 128, in build
    multiMap(lambda p: p.build(), self.pages())
  File "/usr/local/lib/python2.7/dist-packages/cactus/site.py", line 128, in 
    multiMap(lambda p: p.build(), self.pages())
  File "/usr/local/lib/python2.7/dist-packages/cactus/page.py", line 75, in build
    data = self.render()
  File "/usr/local/lib/python2.7/dist-packages/cactus/page.py", line 67, in render
    return Template(data).render(context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 125, in __init__
    self.nodelist = compile_string(template_string, origin)
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 153, in compile_string
    return parser.parse()
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 267, in parse
    compiled_result = compile_func(self, token)
  File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 214, in do_extends
    nodelist = parser.parse()
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 267, in parse
    compiled_result = compile_func(self, token)
  File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 179, in do_block
    raise TemplateSyntaxError("'%s' tag takes only one argument" % bits[0])
django.template.base.TemplateSyntaxError: 'block' tag takes only one argument

Oh well.

Jan 19th, 2013 | Filed under Uncategorized

Cactus Volt

After Punching  Jekyll and Hyde, it was time to look at alternative static blog generator. Something that I came across in the process is Cactus. It looks rather promising, unfortunately as with many open source projects the documentation is somewhat scarce. Still for all this is python which means I can dig through the code, or so I thought until I ran across this curious error in markdown:

UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe2 in position 772: ordinal not in range(128). — Note: Markdown only accepts unicode input!

I know there is nothing wrong with the markdown because the same file was processed without any glitches by Jekyll. Al that the offending line in the markdown plugin does is:

html = md.convert(f.read())

Seriously?

Next up I tried volt and predictably encountered another issue with the markdown. This time the complaint is that the time attribute is missing from the front matter. The input in both cases is the same set of files from the wordpress export. The export was created with the wordpress to jekyll exporter .

 

Update feb 17: I returned to Volt on feb 17, tried to process the markdown files produced by exitwp, volt still chokes on it.

Jan 6th, 2013 | Filed under Uncategorized

Jekyll and Hyde (and punch)

Does Jekyll power this blog now  the like I promised it would? short answer is I am working on it. The long answer is below.

Jekyll is easy to install and get started by to go beyond an absolute bear bones site or blog you need plugins. Plenty of plugins. As with any good open source eco system, there  is always more than one plugin that does the same thing. The trouble is to figure out which one is the best for the task at hand. Ever been to a restaurant where you couldn’t decide what to order because the menu had far too many choices in it? So you end up asking the waiter to recommend something which turns out to be just awful?

Now this is the very thing with WordPress. Whenever you want wordpress to behave differently from the default (and the default is unusable), there is no choice but to download a plugin. The alternative, editing the spaghetti code is the stuff of nightmares. So messing with too many plugins is something I would rather avoid whether it’s WordPress or Jekyll.

So in spite of my aversion to Node.js I decided to give Punch a try. Installation was a piece of cake and same could be said about setting up a simple site, but here is the catch, the default template system is Mustache, which I don’t like. I want something that supports a little bit of logic. Now to look elsewhere maybe Hyde. Now I hasten to add that there is nothing wrong with Punch, it’s just Node.js and Mustache that goes against my religion.

There is a lot  of confusion over Hyde because there are two projects named Hyde by the same user on github. When you are reading a blog post or article on Hyde, you are never quite sure which version they are talking about. Even the most recent project ‘githyb/hyde/hyde‘, hasn’t been updated in nearly a year.  A project that has not been recently updated is that way because it’s either extremely stable and feature complete or abandoned.

 

Jan 2nd, 2013 | Filed under Uncategorized

Goodbye wordpress (this time for real) – Hello Jekyll

The last post on this blog is from Aug 2012. Schedule pressure played a large part in my not writing anything since then is lack of time. The other reason is being sick and tired of WordPress. Each time you login to WordPress there is at least one plugin that needs updating. The template now looks really old but changing it is a real pain.

This is not the first time I have been complaining about WordPress but it will be the last because the blog will be moved to Jekyll soon. Lakshan suggested that move long ago. He made the switch in November and wrote an excellent piece about it. He describes the whole static site to CMS to static sites cycle pretty well.  (please note my comment from nov 2011 on that post)

Not satisfied with Jekyll, laktek has moved onto Punch, a system that he himself wrote and one that has become quite popular (starred by 572 on Github at the time of writing). I will probably stick to Jekyll for the moment because of my aversion to Node.js, but let’s get started.

 

Dec 26th, 2012 | Filed under Uncategorized