[BACK]Return to makeindex.sh CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / htdocs

File: [cvs.NetBSD.org] / htdocs / makeindex.sh (download)

Revision 1.20, Mon Oct 10 09:31:55 2016 UTC (2 years, 11 months ago) by leot
Branch: MAIN
CVS Tags: HEAD
Changes since 1.19: +22 -5 lines

Instruct makeindex.sh to generate the `Upcoming Events' section only if there is
at least one upcoming events.

Discussed with the www@ team. Thanks to <reed> for the feedback!

#!/bin/sh
# $NetBSD: makeindex.sh,v 1.20 2016/10/10 09:31:55 leot Exp $
#
# NAME
#	makeindex.sh - regenerate the index.html file with latest news,
#		event and languages
#
# SYNOPSIS
#	env WEB_PREFIX=<dir> CHANGES_DIR=<dir> EVENTS_DIR=<dir> makeindex.sh
#
# DESCRIPTION
#	makeindex.sh regenerates the index.html file with the latest
#	items from the Changes directory and gallery/events.xml file.
#
# ENVIRONMENT
#	WEB_PREFIX
#		An absolute pathname pointing to the top-level directory
#		of the htdocs.
#
#	HTDOCS_RELTOPDIR
#		A relative path pointing to the top-level directory of
#		the web site.
#
#	CHANGES_DIR
#		The directory where the changes are located.
#
#	EVENTS_DIR
#		The directory where the events are located.
#

set -eu

fail() {
	echo "$0: ERROR: $1" 1>&2
	exit 1
}

checkfile() {
	if [ ! -f "$1" ]; then
		fail "\"$1\" does not exist."
	fi
}

# Check that all environment variables are properly defined.
for var in WEB_PREFIX CHANGES_DIR EVENTS_DIR HTDOCS_RELTOPDIR; do
	eval "value=\${${var}-}"
	if [ "$value" = "" ]; then
		fail "$var must be set and non-empty."
	elif [ ! -d "$value" ]; then
		fail "$var must point to an existing directory."
	fi
done

checkfile "index.html"

# Check that the index file has all necessary category tags.
# Currently don't check for LANGUAGES, as they are completely
# out of date
for category in NEWS EVENTS; do
	for start_end in START END; do
		tag="<!-- ${category}::${start_end} -->"
		if grep "$tag" "index.html" 1>/dev/null; then
			: "Fine."
		else
			echo "$0: error: The tag $tag is missing in `pwd`/index.html." 1>&2
			exit 1
		fi
	done
done

# Extract the head from the page.
awk "(NR == 1),  /<!-- NEWS::START -->/ { print }" \
< "index.html" \
> "index.tmp"

checkfile "index.chg"

# Extract the 4 latest changes.
sed -e 's,\(.*\),<li>&</li>,' \
    -e '4q' \
< "index.chg" \
>> "index.tmp"

# Extract the middle part from the page.
awk "/<!-- NEWS::END -->/, /<!-- EVENTS::START -->/ { print }" \
< "index.html" \
>> "index.tmp"

# Extract the 4 next upcoming events.

checkfile "${EVENTS_DIR}/events.chg"

if [ -s "${EVENTS_DIR}/events.chg" ]; then
	cat >> "index.tmp" <<EOF
	<h3>Upcoming Events</h3>
	<ul>
EOF

	sed -e 's,\(.*\),<li>&</li>,' \
	    -e '4q' \
	< "${EVENTS_DIR}/events.chg" \
	>> "index.tmp"

	cat >> "index.tmp" <<EOF
	  <li>
	    <span class="more">
	      <a href="gallery/events.html">&raquo; Archive</a>
	    </span>
	  </li>
	</ul>
EOF

fi

# Extract another middle part from the page.
awk "/<!-- EVENTS::END -->/, /<!-- LANGUAGES::START -->/ { print }" \
< "index.html" \
>> "index.tmp"

# Generate the links to the translated pages.
# NOTE: Translations are completely out of date. Skip them.
# checkfile "${WEB_PREFIX}/languages"
# while read langcode url langname; do
# 	case "$langcode" in
# 	"#"*|"")	continue;;
# 	esac

# 	case "$url" in
# 	http://*)	link="$url";;
# 	.)		link="${HTDOCS_RELTOPDIR}/";;
# 	*)		link="${HTDOCS_RELTOPDIR}/${url}/";;
# 	esac
# 	echo "          <a href=\"$link\" hreflang=\"$langcode\" lang=\"$langcode\">$langname</a><br>" >> "index.tmp"
# done < "${WEB_PREFIX}/languages"

# # Extract the tail from the page.
# awk "/<!-- LANGUAGES::END -->/, (1 != 1) { print }" \
# < "index.html" \
# >> "index.tmp"

# Replace the index page with the newly generated one.
mv -f "index.tmp" "index.html"