Branch: refs/heads/master Author: Dominic Hopf dmaphy@googlemail.com Committer: Dominic Hopf dmaphy@googlemail.com Date: Tue, 16 Apr 2013 22:48:43 UTC Commit: 04922cba9c053ed8cfaf0ace808bc45159dc579c https://github.com/geany/plugins.geany.org/commit/04922cba9c053ed8cfaf0ace80...
Log Message: ----------- Merge pull request #3 from vmkononenko/master
Changed plugin pages generation concept
Modified Paths: -------------- gencontent.sh
Modified: gencontent.sh 398 files changed, 264 insertions(+), 134 deletions(-) =================================================================== @@ -8,8 +8,8 @@ # plugins.geany.org website # # (C) Copyright 2010 by Dominic Hopf dmaphy@googlemail.com -# Version: 1.1.1 -# Last Change: 2011-12-17 +# Version: 1.2.0 +# Last Change: 2013-04-15
# This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,6 +25,14 @@ # along with this program. If not, see http://www.gnu.org/licenses/.
# ChangeLog: +# 2013-04-15 Volodymyr Kononenko vm@kononenko.ws +# * the plugin listing (left side navigation bar) is now being generated +# from all plugins, available in master branch +# * if the plugin had different page in previous Geany versions, these +# pages are also being generated. Links to them are included in the +# bottom of plugin page +# * fixed checking exceptions in EXCLUDE_PLUGINS +# # 2011-12-17 Dominic Hopf dmaphy@googlemail.com # * generate .html files from READMEs for the latest Geany-Plugins version # instead of git master @@ -47,169 +55,291 @@ # missing!
# SOURCESDIR is the directory, where the README files will be found -SOURCESDIR=$HOME"/.tmp/geany-plugins/" +SOURCESDIR=${HOME}"/.tmp/geany-plugins/" + +WORKDIR=$(pwd)"/"
# CONTENTDIR is the directory, where the generated HTML files will be put -CONTENTDIR="./content/" +CONTENTDIR=${WORKDIR}"content/"
# LOGDIR is the directory where to put any logfiles and information about the # generation of the content files -LOGDIR="./gencontent_logs/" +LOGDIR=${WORKDIR}"gencontent_logs/"
# plugins to exclude from the nightly re-generation via rst2html because they # have a separate HTML page not generated from the README file -EXCLUDE_PLUGINS=( geanylatex geanysendmail geanylua ) +declare -a EXCLUDE_PLUGINS=( geanylatex geanysendmail geanylua ) + +RST2HTML=$(which rst2html) +TIDY=$(which tidy) + +# List of plugins, available in the letest release +declare -a RELEASE_PLUGIN_LIST
-RST2HTML="/usr/bin/rst2html" -TIDY="/usr/bin/tidy" +# List of plugins, available in the letest release +declare -a MASTER_PLUGIN_LIST
if [ ! -x "$RST2HTML" ] then - echo "rst2html not found. Exiting." - exit 127 + echo "rst2html not found. Exiting." + exit 127 fi
if [ ! -x "$TIDY" ] then - echo "tidy not found. Exiting." - exit 127 + echo "tidy not found. Exiting." + exit 127 fi
-# small function to check an array if an element is included in_array() { - NEEDLE=$1 - shift - - # search for the NEEDLE $1 in the haystack $@ - for j in $@; - do - if [ $NEEDLE == $j ]; then - return 0; - fi; - done; - - return 1; + declare -a arr=("${!2}") + found=0 + + for i in "${arr[@]}" + do + if [ "${i}" == "$1" ]; then + found=1 + fi + done + + return ${found} }
-if [ ! -d $SOURCESDIR ]; then - echo -e "Directory containing sources $SOURCESDIR could not be found. Trying to clone from git...\n" - git clone git://github.com/geany/geany-plugins.git $SOURCESDIR -fi +function prepare_source_dir() +{ + if [ ! -d "${SOURCESDIR}" ]; then + echo -e "Directory containing sources $SOURCESDIR could not be found.\nTrying to clone from git...\n" + git clone git://github.com/geany/geany-plugins.git ${SOURCESDIR} + fi + + if [ $? -ne 0 ]; then + echo "git clone failed. Exiting..." + exit 1 + fi +}
-cd $SOURCESDIR - -echo "Checking out master branch..." -git checkout master -echo "Updating master branch..." -git pull - -VERSION=`git tag -l | tail -n1` -echo "Found latest Geany-Plugins version: $VERSION." - -git branch | grep $VERSION - -if [ $? -ne 0 ]; then - echo "A local branch does not exist for $VERSION." - echo "Checking if $VERSION exists remote.." - UPSTREAM=`git branch -r | grep $VERSION` - - if [ $? -eq 0 ]; then - echo "Remote branch $UPSTREAM found. Checking out..." - git checkout -b $VERSION $UPSTREAM - else - echo "Could not find a remote branch. Checking out the tag $VERSION..." - git checkout $VERSION > /dev/null - fi -else - echo "A local branch exists for $VERSION. Updating..." - git checkout $VERSION && git pull -fi
-cd - > /dev/null +function prepare_content_dir() +{ + if [ ! -d "${CONTENTDIR}" ]; then + echo -e "Directory containing contents $CONTENTDIR could not be found!\n" + exit 1 + fi +}
-if [ ! -d $CONTENTDIR ]; then - echo -e "Directory containing contents $CONTENTDIR could not be found!\n" - exit 1 -fi +function prepare_log_dir() +{ + mkdir -p ${LOGDIR} +} + + +function add_to_navigation() +{ + dir=$1 + title=$(echo ${dir} | sed 's/([a-z])([a-zA-Z0-9]*)/\u\1\2/g') + echo "<li><a href="${dir}.html">${title}</a></li>" >> "${CONTENTDIR}geany-plugins-listing.html" +}
-mkdir -p $LOGDIR - - -# reset geany-plugins-listing.html, the file which is included as navigation -rm -f $CONTENTDIR"geany-plugins-listing.html" -touch $CONTENTDIR"geany-plugins-listing.html" - -for i in `ls $SOURCESDIR`; -do - if [ -d $SOURCESDIR$i -a $i"x" != "buildx" -a $i"x" != "pox" ]; then - # check if the current plugin is included in the exclusion-list... - in_array $i ${EXCLUDE_PLUGINS[@]} - - if [ $? -eq 0 ]; then # ... if yes, ... - # ... add it to the navigation ... - title=`echo ${i} | sed 's/([a-z])([a-zA-Z0-9]*)/\u\1\2/g'` - echo "<li><a href="$i.html">${title}</a></li>" >> $CONTENTDIR"geany-plugins-listing.html" - continue # ... and jump to the next one - fi; - - LOGFILE=$LOGDIR$i"_log_"`date "+%Y-%m-%d"` - - echo -e "Generating content file $i.html...\n\n" > $LOGFILE - - if [ -s $SOURCESDIR$i/README ]; then - # TODO: there is still output from rst2html to the shell, that ideally should'nt be - # TODO: newer versions of rst2html may face problems with the configuration files encoding - $RST2HTML -s --config=$CONTENTDIR"rst2html_config.conf" $SOURCESDIR$i/README > .README.html 2> $LOGFILE - title=`echo ${i} | sed 's/([a-z])([a-zA-Z0-9]*)/\u\1\2/g'` - echo "<li><a href="$i.html">${title}</a></li>" >> $CONTENTDIR"geany-plugins-listing.html" - - if [ $? -ne 0 ]; then - echo -e "$RST2HTML exited with $?.\n\n" - continue - fi - else - echo -e "File $SOURCESDIR$i/README not found.\nYou might want to have a look whats up there.\nCopying no-readme-template instead.." - cp "./templates/no-readme-template.html" $CONTENTDIR$i.html - sed -i "s/{plugin_name}/$i/g" $CONTENTDIR$i.html - continue - fi - echo -e "\n\n" >> $LOGFILE - - - $TIDY -config $CONTENTDIR"tidy.conf" .README.html >> $LOGFILE 2>&1 - case "$?" in - 1) - echo -e "$TIDY exited with 1, There were warnings." - ;; - 2) - echo "$TIDY exited with 2. There were errors.\n\n" - continue - ;; - *) - echo -e "$TIDY exited with $?. Everything should be fine.\n" - ;; - esac - echo -e "Result:\t$CONTENTDIR$i.html\nLog:\t$LOGFILE\n" - echo -e "\n\n" >> $LOGFILE - - # since tidy just outputs spaces, not tabs, we'll replace those spaces - # with tabs again ourself - sed -i "s/ /\t/g" .README.html - cp .README.html $CONTENTDIR$i.html - echo -e "\n\n" >> $LOGFILE - - fi # if [ -d $SOURCESDIR$i -a $i"x" != "buildx" -a $i"x" != "pox" ]; -done - -echo "Switching back to master branch..." -git checkout master +function is_plugin() +{ + f=$1 + cd ${SOURCESDIR} + if [ -d "${f}" ] && [ "${f}x" != "buildx" ] && [ "${f}x" != "pox" ]; then + return 1 + else + return 0 + fi +} + + +# Generates geany-plugins-listing.html - the file which is included as navigation +function gen_plugins_listing_html() +{ + cd ${SOURCESDIR} + + echo "Checking out master branch..." + git checkout master + echo "Updating master branch..." + git pull + + cd ${WORKDIR} + + # reset old geany-plugins-listing.html + rm -f ${CONTENTDIR}"geany-plugins-listing.html" + + for dir in $(ls ${SOURCESDIR}) + do + is_plugin ${dir} + if [ $? -eq 1 ]; then + add_to_navigation ${dir} + MASTER_PLUGIN_LIST+=("${dir}") + fi + done +} + + +function gen_html_from_readme() +{ + plugin="$1" + dir="$2" + LOGFILE="${LOGDIR}${plugin}_log_"$(date "+%Y-%m-%d") + + cd ${CONTENTDIR} + # TODO: newer versions of rst2html may face problems with the configuration files encoding + $RST2HTML -s --config=${CONTENTDIR}"rst2html_config.conf" ${SOURCESDIR}${plugin}/README ${SOURCESDIR}.README.html 2> $LOGFILE + cd - > /dev/null + + retcode=$? + if [ ${retcode} -ne 0 ]; then + echo -e "$RST2HTML exited with ${retcode}.\n\n" + fi + + $TIDY -config ${WORKDIR}tidy.conf .README.html >> $LOGFILE 2>&1 + case "$?" in + 1) + echo -e "$TIDY exited with 1. There were warnings." + ;; + 2) + echo "$TIDY exited with 2. There were errors.\n\n" + ;; + *) + echo -e "$TIDY exited with $?. Everything should be fine.\n" + ;; + esac + echo -e "Result:\t${dir}${plugin}.html\nLog:\t${LOGFILE}\n" + echo -e "\n\n" >> $LOGFILE + + # since tidy just outputs spaces, not tabs, we'll replace those spaces + # with tabs again ourself + sed -i "s/ /\t/g" .README.html + cp .README.html ${dir}${plugin}.html + echo -e "\n\n" >> ${LOGFILE} +} + + +function gen_plugin_pages() +{ + cd $SOURCESDIR + for fname in $(ls ${SOURCESDIR}) + do + is_plugin ${fname} + if [ $? -ne 1 ]; then + continue + fi + + RELEASE_PLUGIN_LIST+=(${fname}) + + in_array ${fname} EXCLUDE_PLUGINS[@] + if [ $? -eq 1 ]; then + continue + fi + + prevtag="" + for tag in $(git tag | tac) + do + git checkout -q ${tag} + if [ ${tag} == $(git tag | tail -n 1) ]; then + if [ -s ${SOURCESDIR}${fname}/README ]; then + gen_html_from_readme ${fname} ${CONTENTDIR} + else + echo -e "File ${SOURCESDIR}${fname}/README not found.\nYou might want to have a look whats up there.\nCopying no-readme-template instead." + cp ${WORKDIR}/templates/no-readme-template.html ${CONTENTDIR}${fname}.html + sed -i "s/{plugin_name}/${fname}/g" ${CONTENTDIR}${fname}.html + prevtag=${tag} + continue + fi + else + diff=$(git diff ${prevtag} -- ${fname}/README) + if [ -n "${diff}" ]; then + # diff output is not empty + mkdir -p ${CONTENTDIR}${tag} + gen_html_from_readme ${fname} ${CONTENTDIR}${tag}"/" + fi + fi + prevtag=${tag} + done + + git checkout -q $(git tag | tail -n 1) + done +} + + +# The function generates pages for plugins, which are missing in release +# but are present in master branch +function gen_new_plugins_pages() +{ + git checkout master + for plugin in ${MASTER_PLUGIN_LIST[@]} + do + in_array ${plugin} RELEASE_PLUGIN_LIST[@] + if [ $? -eq 0 ]; then + gen_html_from_readme ${plugin} ${CONTENTDIR} + fi + done +} + + +function add_links_to_old_pages() +{ + declare -A header_added + for plugin in ${RELEASE_PLUGIN_LIST[@]} + do + header_added["${plugin}"]=0 + done + + for tag in $(ls ${CONTENTDIR}) + do + if [ ! -d ${CONTENTDIR}${tag} ]; then + # this is not dir with old pages. Skip it + continue + fi + for plugin in $(ls ${CONTENTDIR}${tag} | awk -F'.' '{print $1}') + do + if [ ${header_added[${plugin}]} -eq 0 ]; then + # Adding header + echo -e "<div class="section" id="docs-for-previous-versions">\n<h3>\nDocs for previous versions\n</h3>\n<p>\n<ul>\n" >> ${CONTENTDIR}${plugin}.html + header_added["${plugin}"]=1 + fi + echo -e "<li><a href="index.php?site=${tag}/${plugin}">${tag}</a></li>\n" >> ${CONTENTDIR}${plugin}.html + done + done + + # closing opened tags + for plugin in "${!header_added[@]}" + do + if [ ${header_added[${plugin}]} -eq 1 ]; then + echo -e "</ul>\n</p>\n</div>" >> ${CONTENTDIR}${plugin}.html + $TIDY -config ${WORKDIR}tidy.conf ${CONTENTDIR}${plugin}.html > /dev/null 2>&1 + fi + done +} +
# clean up any unneccessary files -find $LOGDIR -mtime +7 -delete # delete logfiles older than 7 days +function clean_up() +{ + # delete logfiles older than 7 days + find $LOGDIR -mtime +7 -delete +} + + +function main() +{ + prepare_source_dir + prepare_content_dir + prepare_log_dir + gen_plugins_listing_html + gen_plugin_pages + gen_new_plugins_pages + add_links_to_old_pages + clean_up +} + +main
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
plugins-commits@lists.geany.org