Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[HOWTO] Set up your own blog with nanoblogger
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
MathFreak
Apprentice
Apprentice


Joined: 07 Jul 2002
Posts: 217
Location: Bethlehem, PA

PostPosted: Wed Jul 06, 2005 2:07 am    Post subject: [HOWTO] Set up your own blog with nanoblogger Reply with quote

Say, do you constantly think of things that are so useless and/or boring, no one you know would want to listen to them? I know I do. So what can you do? Simple, set up your own blog. I'd been wanting to for a while, but was never very happy with the free blog sites such as LiveJournal or Blogspot. I decided to set up my own, but then there was the problem of which software to use. All of the ones I saw were pretty complicated things involving php and mysql. For a lot of people, these are great. For me, though, I wanted something even more lightweight. Then I discovered NanoBlogger in portage. It's just a bash script (well, a set, actually) that generates static html pages. Even better, it's highly configurable with plugins. So, here's a breakdown of nanoblogger:

Pros:

  • Generates static HTML with no PHP or MySQL (by default, that is). This means less load on the server and the possibility for less expensive hosting.
  • Highly configurable
  • Lots of plugins and it's easy to write your own.
  • Supports lots of features such as archives, categories, multiple users, RSS, and more.


Cons:

  • Can really only post from one location.
  • If you're not too familiar with shell scripting, you might have some trouble writing plugins
  • There might be others, but I can't think of any at the moment.


What it does

Now, I haven't studied it extensively, but I think I get the basic operation. First, the blog is stored locally. Second, pretty much everything is done with the "nb" command and some command line switches. "nb" reads from two configuration files

  • /etc/nb.conf or ~/.nb.conf: ~/.nb.conf supersedes /etc/nb.conf
  • $BLOG_DIR/blog.conf


The real use of the nb.conf file is to define the BLOG_DIR variable. There are other things in there, but they could easily be defined in $BLOG_DIR/blog.conf. In fact, you don't even need the nb.conf file. If you always add the command line switch "nb --blog_dir (directory)", you don't need much from nb.conf. But I use ~/.nb.conf so I don't have to keep typing "nb --blog_dir (directory)"

Whenever you add an entry or run "nb --update", nanoblogger will update your blog. It does this by doing some set things, but also by running the scripts in /usr/share/nanoblogger/plugins. These are just shell scripts that may or may not set a different shell variable. These plugins can modify your blog in pretty much any way imaginable. There are different kinds of plugins and I admit I'm not too certain on all of their uses. There is some excellent documentation at the nanoblogger homepage.

And that's pretty much it.

The blog itself will have the directory structure
Code:
$BLOG_DIR
|-- archives     - This stores your archived blog entries
|-- articles     - The default directory to store articles you write
|-- atom.xml     - Atom 0.3 feed generated automatically
|-- blog.conf    - Configuration for the blog
|-- cache        - I admit, I'm not certain what this is for
|-- data         - Stores data, but again, I'm not 100% certain which data
|-- galleries    - Directory for a plugin I wrote
|-- images       - Just a plain old images directory
|-- index.html   - Your blog's main page
|-- index.xml    - Uh, not sure
|-- parts        - Parts, I'll explain this after this code block
|-- recipes      - Directory I added for the articles plugin
|-- rss.xml      - RSS feed automatically generated
|-- styles       - Stores the stylesheets for your blog.
|-- templates    - Stores the templates.  I'll explain this along with parts.
`-- tidy.log

This is actually my blog's directory. It's different because of some customizations I made (coming next post). One of the things plugins do is generate their own html files in the "parts" directory. Nanoblogger then merges them with the templates found in the "templates" directory. It then combines things into your index.html and various other pages it uses.

Installation and Basic Configuration

Now, if you've decided to use nanoblogger, installation is as simple as
Code:
emerge -va nanoblogger
You can use bash-completion if you want, but I use ZSH and don't know how well the completion works.

The main nanoblogger configuration file is /etc/nb.conf. But you can have a per-user one as ~/.nb.conf by doing:
Code:
cp /etc/nb.conf ~/.nb.conf


The nb.conf file is just a bunch of shell variables. The only thing you really need to edit is the BLOG_DIR variable. This is just what it looks like: where your blog is located locally. I'll get to remote hosting in a little while. If you're hosting this on your own server, you can set it to something such as "/home/chris/public_html/blog" or somesuch. Since I use a hosting provider, my .nb.conf has the line:
Code:
BLOG_DIR="/home/chris/docs/blog"


Now for the blogging. Most everything you do will involve running the "nb" command. To start your new blog, just enter the command
Code:
nb -a


This command will copy over a whole bunch of files and then give you the option to configure your blog. You're definitely going to want to configure it. Like the nb.conf file, this is just a bunch of shell variables. All the variables are nicely documented in the config file, but here are a couple important ones you'll want to take a look at.

  • EDITOR: This is just the editor that is used by nanoblogger and commented out by default. Since these are just shell variables, if you leave it commented out nanoblogger will use the system default editor.
  • BROWSER: Which browser you want to preview your blog in.
  • BLOG_CSS: Sets the stylesheet for your blog. There are four by default, and it shouldn't be too tough to make your own.
  • BLOG_{TITLE,DESCRIPTION,AUTHOR}: Three variables that are just what the look like. The blog's title, description (appears just under the title, usually), and author. For author, you just need a name, not an email address.
  • BLOG_CONTACT: This is where you put your email address. This should really be something like <a href="mailto:cgodboutREMOVETHIS@gmail.com">'$BLOG_AUTHOR'</a>. This just gets put directly into the index.html file
  • BLOG_PUBLISH_CMD: What you want nanoblogger to run when you publish your blog. I'm giving this it's own section


There are two variables that I have that you might find useful

  • NB_DATATYPE: This defaults to "txt" and is the default extension that nanoblogger uses for it's files, such as your blog entries, categories, etc. Leaving it as txt is just fine. However, your blog entries are just html files (minus <html>,<head>, and <body> tags) that get inserted into the blog. Since I use vim, I wanted syntax highlighting, auto-indenting, etc. so changing the variable to "html" lets vim know I'm working with html and set the options accordingly.
  • ARTICLE_SUFFIX: Same thing as NB_DATATYPE, but for articles (more on this in the plugins section). Defaults to "txt", but changing to "html" lets you use syntax highlighting, etc.


Remote Hosting
So you're like me and don't have the bandwidth to host your own blog. To host it somewhere else, you'll want to set the BLOG_PUBLISH_CMD variable to the command you want nanoblogger to run either after adding a new entry or typing
Code:
nb --publish


I use rsync over SSH since my hosting allows that, so here's what I have:
Code:
BLOG_PUBLISH_CMD="rsync -avze ssh /home/chris/docs/blog/* mathfrk@mathfreak.ws:/home/mathfrk/public_html"


That's really all there is to it. The nanoblogger documentation has a part about using ftp to publish, but I don't think plain old ftp has an option for recursing directories. You should be able to use something like ncftpput, though.

There, your blog is now set up. Let's actually do something.

Basic Usage
First thing you might want to do is add an entry. This is as simple as typing
Code:
nb --add

This will first ask you for some basic info such as author and tile and then launch your favorite editor (chosen by the EDITOR variable). From here you just type an entry. This file is just an html file, so put whatever you want in there. When you're done, just quit the editor and let nanoblogger do its thing.

Uh-oh, you made a mistake. You'll want to edit that. To do this, first type
Code:
nb --list

This give you a list of all the entries. Let's say you want to edit entry 5. To do this, just type
Code:
nb --edit 5

This will simply launch your editor and give you a file that looks like
Code:
TITLE: blah
AUTHOR: Joe Schmoe
DATE: <date here>
DESC: Description
-----
BODY:
Blog entry here
-----
You'll really only want to edit the BODY part. This is the entry itself.

Well, now you realized that you shouldn't have posted angry/drunk/whatever and want to take down that article entirely. Simply get the article id, again using 5 as an example, and type
Code:
nb --delete 5


That's pretty much everything you need to blog, but let's add some categories to make navigation easier for your reader(s). Since you have no categories right now, type
Code:
nb --category new --add


This will ask you for a category name and then add it. To see the categories you have, type
Code:
nb --list cat


To add a new post to a specific category, say with id 3, type
Code:
nb --category 3 --add


Say you already posted before adding the category. No problem, just type
Code:
nb --category 3 --move 5
Since you have no categories right now, type
Code:
nb --category new --add


This will ask you for a category name and then add it. To see the categories you have, type
Code:
nb --list cat


To add a new post to a specific category, say with id 3, type
Code:
nb --category 3 --add


Say you already posted before adding the category. No problem, just type
Code:
nb --category 3 --move 5
Since you have no categories right now, type
Code:
nb --category new --add


This will ask you for a category name and then add it. To see the categories you have, type
Code:
nb --list cat


To add a new post to a specific category, say with id 3, type
Code:
nb --category 3 --add


Say you already posted before adding the category. No problem, just type
Code:
nb --category 3 --move 5
Since you have no categories right now, type
Code:
nb --category new --add


This will ask you for a category name and then add it. To see the categories you have, type
Code:
nb --list cat


To add a new post to a specific category, say category with id 3 or to multiple categories, type
Code:
nb --category 3 --add
nb --category 3,4,7 --add


Say you already posted before adding the category. No problem, just type
Code:
nb --category 3 --move 5


Just realized that your quick review of the latest issue of the Astonishing X-Men (entry id 7) doesn't belong in the category about fishing tackle (category id 1)?
Code:
nb --category 1 --delete 7


Showing your blog to your significant other and don't want a category titled "People Hotter Than My S.O."? You can either delete or rename it
Code:
nb --category 1 --delete cat #delete it, but not the articles in it
nb --category 1 --title "People Not Nearly As Hot As My S.O." --edit cat #change the title to something your s.o. will never suspect


And that's really all there is to the basics of nanoblogger. I hope. Let me know if anything doesn't work out right. See the next post for creamy plugin goodness.
_________________
"You probably wouldn't worry about what people think of you if you could know how seldom they do."
-Olin Miller
Back to top
View user's profile Send private message
MathFreak
Apprentice
Apprentice


Joined: 07 Jul 2002
Posts: 217
Location: Bethlehem, PA

PostPosted: Wed Jul 06, 2005 2:08 am    Post subject: Reply with quote

Plugins

Here is where nanoblogger rocks. In theory, there's really no limit to what you can do with your blog thanks to plugins. The only ones I know much about reside in /usr/share/nanoblogger/plugins/. These plugins are run every time nanoblogger is run. Usually, the generate html files and return them as shell variables which nanoblogger inserts into your blog.

Fortune Plugin
This is the most basic plugin and easiest to understand. Here it is in its entirety:
Code:
# NanoBlogger Fortune plugin, requires the fortune program.

# sample code for templates, based off default stylesheet
#
# <div class="sidetitle">
# Random Fortune
# </div>
#
# <div class="side">
# $NB_Fortune
# </div>

# Fortune command, use "-s" for short fortunes
: ${FORTUNE_CMD:=fortune -s}

PLUGIN_OUTFILE="$BLOG_DIR/$PARTS_DIR/fortune.$NB_FILETYPE"

if $FORTUNE_CMD > "$PLUGIN_OUTFILE" 2>&1; then
   nb_msg "generating fortune ..."
   echo '<div class="fortune">' > "$PLUGIN_OUTFILE"
   $FORTUNE_CMD ${FORTUNE_FILE} \
      |sed -e '/[\<]/ s//\</g; /[\>]/ s//\>/g; /^$/ s//<br \/>/g; /$/ s//<br \/>/g; /[\$]/ s//\\$/g' \
      >> "$PLUGIN_OUTFILE"
   echo '</div>' >> "$PLUGIN_OUTFILE"
   NB_Fortune=$(< "$PLUGIN_OUTFILE")
fi


First, thing you see are the comments. They give you the default method for inserting a random fortune. This you'll want to put into $BLOG_DIR/templates/main.htm somewhere. In that file, there are two main <div> sections, content and links. Content is where your blog entries go, links is that thingamajig that goes down the side. If they use this, most people would put the two html chunks given directly into the links secion. I like big quotes, so I put mine in the content section.


Next we get to the code. Everything in capital letters is a shell variable. Every one of them in this plugin can be overridden by the blog.conf configuration file. For instance,
Code:
: ${FORTUNE_CMD:=fortune -s}

If you don't do much shell scripting, this just gives a default command to run for the fortune plugin. If you don't have "FORTUNE_COMMAND=something" in your blog.conf, the plugin will run "fortune -s".

Next we have PLUGIN_OUTFILE. This is just a temporary file for fortune to work with. As you can see, all that really happens here is the fortune command is run and piped to a temporary file. Then it formats it and stores it in the variable NB_Fortune. Putting $NB_Fortune anywhere in a template will cause this html code to be inserted.

Articles Plugin

This is much more complicated than the fortune plugin, and much more useful. This plugin is /usr/share/nanoblogger/plugins/zyx_articles.sh What this does, is take files in the articles directory, turns them into nice, matching html files, and makes an index for the front page. While the script itself is complicated, you control it with really just three variables
Code:
:${ARTICLE_DIRS:=articles}
: ${ARTICLE_SUFFIX:=txt}
: ${ARTICLE_TEMPLATE:=$NB_TEMPLATE_DIR/makepage.htm}


ARTICLES_DIRS is a space delimited list of directories. What the plugin does is go into each directory in ARTICLES_DIRS under BLOG_DIR and then go through each file in that directory ending in ARTICLE_SUFFIX. It throws it into the template selected by ARTICLE_TEMPLATE and makes its own little directoy under BLOG_DIR/ARTICLE_DIRS. Then you just put the following into make_index.htm
Code:
<div class="side">
$NB_Article_Links
</div>


The name of the files the plugin reads is something.ARTICLE_SUFFIX. The first line in that file is the title of the article. This gets converted in its own way. The second line on is just html. Like your blog entries, do whatever you want.

Now, you can see from my directory listing (way up in the previous post) that I have another article directory called recipes. My blog.conf has the lines
Code:
ARTICLE_SUFFIX="html"
ARTICLE_DIRS="articles recipes"


So, the plugin generates articles under each directory and that one bit of code from above is all I need in main_index.htm to generate an index that separates my regular articles from my recipes.

Photo Gallery Plugin

Okay, here's where I pimp my own plugin. I just wrote it. What it does is generate image galleries given a simple text file. First, you make a directory called galleries under BLOG_DIR. Then, for each gallery, you make a simple text file with the extension.txt that contains the following format:
Code:
<Image Location>, [Caption]


Image location is the image you want, but it has to be a local file. Caption is just the caption you want. It returns the variable NB_GalleryLinks which you just throw into the sidebar like so:
Code:
<div class="sidetitle">
    Galleries
</div>
<div class="side">
    $NB_GalleryLinks
</div>


It requires ImageMagick to make thumbnails, a template that can be changed, and a modified style file (I use nb_clean.css), all of which can be found here. It's still in it's very rough stages, but if you decide to use nanoblogger, consider giving this guy a whirl and see if you can help me make it better.

Comments Plugin
Yes, that's right, you can do comments with nanoblogger using the plugin found here. However, it requires MySQL 4.1 and my hosting only has 4.0. I also don't really care about comments, so I probably won't even try it. But they're there. So, I don't really have anything else to say about it.

Fin

Well, that's all I can think of to post. Which probably makes you, the reader, quite happy. I hope you enjoyed this, or at the very least, could follow it. A little. Any suggestions or comments, please let me know. Before starting on nanoblogger (about a week ago) I hadn't done any html or css and very little shell scripting, so there are probably problems with quite a bit of my work.

And before I forget, I guess I could pimp my blog as well. It's at http://mathfreak.ws
_________________
"You probably wouldn't worry about what people think of you if you could know how seldom they do."
-Olin Miller
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum