cd / ; apropos ; find * ;

gemfeed.awk #

#!/usr/bin/awk -f
# Create an gemfeed from a list of plain text files.
# First line of a post is title
# Second line is date formatted %Y-%m-%dT%TZ


BEGIN {
	if ( ARGC != 2 ) { usage() } # check we have ARGV[1]

	# if the user didn't specify variables, use defaults
	if ( gemfeedtitle == "" ) { gemfeedtitle = "My gemfeed"}

	# command to list all posts. ARGV[1] is replaced by directory given as arg
	if ( cmd == "" ) {
		cmd = "find " ARGV[1] " -name '*.txt' -maxdepth 1 -a ! -name '_*'  | sort -r"
	}

	printf "# %s\n\n", gemfeedtitle

	# let's go
	n = 0

	while (( cmd | getline post ) == 1 ) {

		# get first line : title
		if ((getline title < post) != 1) { continue }
		# remove leading "#" if any
		sub("^# +?", "", title)
		# get second line : pubdate
		if ((getline pubdate < post) != 1) { continue }
		date = substr(pubdate, 1, 10)

		link = "/" post

		printf "=> %s %s  —  %s\n", link, date, title
		n++
	}
	close(cmd)
}

END {
	print "=> ../ "
}

function usage() {
	printf "usage : awk -f atom.awk -v gemfeedtitle='my feed' posts/"
	exit 1
}