Browse Source

Improved tag map generation

NEWTESTIMONIALPAGES
Reinhard Müller 7 months ago
parent
commit
eb8976770d
9 changed files with 125 additions and 110 deletions
  1. 1
    0
      .gitignore
  2. 1
    0
      Makefile
  3. 7
    3
      build/xslt/get_tags.xsl
  4. 8
    15
      tags/tags.en.xhtml
  5. 8
    15
      tags/tags.fr.xhtml
  6. 10
    15
      tags/tags.nl.xhtml
  7. 1
    5
      tags/tags.sources
  8. 25
    53
      tags/tags.xsl
  9. 64
    4
      tools/update_xmllists.sh

+ 1
- 0
.gitignore View File

@@ -7,6 +7,7 @@ tools/.texts-??.xml
.fundraising.??.xml
.*.xmllist
tags/tagged-*.en.xhtml
tags/.tags.??.xml
events/????/????.??.xhtml
events/????/????.sources
events/????/????.xsl

+ 1
- 0
Makefile View File

@@ -121,6 +121,7 @@ default_xsl:
# automatically created, these are regular source files for HTML pages, and
# in phase 2 are built into pages listing all news items and events for a
# tag.
# * tags/.tags.??.xml with a list of the tags useed.
# * <dir>/.<base>.xmllist for each <dir>/<base>.sources as well as for each
# tags/tagged-<tags>.en.xhtml. These files are used in phase 2 to include the
# correct XML files when generating the HTML pages. It is taken care that

+ 7
- 3
build/xslt/get_tags.xsl View File

@@ -12,10 +12,14 @@
<xsl:output method="text" encoding="UTF-8"/>

<xsl:template match="tag">
<xsl:value-of select="."/>
<!-- tag name -->
<xsl:value-of select="translate(.,' .+-/:_','')"/>
<!-- blank -->
<xsl:text> </xsl:text>
<!-- tag label -->
<xsl:value-of select="@content"/>
<!-- append a newline -->
<xsl:text>
</xsl:text>
<xsl:text>&#xa;</xsl:text>
</xsl:template>
<xsl:template match="@*|node()" priority="-1">

+ 8
- 15
tags/tags.en.xhtml View File

@@ -2,25 +2,18 @@

<html>
<head>
<title>FSFE - Tags</title>
<title>Tags - FSFE</title>
</head>

<body>
<h1>Tags</h1>

<h2>News</h2>
<all-tags-news/>

<taglist section="news"/>

<h2>Events</h2>
<all-tags-events/>
</body>

<timestamp>$Date: 2011-01-13 15:29:42 +0100 (jeu. 13 janv. 2011) $ $Author: samtuke $</timestamp>
<taglist section="events"/>
</body>
</html>
<!--
Local Variables: ***
mode: xml ***
End: ***
-->

+ 8
- 15
tags/tags.fr.xhtml View File

@@ -2,25 +2,18 @@

<html>
<head>
<title>FSFE - Tags</title>
<title>Tags - FSFE</title>
</head>

<body>
<h1>Tags</h1>

<h2>Actualités</h2>
<all-tags-news/>

<taglist section="news"/>

<h2>Évènements</h2>
<all-tags-events/>
</body>

<timestamp>$Date: 2011-01-13 15:29:42 +0100 (jeu. 13 janv. 2011) $ $Author: samtuke $</timestamp>
<taglist section="events"/>
</body>
</html>
<!--
Local Variables: ***
mode: xml ***
End: ***
-->

+ 10
- 15
tags/tags.nl.xhtml View File

@@ -1,26 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>

<html>
<head>
<title>FSFE - Trefwoorden</title>
<title>Trefwoorden - FSFE</title>
</head>

<body>
<h1>Trefwoorden</h1>

<h2>Nieuws</h2>
<all-tags-news/>

<taglist section="news"/>

<h2>Evenementen</h2>
<all-tags-events/>
<taglist section="events"/>
</body>

<timestamp>$Datum: 2011-01-13 15:29:42 +0100 (don. 13 jan. 2011) $ $Auteur: samtuke $</timestamp>
<translator>André Ockers</translator>
<translator>André Ockers</translator>
</html>
<!--
Local Variables: ***
mode: xml ***
End: ***
-->

+ 1
- 5
tags/tags.sources View File

@@ -1,5 +1 @@
news/*/news-*:[]
news/*/.news-*:[]
news/nl/nl-*:[]
news/nl/.nl-*:[]
events/*/event-*:[]
tags/.tags:[]

+ 25
- 53
tags/tags.xsl View File

@@ -1,65 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dt="http://xsltsl.org/date-time">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="../fsfe.xsl" />
<xsl:output method="html" encoding="utf-8" indent="yes" doctype-system="about:legacy-compat" />
<!-- The top level element of the input file is "buildinfo" -->
<xsl:template match="buildinfo">
<xsl:apply-templates select="node()"/>
</xsl:template>

<xsl:key name="news-tags" match="/buildinfo/document/set/news/tags/tag[@key]"
use="translate(@key,'ABCDEFGHIJKLMNOPQRSTUVWXYZ-_+ /','abcdefghijklmnopqrstuvwxyz')"/>
<xsl:key name="news-tags" match="/buildinfo/document/set/news/tags/tag[not(@key)]"
use="translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ-_+ /','abcdefghijklmnopqrstuvwxyz')"/>
<xsl:key name="event-tags" match="/buildinfo/document/set/event/tags/tag[@key]"
use="translate(@key,'ABCDEFGHIJKLMNOPQRSTUVWXYZ-_+ /','abcdefghijklmnopqrstuvwxyz')"/>
<xsl:key name="event-tags" match="/buildinfo/document/set/event/tags/tag[not(@key)]"
use="translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ-_+ /','abcdefghijklmnopqrstuvwxyz')"/>
<xsl:template name="taglink">
<xsl:param name="type"/>
<xsl:template match="taglist">
<xsl:variable name="section">
<xsl:value-of select="@section"/>
</xsl:variable>

<xsl:variable name="keyname"
select="translate(@key,'ABCDEFGHIJKLMNOPQRSTUVWXYZ-_+ /','abcdefghijklmnopqrstuvwxyz')"/>
<xsl:variable name="tagname"
select="translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ-_+ /','abcdefghijklmnopqrstuvwxyz')"/>
<xsl:element name="ul">
<xsl:attribute name="class">taglist</xsl:attribute>

<xsl:choose><xsl:when test="@key">
<xsl:if test="generate-id() = generate-id(key($type, $keyname))">
<li><a href="/tags/tagged-{$keyname}.html"><xsl:value-of select="."/></a></li>
</xsl:if>
</xsl:when><xsl:when test="@content and not(@content = '')">
<xsl:if test="generate-id() = generate-id(key($type, $tagname))">
<li><a href="/tags/tagged-{$tagname}.html"><xsl:value-of select="@content"/></a></li>
</xsl:if>
</xsl:when><xsl:otherwise>
<xsl:if test="generate-id() = generate-id(key($type, $tagname))">
<li><a href="/tags/tagged-{$tagname}.html"><xsl:value-of select="."/></a></li>
</xsl:if>
</xsl:otherwise></xsl:choose>
</xsl:template>
<xsl:for-each select="/buildinfo/document/set/tag[@section=$section]">
<xsl:sort select="."/>

<!--display dynamic list of news items-->
<xsl:template match="all-tags-news">
<ul class="taglist">
<xsl:for-each select="/buildinfo/document/set/news/tags/tag"><xsl:sort select="translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" order="ascending" />
<xsl:call-template name="taglink"><xsl:with-param name="type" select="'news-tags'"/></xsl:call-template>
</xsl:for-each>
</ul>
</xsl:template>
<xsl:element name="li">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:text>tagged-</xsl:text>
<xsl:value-of select="@name"/>
<xsl:text>.html</xsl:text>
</xsl:attribute>

<!--display dynamic list of event items-->
<xsl:template match="all-tags-events">
<ul class="taglist">
<xsl:for-each select="/buildinfo/document/set/event/tags/tag"><xsl:sort select="translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" order="ascending" />
<xsl:call-template name="taglink"><xsl:with-param name="type" select="'event-tags'"/></xsl:call-template>
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
<xsl:element name="span">
<xsl:attribute name="class">badge</xsl:attribute>
<xsl:value-of select="@count"/>
</xsl:element><!-- /span -->
</xsl:element><!-- /a -->
</xsl:element><!-- /li -->
</xsl:for-each>
</ul>
</xsl:element><!-- /ul -->
</xsl:template>

</xsl:stylesheet>

+ 64
- 4
tools/update_xmllists.sh View File

@@ -2,13 +2,16 @@
# -----------------------------------------------------------------------------
# Update XML filelists (*.xmllist) and tag list pages (tags/tagged-*)
# -----------------------------------------------------------------------------
# This script is called from the phase 1 Makefile.
# This script is called from the phase 1 Makefile and creates/updates the
# following files:
#
# * tags/tagged-<tags>.en.xhtml for each tag used. Apart from being
# automatically created, these are regular source files for HTML pages, and
# in phase 2 are built into pages listing all news items and events for a
# tag.
#
# * tags/.tags.??.xml with a list of the tags useed.
#
# * <dir>/.<base>.xmllist for each <dir>/<base>.sources as well as for each
# tags/tagged-<tags>.en.xhtml. These files are used in phase 2 to include the
# correct XML files when generating the HTML pages. It is taken care that
@@ -39,16 +42,31 @@ tagmaps="/tmp/tagmaps-${pid}"
rm -rf "${tagmaps}"
mkdir "${tagmaps}"

taglabels="/tmp/taglabels-${pid}"

rm -rf "${taglabels}"
mkdir "${taglabels}"

# -----------------------------------------------------------------------------
# Create a complete and current map of which tag is used in which files
# -----------------------------------------------------------------------------

echo "* Generating tag maps"

for xml_file in $(find * -name '*.??.xml' | xargs grep -l '</tag>' | sort); do
xsltproc "build/xslt/get_tags.xsl" "${xml_file}" | while read raw_tag; do
tag=$(echo "${raw_tag}" | tr -d ' +-/:_' | tr '[:upper:]' '[:lower:]')
for xml_file in $(find * -name '*.??.xml' -not -path 'tags/*' | xargs grep -l '</tag>' | sort); do
xsltproc "build/xslt/get_tags.xsl" "${xml_file}" | while read raw_tag label; do
tag=$(echo "${raw_tag}" | tr '[:upper:]' '[:lower:]')

# Add file to list of files by tag name
echo "${xml_file%.??.xml}" >> "${tagmaps}/${tag}"

# Store label by language and tag name
language=$(echo ${xml_file} | sed -rn 's/^.*\.(..)\.xml/\1/p')
if [ "${language}" -a "${label}" ]; then
mkdir -p "${taglabels}/${language}"
# Always overwrite so the newest news item will win.
echo "${label}" > "${taglabels}/${language}/${tag}"
fi
done
done

@@ -81,11 +99,53 @@ for tag in $(ls "tags" | sed -rn 's/tagged-(.*)\.en.xhtml/\1/p'); do
fi
done

# -----------------------------------------------------------------------------
# Update the tag lists
# -----------------------------------------------------------------------------

taglist="/tmp/taglist-${pid}"

for language in $(ls ${taglabels}); do
{
echo '<?xml version="1.0" encoding="UTF-8"?>'
echo ''
echo '<tagset>'

for section in "news" "events"; do
for tag in $(ls "${tagmaps}"); do
count=$(grep "^${section}/" "${tagmaps}/${tag}" | wc --lines || true)

if [ -f "${taglabels}/${language}/${tag}" ]; then
label="$(cat "${taglabels}/${language}/${tag}")"
elif [ -f "${taglabels}/en/${tag}" ]; then
label="$(cat "${taglabels}/en/${tag}")"
else
label="${tag}"
fi

if [ "${count}" != "0" ]; then
echo " <tag section=\"${section}\" name=\"${tag}\" count=\"${count}\">${label}</tag>"
fi
done
done

echo '</tagset>'
} > ${taglist}

if ! cmp --quiet "${taglist}" "tags/.tags.${language}.xml"; then
echo "* Updating tags/.tags.${language}.xml"
cp "${taglist}" "tags/.tags.${language}.xml"
fi

rm -f "${taglist}"
done

# -----------------------------------------------------------------------------
# Remove the temporary directory
# -----------------------------------------------------------------------------

rm -rf "${tagmaps}"
rm -rf "${taglabels}"

# -----------------------------------------------------------------------------
# Update .xmllist files for .sources

Loading…
Cancel
Save