[BACK]Return to groups.awk CVS log [TXT][DIR] Up to [local] / www / build

File: [local] / www / build / groups.awk (download)

Revision 1.13, Mon May 27 22:55:27 2019 UTC (5 years ago) by bentley
Branch: MAIN
CVS Tags: HEAD
Changes since 1.12: +12 -13 lines

Substantially clean up and modernize HTML markup across openbsd.org.

This was done with three purposes in mind:
- to reduce the massive amount of inline HTML, to be easier on developers
  adding actual content
- to allow running the HTML validator across the source (doing this found
  many unintentional mistakes in the present code, including at least a
  dozen cases of half- or fully-invisible text)
- to separate content from presentation, so appearance can be controlled
  through stylesheets

Great care was taken to keep all pages, even very old ones, looking the
same, give or take a few pixels of whitespace.

Much review, critique, and improvement from tj@

#!/usr/bin/nawk -f

# Called from makefile to convert from groups.dat to ../groups.html

# convert data like this (order doesn't matter except 0 at front)
# 0
# C Erewhon
# P Ontario
# T Dictionopolis
# A R R # 1
# O OpenBSD User Group of Greater Erewhon
# I Ian F. Darwin
# F Every Monday at 25:00
# M ian@ougge.erewhon
# U http://www.ougge.erewhon/
# N OpenBSD

# into HTML to make nice neat tables.

/^#/ { next; }

$1 == "0" {
	if (country == "" && prov == "")
		next;
	dump();
	reset();
	next;
	}

$1 == "C" { country = substr($0, 3);
	if (country == "USA")
		country = "United States"
	if (country != oldCountry) {
		print "<tbody><tr><th colspan=\"5\""
		if (country == "United States") {
			n = split("USA", labels, " ")
		} else {
			n = split(country, labels, " ")
		}
		print "id='" labels[1] "'>"
		print country
	 }
	oldCountry = country
	next
}
$1 == "P" { prov = substr($0, 3); next }
$1 == "T" { city = substr($0, 3); next }
$1 == "A" { addr = substr($0, 3); next }
$1 == "O" { org = substr($0, 3); next }
$1 == "I" { indv = substr($0, 3); next }
$1 == "B" { phone = substr($0, 3); next }
$1 == "F" { freq = substr($0, 3); next }
$1 == "M" { email = substr($0, 3); next }
$1 == "U" { url = substr($0, 3); next }
$1 == "N" { note = substr($0, 3); next }

# left over - must be part of note?
	{
	note = note "\n" $0
	next
	}

function dump() {
	print "<tr>"
	print "<td>" 
		if (indv != "")
			print indv "<br>" 
		print "<b>" org "</b><br>" addr
	print "	<td>" city "<br>" prov
	print "	<td>" 
		if (phone != "")
			print phone "<br>" 
		print freq
	print "	<td>"
		if (email != "")
			print "<a href=\"mailto:" email "\">" email "</a>" "<br>"
		print "<a href=\"" url "\">" url "</a>"
	print "	<td>" note
}

function reset() {
	prov = ""
	city = ""
	addr = ""
	org = ""
	indv = ""
	email = ""
	phone = ""
	freq = ""
	url = ""
	note = ""
}

END {
	dump();		# don't forget the last guy!
}