Subject: makeindex.sh
To: None <www@netbsd.org, netbsd-docs@netbsd.org>
From: Jan Schaumann <jschauma@netbsd.org>
List: netbsd-docs
Date: 06/03/2002 12:40:28
--IJpNTDwzlM2Ie8A6
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

All,

I've been trying to find the Best Way to update index.html automatically
from Changes/index.list and gallery/events.list while at the same time
updating the translations websites *without* overwriting all existing
(translated) news-entries on those index-pages.

The problem is that we have to make a choice:

(I) We always want to have the latest news on all index pages.  If that
means that the news entries are in english even on the non-english
sites, so be it.  At the same time, we also want to be able to
re-generate the Changes/index.html file (possibly to correct spelling
errors in the headlines) and automatically correct the entries on the
various main pages.

(II) We only want to add the latest News entries to the various main
pages, preserving possibly already translated entries.  This means that
if we encounter a spelling error in the headline and re-generate the
news-entries, we'd end up with two entries for the same news:  they
differ, and so they are treated as separate entries.  (Alternate
scenario:  the headline with the error remains, but no duplicates are
generated)

Solution (I) is what we have in place, and the only problem with this is
that for the translated news, the translators need to regenerate the
entries by hand and paste them into the main page after an update to not
loose the translated links.

Solution (II) is what is attached in a different version of makeindex.sh
and Makefile.

As I write this, I believe it became obvious to me that we want to stick
with (I) and translators have to deal with it.  But if you have other
input (or even a third, better solution), let's discuss it.

-Jan

-- 
http://www.netbsd.org -
         Multiarchitecture OS, no hype required.

--IJpNTDwzlM2Ie8A6
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=Makefile

# $NetBSD: Makefile,v 1.6 2002/06/02 04:08:57 hubertf Exp $
# Nasty makefile to recurse into subdirs to ensure faq files are up to date

LANGS=	. de es pl se

all:	subdirs index

subdirs:
	@for dir in `echo */Makefile | sed 's:/Makefile::g'` ; do \
	    echo "-> ${PDIR}$$dir";cd $$dir;${MAKE} PDIR=${PDIR}$$dir/; cd .. ;\
	done

index: index.html

index.html: gallery/events.html Changes/index.html
	@for l in ${LANGS}; do \
		echo -n "News for '$$l' ..."; sh makeindex.sh $$l; echo " done."; \
	done;
	
gallery/events.html: gallery/events.list
	cd gallery; make events.html; cd ..;

Changes/index.html: Changes/index.list
	cd Changes; make index.html ; cd ..;


--IJpNTDwzlM2Ie8A6
Content-Type: application/x-sh
Content-Disposition: attachment; filename="makeindex.sh"

#!/bin/sh
#
# $NetBSD: makeindex.sh,v 1.0 2002/01/21 16:27:57 jschauma Exp $
#
# update <lang>/index.html with NEWS and EVENTS from /htdocs/Changes/index.html
# and /htdocs/gallery/events.html

LANG=${1:-.}
if [ "$LANG" = "." ]; then
	DIR="\.\/"
else
	DIR="\.\.\/"
fi
TMPDIR=${TMPDIR:-/tmp}
CNT=0
NUM=0

# insert the head
sed -e '/<!-- NEWS::START -->/q' ${LANG}/index.html > ${TMPDIR}/index.tmp

# get current news
sed -e '/<!-- NEWS::START -->/!d' -e '/<!-- NEWS::END -->/bt
:t
/<!-- NEWS::START -->/,/<!-- NEWS::END -->/ {
        /<!-- NEWS::END -->/! {
                $! {
                        N;
                        bt
                }
        }
}
' ${LANG}/index.html > ${TMPDIR}/news.current

# get new news
# links to anchors on that page are new, trim grep's separator and only print
# the first 8 links (each links is two lines)
grep -B 1 'href="#' Changes/index.html | sed -e 's/<font face="helvetica, arial, sans-serif">/<font face="helvetica, arial" size="-1">/' -e "s/href=\"#/href=\"${DIR}Changes\/#/" -e '/^--/d' | sed -e '17,$d' > ${TMPDIR}/news.new

# see what's new
for i in `grep 'Changes' ${TMPDIR}/news.new | \
		sed -e 's/\(.*\)Changes\/#\(.*\)"\(.*\)/\2/'`; do
	grep $i ${TMPDIR}/news.current 2>&1 >/dev/null
	if [ "$?" -gt "0" ]; then
		grep -B 1 "Changes\/\#${i}" ${TMPDIR}/news.new >> ${TMPDIR}/index.tmp
		CNT=$(($CNT+1))
	fi
done;

# add remaining news
NUM=$((17-2*$CNT))
grep -v 'NEWS::' ${TMPDIR}/news.current | awk "NR<$NUM { print; }" >> ${TMPDIR}/index.tmp

# insert the middle part
sed -e '/<!-- NEWS::END -->/!d' -e '/<!-- NEWS::END -->/bt
:t
/<!-- NEWS::END -->/,/<!-- EVENTS::START -->/ {
        /<!-- EVENTS::START -->/! {
                $! {
                        N;
                        bt
                }
        }
}
' ${LANG}/index.html >> ${TMPDIR}/index.tmp

# links to anchors on that page are events, if we encounter "--" it means that
# Upcoming Events is over (grep had to jump) and we can stop.  Only add at
# most 6 events (each event is two lines)
grep -B1 'href="#' gallery/events.html | sed -e 's/<font face="helvetica, arial, sans-serif">/<font face="helvetica, arial" size="-1">/' -e 's/href="#/href="gallery\/events.html#/' -e '/^--/q' | sed -e '/^--/d' -e '13,$d' >> ${TMPDIR}/index.tmp

# insert the tail
sed -e '/<!-- EVENTS::END -->/!d' -e '/<!-- EVENTS::END -->/bt
:t
/<!-- EVENTS::END -->/,$ {
        $! {
                N;
                bt
        }
}' ${LANG}/index.html >> ${TMPDIR}/index.tmp

# put in place
mv -f ${TMPDIR}/index.tmp ${LANG}/index.html

# clean up
rm -f ${TMPDIR}/news.current ${TMPDIR}/news.new

--IJpNTDwzlM2Ie8A6--