[sitegen] / buildsite Repository:
ViewVC logotype

View of /buildsite

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (download) (annotate)
Sun Jul 2 03:28:19 2006 UTC (3 years, 4 months ago) by synack
File size: 3736 byte(s)
Initial import
#!/bin/sh
# buildsite - Builds a static XHTML blog out of flat text files using basic UNIX
#             scripting facilities
# Copyright (C) 2006 Jeremy Grosser
# See LICENSE file in the root of the source distribution for details

# Location of the output directory
sitedir="../public_html"

# Build individual entry pages
for entry in entries/*.txt; do
	# Figure out what number this is
	let num=`echo $entry | sed -e "s/.txt//g" -e "s/entries\///g" -e "s/^0//g"`

	# Don't regenerate all the entry pages... Update this occasionally
	if [ $num -gt 78 ]; then
		pagename="entry$num"
		echo "Building $pagename.html"
		rm -f $sitedir/$pagename.html

		# Start with a page header
		cat resources/header.lres >> $sitedir/$pagename.html

		# Pull the metadata out of the entry file
		date="`cat $entry | head -n1`"
		subject="`cat $entry | head -n2 | tail -n1`"

		# Figure out how many lines we have and forget about the first two
		let lines=`wc -l $entry | cut -d" " -f1`
		let lines=$lines-2
		content="`cat $entry | tail -n$lines`"

		# Append the metadata to the entry document
		echo "<div class=\"blog_subject\">$subject</div>" >> $sitedir/$pagename.html
		echo "<div class=\"blog_date\">$date</div>" >> $sitedir/$pagename.html
		echo "<div class=\"blog_body\">$content</div>" >> $sitedir/$pagename.html

		# Append any remaining resource files
        for resource in resources/*.res; do
			cat $resource >> $sitedir/$pagename.html
        done
	fi
# Do it again
done

# at this point $num is the number of the last entry processed
echo "Building index.html, feed.rss"
rm -f $sitedir/index.html

let first=$num-10
let last=$num

cat resources/header.lres >> $sitedir/index.html

rm -f $sitedir/feed.rss
cat resources/rss_header.lres >> $sitedir/feed.rss

# Very similar to the single entry pages... But different
for((i=$last;i>$first;i--)); do
	echo "   -> entry $i"
	entry="entries/$i.txt"
	date="`cat $entry | head -n1`"
	subject="`cat $entry | head -n2 | tail -n1`"

	let lines=`wc -l $entry | cut -d" " -f1`
	let lines=$lines-2
	content="`cat $entry | tail -n$lines`"

	echo "<div class=\"blog_subject\">$subject</div>" >> $sitedir/index.html
	echo "<div class=\"blog_date\">$date</div>" >> $sitedir/index.html
	echo "<div class=\"blog_body\">$content</div>" | sed -e "s/\\n/\n/g" >> $sitedir/index.html
	echo "<hr />" >> $sitedir/index.html

	echo "		<item>" >> $sitedir/feed.rss
	echo "			<title>$subject</title>" >> $sitedir/feed.rss
	echo "			<link>http://www.neohippie.net/entry$i.html</link>" >> $sitedir/feed.rss
	echo "			<pubDate>$date -0500</pubDate>" >> $sitedir/feed.rss
	echo "			<guid isPermaLink=\"true\">http://www.neohippie.net/entry$i.html</guid>" >> $sitedir/feed.rss
	echo "			<description><![CDATA[$content]]></description>" >> $sitedir/feed.rss
	echo "		</item>" >> $sitedir/feed.rss
done

for resource in resources/*.res; do
	cat $resource >> $sitedir/index.html
done

cat resources/rss_footer.lres >> $sitedir/feed.rss

# now we build an index of all the subject lines for an archive page
echo "Building archive.html"
rm -f $sitedir/archive.html

cat resources/header.lres >> $sitedir/archive.html

for((i=$last;i>1;i--)); do
	echo "   -> entry $i"
	if [ $i -lt 10 ]; then
		entry="entries/0$i.txt"
	else
		entry="entries/$i.txt"
	fi

	date="`cat $entry | head -n1`"
	subject="`cat $entry | head -n2 | tail -n1`"

	echo "<a href=\"entry$i.html\">$subject</a><div class=\"blog_date\">$date</div>" >> $sitedir/archive.html
done

for resource in resources/*.res; do
	cat $resource >> $sitedir/archive.html
done

# Run google sitemap, hopefully it'll generate something useful
python sitemap/sitemap_gen.py --config=sitemap/config.xml

# fix permissions
#chown jeremy:web $sitedir/*
chmod 755 $sitedir/*

synack at csh.rit.edu
ViewVC Help
Powered by ViewVC 1.0.0