1
0
Fork 0
easejs/tools/webdoc

94 lines
3.0 KiB
Plaintext
Raw Permalink Normal View History

#!/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.
#
# Copyright (C) 2012, 2013 Free Software Foundation, Inc.
#
# 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/>.
#
# This will produce documentation in the following format:
# manual/ multi-page HTML
# manual/easejs.html single-page HTML
##
path_dest=webroot/manual
path_doc="$(pwd)/doc-cp"
path_img="$path_doc/img"
path_js="$path_doc/interactive.js"
path_doc_multi="$path_doc/easejs.html"
# style a particular file, rewriting relevant portions of the HTML
webify()
{
docpath="$1"
root="$2"
tmp="$1.tmp"
# 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)
shref='sed \"s#\\(src\\|href\\)=\\\"\\([^\\\"]\\+\\)\\\"#'
shref="$shref"'\\1=\\\"'"$root"'\\2\\\"#g\"'
shref="$shref | sed 's#//\\\"#\\\"#g'"
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/&#;
s#</body>#\n&#;
' "$docpath" \
| awk '
/<body/ {
print "<body class=\"manual\" lang=\"en\">";
system( "awk \"/body/{i=1;next;} i\" includes/header.html | '"$shref"'" );
next
}
/<\/body>/ {
system( "cat includes/footer.html | '"$shref"'" );
exit
}
{ print }
' \
> "$tmp"
# overwrite file with changes
mv "$tmp" "$docpath"
}
# generate the documentation from the master branch
(
cd .. \
&& autoreconf -fvi \
&& ./configure \
&& make html html-single \
&& cp -rl doc "$path_doc"
) \
&& pwd \
&& ln -sfv "$path_doc/easejs-single.html" "$path_doc_multi/easejs.html" \
&& for path in $( find "$path_doc_multi" -name '*.htm?' )
do
webify "$path" "../"
done \
&& ln -sfv "$path_doc_multi" "$path_dest" \
&& ln -sfv "$path_img" "$path_js" "$path_dest/"