Home Archive About

This site is a slowly evolving proof-of-concept to show how txt2tags can be used as a general purpose blogging engine.

How to create multi-page sites

Wed 17 Oct 2007 05:36:10 PM BST

Having everything on one page is good if you're not expecting to make many blogposts, but any sensible site needs a way to grow as time passes. By adding just a little more txt2tags magic to the site, it's possible to put together a site which is easy to extend on the fly. Here's how.

First of all, we're going to simplify the makeblog script by using a config file to store our site preferences. Create a .conf file as follows. I've called mine txt2blog.conf:

  %!target: html
  %!options: --css-sugar
  %!options: --style=modern.css
  %!options: --mask-email

This sets the target as html with a preferred style-sheet. I've also added the option to mask any email addresses from spam harvesters - always a nice touch.

All of this means that the makeblog scripts can be simplfied to:

  #!/bin/bash
  txt2tags -C txt2blog.conf *.t2t
  scp * greywulf@greywulf.net:~/greywulf.net/txt2blog/

This takes every file which ends with .t2t in the directory, applies the config file and spits out the formatted .html. Finally, it copies everything (including a backup of the .t2t files, of course) up to the server. Adjust to suit your needs.

Next, create a header.t2t file which contains anything you want you include on every page. This might be a link bar, image, mission statement ofr whatever. For example, here's mine:

| [Home index.html] | [Archive archive.html] | [About about.html] 

This site is a slowly evolving proof-of-concept to show how 
[txt2tags http://txt2tags.sourceforge.net] can be used as a general 
purpose blogging engine.

To create a new page, just add it to the link bar in your header.t2t, and create the page with the site-title, your name, copyright and an instruction to include the header.t2t in the page, and you're all set. For this site, it looks like this:

txt2blog
Robin V. Stacey :: greywulf (at) gmail.com
(c) Creative Commons Attribution ShareAlike 2007

%!include: header.t2t

Amend your existing pages to include header.t2t just once, and any future changes to header.t2t will automatically be pulled in when new pages are added.

Ideally, I'd like to be able to add the site title, etc to the header.t2t too so it's only referenced once, but txt2tags requires that these three lines appear at the top of the source file. Maybe it's possible through clever use of the preproc config option.

Thoughts?

Add Comment (Opens mail window. Comments are moderated.)

Coming soon.......

Wed 17 Oct 2007 03:00:27 PM BST

Here's the plan for txt2blog now that we've got the basic proof of concept in place:

At it stands, txt2tags holds up well against a simple, dedicated blogging engine like blosxom. It can be much, much more though. Let's see just how far we can push this puppy!

Add Comment (Opens mail window. Comments are moderated.)

Blogging with txt2tags

Mon 15 Oct 2007 09:30:17 PM BST

txt2tags is a small (485k download) command-line application for Linux and similar Operating Systems. It takes any text file with a bare minimum of markup and converts it into a beautifully formatted document in any of several formats, including html, pdf, TeX and Pagemaker - all from the same source. This is perfect if you want to provide a document in several formats with the minimum of effort, or want to create pdfs without needing a resource-heavy word processor.

For the purposes of blogging though, the main goal is to take a text file, use txt2tags to convert it to html and upload it to the server.

There are several advantages to using txt2tags as your blogging engine of choice:

Of course, there are a few downsides, most notably the lack of rss, searching and tags. These can easily added however; I'll save that particular trick for a future blogpost though. Let's keep things simple for now :)

So, can it be done? Obviously, as you are reading this, it can. This entire site was created using txt2tags and any old text editor. Even the stylesheet is the example modern.css provided with the txt2tags package, and can easily be customized to taste.

First, you need a template for your blog. Here's the one for this site:

txt2blog
Robin V. Stacey :: greywulf (at) gmail.com
(c) Creative Commons Attribution ShareAlike 2007

| [Home index.html] | [Archive archive.html] | [About about.html] 

= First Post! = 
//Put the date here// 

**Hello world**! Replace this text, and start //blogging//.

[Add Comment mailto:greywulf@gmail.com] (Opens mail window. Comments are moderated.)

Just download and install txt2tags copy and paste the text above into a new file called yoursitename.t2t (or whatever), and you're all set.

Here's how it works. The first line is the name of your site. The second is your name and contact information and the third (usually reserved in txt2tags for the publication date) is the copyright notice. Adjust to suit. The fourth line is optional. It puts a row of links to other pages on the site. Remove this if you want one (potentially very long) blog, or set to your preference.

After that, everything else is blog.

A blogpost has a title surrounded by single = marks. Underneath, add the date. Text is just plain text with blank lines to denote paragraphs. Use square brackets to create links (for example, [Home txt2blog.html] gives Home), and surround the text with double asterisks (**like this**) and double slashes (//like this//) for bold and italic. To post images, surround the filename with square brackets like this: [hotrod1.jpg].

Put the image directly before a paragraph on the same line and it will align with it. If you need more than this, check the txt2tags documentation.

If you want comments (and who doesn't?), copy and paste the following line underneath each post, replacing the email address:

  [Add Comment mailto:greywulf@gmail.com] (Opens mail window. Comments are moderated.)

When you receive a comment, just add it to the text in the correct location.

Each time you want to make a new post, just start a new entry at the top of the .t2t file. When you reach around 10 posts, consider moving the bottom items into an archive.t2t file to keep the main page a sensible size.

Finally, copy the modern.css file from /usr/share/doc/txt2tags/examples/css into the same location as your blog. This controls the page layout, so adjust as required.

Use txt2tags to make the .html file and copy it to the server. The following script, called makeblog, handles all this by generating the html page with modern.css specified, then using scp to upload to files. Remember to replace my details with yours!

  #!/bin/bash
  txt2tags -t html -o index.html --css-sugar --style=modern.css txt2blog.t2t

  # If you're using an archive, uncomment the next line to have it updated as well.
  # txt2tags -t html -o archive.html --css-sugar --style=modern.css archive.t2t
  #
  # .... add extra pages as required.

  scp * greywulf@greywulf.net:~/greywulf.net/txt2blog/

There you have it. A blog, using txt2tags. Clever, eh?

If you use this, please send me a comment!

Add Comment (Opens mail window. Comments are moderated.)