From eb8976770d335a8525dbfb6c3c7af0efd0ef2463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20M=C3=BCller?= Date: Thu, 14 Mar 2019 02:25:37 +0100 Subject: [PATCH] Improved tag map generation --- .gitignore | 1 + Makefile | 1 + build/xslt/get_tags.xsl | 10 +++-- tags/tags.en.xhtml | 31 ++++++---------- tags/tags.fr.xhtml | 31 ++++++---------- tags/tags.nl.xhtml | 25 +++++-------- tags/tags.sources | 6 +-- tags/tags.xsl | 80 +++++++++++++--------------------------- tools/update_xmllists.sh | 68 ++++++++++++++++++++++++++++++++-- 9 files changed, 134 insertions(+), 119 deletions(-) mode change 100755 => 100644 tags/tags.sources diff --git a/.gitignore b/.gitignore index 187b1328a0..e8f7ea50e6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ tools/.texts-??.xml .fundraising.??.xml .*.xmllist tags/tagged-*.en.xhtml +tags/.tags.??.xml events/????/????.??.xhtml events/????/????.sources events/????/????.xsl diff --git a/Makefile b/Makefile index 7c0dc856f8..0826f2d119 100644 --- a/Makefile +++ b/Makefile @@ -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. # * /..xmllist for each /.sources as well as for each # tags/tagged-.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 diff --git a/build/xslt/get_tags.xsl b/build/xslt/get_tags.xsl index 31161709a0..d431a673de 100644 --- a/build/xslt/get_tags.xsl +++ b/build/xslt/get_tags.xsl @@ -12,10 +12,14 @@ - + + + + + + - - + diff --git a/tags/tags.en.xhtml b/tags/tags.en.xhtml index 835f585be8..652c557ddd 100644 --- a/tags/tags.en.xhtml +++ b/tags/tags.en.xhtml @@ -2,25 +2,18 @@ - FSFE - Tags + Tags - FSFE - - -

Tags

- - -

News

- - -

Events

- - - - $Date: 2011-01-13 15:29:42 +0100 (jeu. 13 janv. 2011) $ $Author: samtuke $ + +

Tags

+ +

News

+ + + +

Events

+ + + - diff --git a/tags/tags.fr.xhtml b/tags/tags.fr.xhtml index 55b65bf435..8502f17f83 100644 --- a/tags/tags.fr.xhtml +++ b/tags/tags.fr.xhtml @@ -2,25 +2,18 @@ - FSFE - Tags + Tags - FSFE - - -

Tags

- - -

Actualités

- - -

Évènements

- - - - $Date: 2011-01-13 15:29:42 +0100 (jeu. 13 janv. 2011) $ $Author: samtuke $ + +

Tags

+ +

Actualités

+ + + +

Évènements

+ + + - diff --git a/tags/tags.nl.xhtml b/tags/tags.nl.xhtml index 2c9d32b213..2c53f8c8a1 100644 --- a/tags/tags.nl.xhtml +++ b/tags/tags.nl.xhtml @@ -1,26 +1,21 @@ + - FSFE - Trefwoorden + Trefwoorden - FSFE + -

Trefwoorden

- - +

Nieuws

- - + + +

Evenementen

- - + + - $Datum: 2011-01-13 15:29:42 +0100 (don. 13 jan. 2011) $ $Auteur: samtuke $ -André Ockers + André Ockers - diff --git a/tags/tags.sources b/tags/tags.sources old mode 100755 new mode 100644 index 335d86153d..939f88afc1 --- a/tags/tags.sources +++ b/tags/tags.sources @@ -1,5 +1 @@ -news/*/news-*:[] -news/*/.news-*:[] -news/nl/nl-*:[] -news/nl/.nl-*:[] -events/*/event-*:[] +tags/.tags:[] diff --git a/tags/tags.xsl b/tags/tags.xsl index 22778fefe8..0786981ac5 100644 --- a/tags/tags.xsl +++ b/tags/tags.xsl @@ -1,65 +1,37 @@ - - + - - - - - - - - - - - - - + + + + - - + + taglist - - -
  • -
    -
    - -
  • -
    -
    - -
  • -
    -
    -
    + + - - -
      - - + + + + tagged- + + .html + + + + + + badge + + + + -
    -
    - - - -
      - - - -
    +
    diff --git a/tools/update_xmllists.sh b/tools/update_xmllists.sh index eeffe8f43e..eb27ee99d7 100755 --- a/tools/update_xmllists.sh +++ b/tools/update_xmllists.sh @@ -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-.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. +# # * /..xmllist for each /.sources as well as for each # tags/tagged-.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 '' | 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 '' | 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 '' + echo '' + echo '' + + 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 " ${label}" + fi + done + done + + echo '' + } > ${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