Raging Penguin

The random ramblings of a Linux geek

mobile menu button

Extending BlazeBlogger with custom post footers

2013-03-20 by TuxRag3r, tagged as webdev

Thanks to Jaromir Hradilek’s comments in the blaze-config and blaze-make utilities, I finally managed to add a new feature to BlazeBlogger: custom post footer code!. It is now possible to specify an append file, the contents of which will be added to the bottom of every post. That means you can now add code for Disqus, share buttons, a custom comment form, or just a simple footer.

Up until now, I’ve been manually appending a PHP include shim at the bottom of every post for Disqus. With this relatively simple modification, nobody has to do that anymore. The rest of this post is an explanation of how I did this and how it works. If you just want the files, here they are.

Blaze-config

For this modification, I started with the blaze-config script. In my opinion, this is the most important utility in BlazeBlogger, as the other utilities would be unable to function propperly without it. Around line #60, I found something like this:

# Post related settings:
 'post.author'      => 'top',                      # Post author location.
 'post.date'        => 'top',                      # Post date location.
 'post.tags'        => 'top',                      # Post tags location.

I added the 'post.append' => '', after the 'post.tags' line.

# Post related settings:
 'post.author'      => 'top',  # Post author location.
 'post.date'        => 'top',  # Post date location.
 'post.tags'        => 'top',  # Post tags location.
 'post.append'      => '',     # <--- Custom code

Next I went down to line #276 and added a new variable for ‘append’:

# Prepare the advanced post settings:
  my $post_author    = $conf->{post}->{author}  || $opt{'post.author'};
  my $post_date      = $conf->{post}->{date}    || $opt{'post.date'};
  my $post_tags      = $conf->{post}->{tags}    || $opt{'post.tags'};
  my $post_append    = $conf->{post}->{append}  || $opt{'post.append'}; # <--- New variable

Then I went to line #381 and added the required option and a short description:

##  append         Append custom code from a file to every post. Useful for
##                 comments, share buttons, and more.
[post]
author=$post_author
date=$post_date
tags=$post_tags
append=$post_append # <--- New config option

Blaze-make

The next thing that had to be modified was the blaze-make script, which generates the site. Because I wanted this modificaiton to only affect blog posts, I started at line #1306:

# Generate the blog posts:
sub generate_posts {
  my $data         = shift || die 'Missing argument';

  # Read required data from the configuration:
  my $blog_posts   = $conf->{blog}->{posts}      || 10;

  # Read path to post append file:
  my $append_file  = $conf->{post}->{append}     || '';

Finally, here’s the code that actually does the work, starting at line #1341:

# Set empty append variable
  my $appFile = '';
  
  # If the file exists, write the contents to the append variable
  if (-e $append_file) {
  	open (APPFILE, "$append_file") or return '';
	
	  # Read file to a variable
	  while (my $line = <APPFILE>) {
	  	$appFile .= $line;
	  }

  	# Close the file
  	close(APPFILE);
  }

I may expand on this in the future to support things like ads, Twitter feeds, and tag clouds. For now, it’s back to VECTOR. I’m trying out a new way to define objects in JavaScript!

comments powered by Disqus

Built with Vim, The GIMP, and BlazeBlogger.

Valid HTML5