💾 Archived View for celehner.com › 2021 › 07 › oldcomp › entry.awk captured on 2021-12-17 at 13:26:06.

View Raw

More Information

⬅️ Previous capture (2021-11-30)

-=-=-=-=-=-=-

function escape_html(text) {
	gsub(/&/, "\\&", text)
	gsub(/</, "\\&lt;", text)
	gsub(/>/, "\\&gt;", text)
	gsub(/"/, "\\&quot;", text)
	return text
}

BEGIN {
	self = base name
	print "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
	print "<feed xmlns=\"http://www.w3.org/2005/Atom\">"
	print "  <title>" title "</title>"
	#print "  <link rel=\"alternate\" type=\"text/html\" href=\"" base "\"/>"
	print "  <link rel=\"self\" type=\"application/atom+xml\" href=\"" self "\"/>"
	print "  <updated>" strftime("%FT%TZ") "</updated>"
	print "  <id>" self "</id>"
}

FNR == 1 {
	if (NR != 1) { end_entry() }
	id = base FILENAME
	datecmd = "date -Isec -r " FILENAME
	datecmd | getline time
	close(datecmd)
	print "<entry>"
	print "  <title>" FILENAME "</title>"
	print "  <id>" id "</id>"
	print "  <link rel=\"alternate\" href=\"" id "\" />"
	print "  <author><name>" author_name "</name><email>" author_email "</email></author>"
	print "  <updated>" time "</updated>"
	printf "  <content type=\"html\">&lt;pre&gt;"
}

{
	print escape_html(escape_html($0))
}

function end_entry() {
	print "&lt;/pre&gt;</content>"
	print "</entry>"
}

END {
	end_entry()
	print "</feed>"
}