changeset 6:6b8fa938630b

archive: archive view
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sat, 31 Jan 2009 00:46:22 -0500
parents 372b26cadaf3
children 26ae3b8f443d
files archive.cgi common-head.sh
diffstat 2 files changed, 65 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/archive.cgi	Sat Jan 31 00:46:22 2009 -0500
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+. common-head.sh
+
+##########################
+
+catid=`echo "$PATH_INFO" | sed -e 's,^/,,'`
+
+cat templates/header.html | sed -e "s|@@TITLE@@|`arch_title_date $catid`|"
+
+for postid in `ls data/by-month/$catid/ | sort -nr` ; do
+	fn="data/posts/$postid/post.txt"
+
+	cat templates/story-top.html | sed -e "
+s|@@POSTID@@|`basename $postid`|g
+s|@@POSTDATE@@|`get_date "$fn"`|g
+s|@@TITLE@@|`get_xattr post_title "$fn"`|g
+"
+
+	for catname in `get_xattr post_cats "$fn" | sed -e 's|,| |g'` ; do
+		cat templates/story-cat-item.html | sed -e "
+s|@@CATNAME@@|$catname|g
+	"
+	done
+
+	cat templates/story-middle.html | sed -e "
+s|@@POSTTIME@@|`get_time "$fn"`|g
+	"
+
+	cat_post "$fn"
+
+	cat templates/story-bottom.html
+done
+
+##########################
+
+. common-foot.sh
--- a/common-head.sh	Sat Jan 31 00:35:03 2009 -0500
+++ b/common-head.sh	Sat Jan 31 00:46:22 2009 -0500
@@ -16,28 +16,38 @@
 	date "+%H:%M" -d "`get_xattr post_time "$1"`"
 }
 
+# usage: str_month <MM>
+str_month()
+{
+	case "$1" in
+		01) echo "january" ;;
+		02) echo "february" ;;
+		03) echo "march" ;;
+		04) echo "april" ;;
+		05) echo "may" ;;
+		06) echo "june" ;;
+		07) echo "july" ;;
+		08) echo "august" ;;
+		09) echo "september" ;;
+		10) echo "october" ;;
+		11) echo "november" ;;
+		12) echo "december" ;;
+		*)  echo "unknown" ;;
+	esac
+}
+
 # usage: arch_date <YYYYMM>
 arch_date()
 {
-	y=`expr substr "$1" 1 4`
+	m=`expr substr "$1" 5 2`
+	echo "`str_month $m` `expr substr "$1" 1 4`"
+}
 
-	case `expr substr "$1" 5 2` in
-		01) m="january" ;;
-		02) m="february" ;;
-		03) m="march" ;;
-		04) m="april" ;;
-		05) m="may" ;;
-		06) m="june" ;;
-		07) m="july" ;;
-		08) m="august" ;;
-		09) m="september" ;;
-		10) m="october" ;;
-		11) m="november" ;;
-		12) m="december" ;;
-		*) m="unknown" ;;
-	esac
-
-	echo "$m $y"
+# usage: arch_title_date <YYYYMM>
+arch_title_date()
+{
+	m=`expr substr "$1" 5 2`
+	echo "`expr substr "$1" 1 4` \&raquo; `str_month $m`"
 }
 
 # usage: cat_post <filename>