#!/bin/sh

####################################################################################################
####################################################################################################
###
###	Default is to create the HTML page
###

savePage=1
if [ "${1}" = "--inspect" ]
then
	savePage=0
fi


####################################################################################################
####################################################################################################
###
###	Site List ("heredoc" storage format)
###

useData()
{
	version="2026-08-05  v0.3<br/><br/>"

	cat >"${tmp}" <<'EnDoFfIlE'
Open Worldwide Application Security Project User group (OWASP) - Ottawa chapter|https://github.com/OWASP/www-chapter-ottawa|
Open Source Nerds and Nachos|https://www.meetup.com/opensourcenerdsandnachos/|
Ottawa Capital Linux User Group|https://wiki.linux-ottawa.org/doku.php?id=start|
Ottawa BSD User Group|ocbug@ocbug.ca|
Hamilton BSD User Group|https://hambug.ca/|
Ontario BSD User Group|https://www.onbsd.ca/|
Greater Toronto Area BSD User Group|https://www.gtabug.ca/|
Linux User Group at Ryerson University (now, Toronto Metropolitan University)|https://www.facebook.com/RULUG/|
Vancouver Linux Users Group|https://vanlug.ca/|
Nova Scotia Linux Users Group|https://www.nslug.ns.ca/|
Edmonton Linux Users Group|https://elug.ca/|
Manitoba Unix Users Group|https://muug.ca/|
Rutgers Student Linux User Group|https://www.cs.rutgers.edu/component/content/article/rutgers-student-linux-user-group-ruslug?Itemid=101&amp;catid=129|
Low Level Linux User Group (L3GO)|sigs-l3go@linux-ottawa.org|
Toronto Postgres User Group|https://www.meetup.com/toronto-postgres-user-group/|
Rencontres Linux|https://www.rencontres-linux.quebec/|
Linux Gatineau|https://www.linux-gatineau.org|
Calgary Unix Users Group|https://cuug.ab.ca/|
Savoir Faire Linux|https://www.savoirfairelinux.ca|
Club Framboise (dedicated to the Raspberry Pi)|https://www.clubframboise.ca|
Microsoft Reactor Toronto|https://www.meetup.com/microsoft-reactor-toronto/|
EnDoFfIlE

} #useData


####################################################################################################
####################################################################################################
###
###	HTML Wrapper for displayed list
###

buildPage()
{
	tableStyles=""
	if [ ${inclCSS} -eq 1 ]
	then
		version="<div class=\"version\">${version}<br/></div>"

		tableStyles=$( cat <<EnDoFfIlE
<style>

.column {
	width:			100% ;
}

.siteDesc, .siteUrl {
	width:			100% ;
	padding-bottom:		0px ;
}

.siteDesc {
	font-family:		sans-serif ;
	font-size:		15px ;
	font-style:		normal ;
	font-weight:		bold ;
	padding-top:		4px ;
	padding-left:		3px ;
}

.siteUrl {
	font-family:		monospace ;
	font-size:		13px ;
	font-style:		italic ;
	font-weight:		normal ;
	padding-top:		0px ;
	padding-left:		30px ;
	transition:		all 0.2s ease;
	transition-delay:	0s;
}

.siteUrl:hover {
	background-color:	#2F2F2F ;
	color:			yellow ;
	font-size:		18px ;
	padding-top:		4px ;
	padding-bottom:		4px ;
}

a:link {
  color: black;
  background-color: transparent;
  text-decoration: none;
}

a:visited {
  color: black;
  background-color: transparent;
  text-decoration: none;
}

a:hover {
  color: red;
  background-color: transparent;
  text-decoration: none;
  /*
  text-decoration: underline;
  */
}

a:active {
  color: yellow;
  background-color: transparent;
  text-decoration: none;
  /*
  text-decoration: underline;
  */
}

body {
  background-image:		url('CREAZILLA__canada-halftone-flag-clipart.png') ;
  background-attachment:	fixed ;
  background-position:		center ;
  background-repeat:		no-repeat ;
  background-size:		cover ;
  /*
  filter:			saturate(10%) brightness(40%) ;
  */
}

h2 {
	background-color:	#ed1c24 ;
	color:			white ;
	text-align:		center ;
	padding-top:		6px ;
	padding-bottom:		6px ;
}

.version {
	font-family:		sans-serif ;
	font-size:		10px ;
	font-style:		italic ;
	font-weight:		bold ;
	padding-left:		30px ;
}

</style>
EnDoFfIlE
)
	fi

	cat <<EnDoFfIlE
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
${tableStyles}

</head>
<body>

<h2>Linux Communities Currently Active in Canada</h2>
${version}
${formattedList}

<br/><br/>
<i>For updates, contact:  Katie via sigs-l3go &lt;sigs-l3go &amp; linux-ottawa.org&gt;</i>

</body>
</html>
EnDoFfIlE

} #buildPage()


####################################################################################################
####################################################################################################
###
###	Generate page using original basic presentation format
###

doBasic(){
	#awk -v mode=${sel} 'BEGIN{
	formattedList=$( awk 'BEGIN{
		sIndx=0 ;
		pIndx=0 ;
	}{
		if( NF > 0 ){
			n=split( $0, sites, "|" ) ;
			printf("- %s:<br/>\n\n &nbsp; &nbsp; &nbsp; %s<br/>\n\n", sites[1], sites[2] ) ;
		} ;
	}' <${tmp} )

} #doBasic()


####################################################################################################
####################################################################################################
###
###	Generate page using original basic presentation format
###

doTable(){
	#awk -v mode=${sel} 'BEGIN{
	formattedList=$( awk 'BEGIN{
		sIndx=0 ;
		pIndx=0 ;

		###	Initialize tags for start of HTML table
		printf("<table class=\"column\">\n")
	}{
		if( NF > 0 ){
			n=split( $0, sites, "|" ) ;
			if( sites[2] !~ /^http/ ){
				urlPref="mailto:" ;
			}else{
				urlPref="" ;
			} ;
			printf("\t<tr><td class=\"siteDesc\"> 🍁 <a href=\"%s%s\">%s:</a></td></tr>\n\t<tr><td class=\"siteUrl\">%s</td></tr>\n", urlPref, sites[2], sites[1], sites[2] ) ;
		} ;
	}END{
		###	Close off tags for end of HTML table
		printf("</table>\n") ;
	}' <${tmp} )

} #doTable()


####################################################################################################
####################################################################################################
###
###	Script controlling logic
###

selectOutput()
{
	base="$(basename "${0}" ".sh" )"
	tmp="/tmp/${base}_$$.tmp"
	out=""
	here=$(pwd)

	echo "
	Choose HTML page format:

	[1] Basic (original)
	[2] Table

	Enter selection [ 1 | (2) ] => \c" >&2 ; read sel
	if [ -z "${sel}" ] ; then  sel=2 ; fi

	useData

	case ${sel} in
		1 ) inclCSS=0 ; doBasic ;;
		2 ) inclCSS=1 ; doTable ;; 
		* ) echo "\t Selection entered is not available.  Try again!\n" >&2; exit 1 ;;
	esac

	if [ ${savePage} -eq 1 ]
	then
		out="${here}/${base}.html"
		buildPage >"${out}"
		echo "\n\tSaved: ${out}" >&2
	else
		buildPage
	fi

}


####################################################################################################
####################################################################################################
###
###	Background graphics (modified version of below)
###
###	SCR:	https://creazilla.com/media/clipart/7822218/canada-halftone-flag
###



####################################################################################################
####################################################################################################
###
###	Run script to create HTML page displaying Canadian Site Index
###

selectOutput

