2012-05-07 21:40:32 -04:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Styles documentation, generated from master, to match the rest of the website
|
|
|
|
#
|
|
|
|
# What a relief. This also allows the documentation that is generated separately
|
|
|
|
# (apart from the website) to have its own style; that makes sense, considering
|
|
|
|
# the master branch should have no knowledge of the website.
|
|
|
|
#
|
2014-04-09 19:49:00 -04:00
|
|
|
# Copyright (C) 2012, 2013 Free Software Foundation, Inc.
|
2012-05-07 21:40:32 -04:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-12-24 15:07:06 -05:00
|
|
|
#
|
|
|
|
# This will produce documentation in the following format:
|
|
|
|
# manual/ multi-page HTML
|
|
|
|
# manual/easejs.html single-page HTML
|
2012-05-07 21:40:32 -04:00
|
|
|
##
|
|
|
|
|
|
|
|
# ensure that we are within the git repository (otherwise, we cannot generate
|
|
|
|
# content from master)
|
|
|
|
git rev-parse --git-dir >/dev/null 2>/dev/null || {
|
|
|
|
echo "This command may only be run from within the git repository" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# we do not want to switch branches if it may risk losing changes
|
|
|
|
[ "$( git status --short | grep -v '??' )" ] && {
|
|
|
|
# auto-stashing can be used during development to test this script without
|
|
|
|
# fighting with git
|
|
|
|
if [ -z "$WEBDOC_AUTOSTASH" ]; then
|
|
|
|
echo "Working tree is dirty; please stash or commit changes" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
# automatically stash changes
|
|
|
|
echo "Stashing changes before switching branches..." >&2
|
|
|
|
git stash save 'Stashed by webdoc'
|
|
|
|
|
|
|
|
# on exit, pop the stash
|
|
|
|
trap 'git stash pop' EXIT
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-24 23:57:36 -05:00
|
|
|
path_dest=webroot/manual
|
|
|
|
path_doc=doc-cp
|
2012-05-07 21:40:32 -04:00
|
|
|
path_img=$path_doc/img
|
|
|
|
path_js=$path_doc/interactive.js
|
2013-12-24 23:57:36 -05:00
|
|
|
path_doc_multi=$path_doc/easejs.html
|
2012-05-07 21:40:32 -04:00
|
|
|
|
|
|
|
# style a particular file, rewriting relevant portions of the HTML
|
|
|
|
webify()
|
|
|
|
{
|
|
|
|
docpath="$1"
|
|
|
|
root="$2"
|
|
|
|
tmp="$1.tmp"
|
|
|
|
|
2012-05-08 19:06:24 -04:00
|
|
|
# if necessary, rewrite links to point to the proper directory (we do not use
|
|
|
|
# absolute paths, as that is not friendly to viewing the documentation on a
|
|
|
|
# filesystem)
|
2013-12-24 19:31:57 -05:00
|
|
|
shref='sed \"s#\\(src\\|href\\)=\\\"\\([^\\\"]\\+\\)\\\"#'
|
|
|
|
shref="$shref"'\\1=\\\"'"$root"'\\2\\\"#g\"'
|
2012-05-08 19:06:24 -04:00
|
|
|
shref="$shref | sed 's#//\\\"#\\\"#g'"
|
|
|
|
|
2012-05-07 21:40:32 -04:00
|
|
|
echo "Styling $path..."
|
|
|
|
|
|
|
|
# We do not use -i here because we have some piping to do. We also use a $root
|
|
|
|
# var in place of a simple "/" prefix to permit this page to be viewed
|
|
|
|
# anywhere --- not just on the root of a domain.
|
|
|
|
sed '
|
|
|
|
s#</head>#<link type="text/css" rel="stylesheet" \
|
|
|
|
href="'$root'style.css" />\n&#;
|
|
|
|
s#highlight\.pack\.js#'$root'scripts/&#;
|
2012-05-07 23:50:24 -04:00
|
|
|
s#</body>#\n&#;
|
2012-05-07 21:40:32 -04:00
|
|
|
' "$docpath" \
|
|
|
|
| awk '
|
|
|
|
/<body>/ {
|
2013-12-25 02:07:33 -05:00
|
|
|
print "<body class=\"manual\">";
|
2012-05-08 19:06:24 -04:00
|
|
|
system( "awk \"/body/{i=1;next;} i\" includes/header.html | '"$shref"'" );
|
2012-05-07 21:40:32 -04:00
|
|
|
next
|
|
|
|
}
|
|
|
|
/<\/body>/ {
|
2012-05-08 19:06:24 -04:00
|
|
|
system( "cat includes/footer.html | '"$shref"'" );
|
2012-05-07 23:50:24 -04:00
|
|
|
exit
|
2012-05-07 21:40:32 -04:00
|
|
|
}
|
2012-05-07 23:50:24 -04:00
|
|
|
{ print }
|
2012-05-07 21:40:32 -04:00
|
|
|
' \
|
|
|
|
> "$tmp"
|
|
|
|
|
|
|
|
# overwrite file with changes
|
|
|
|
mv "$tmp" "$docpath"
|
|
|
|
}
|
|
|
|
|
|
|
|
# generate the documentation from the master branch
|
2014-04-29 03:14:46 -04:00
|
|
|
git checkout "${WEBDOC_BRANCH:-master}" \
|
2013-12-24 22:41:50 -05:00
|
|
|
&& autoreconf -fvi \
|
|
|
|
&& ./configure \
|
2013-12-24 23:57:36 -05:00
|
|
|
&& make html html-single \
|
|
|
|
&& cp -rl doc "$path_doc" \
|
2012-05-07 21:40:32 -04:00
|
|
|
&& git checkout - \
|
2013-12-24 23:57:36 -05:00
|
|
|
&& ln -sf "../easejs-single.html" "$path_doc_multi/easejs.html" \
|
2012-05-07 21:40:32 -04:00
|
|
|
&& for path in $( find "$path_doc_multi" -name '*.htm?' )
|
|
|
|
do
|
|
|
|
webify "$path" "../"
|
|
|
|
done \
|
2013-12-24 23:57:36 -05:00
|
|
|
&& ln -sf "../$path_doc_multi" "$path_dest" \
|
|
|
|
&& ln -sf "../../$path_img" "../../$path_js" "$path_dest/"
|