summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorShaun McCance <shaunm@gnome.org>2015-06-18 20:31:02 -0400
committerShaun McCance <shaunm@gnome.org>2015-06-18 20:31:02 -0400
commit1ad0853ee662ae67d52107949f2cebb7f13ec772 (patch)
tree415ee64ba31b1b07c1e1ece36933d0d7cffe5c3e /tools
parent52f6a118201328ab89b4acbfd5818d5592e2a57e (diff)
downloadyelp-tools-1ad0853ee662ae67d52107949f2cebb7f13ec772.tar.gz
yelp-check: Support Mallard Sites for hrefs
Diffstat (limited to 'tools')
-rwxr-xr-xtools/yelp-check.in118
1 files changed, 61 insertions, 57 deletions
diff --git a/tools/yelp-check.in b/tools/yelp-check.in
index 91b7289..05de8fc 100755
--- a/tools/yelp-check.in
+++ b/tools/yelp-check.in
@@ -128,6 +128,9 @@ yelp_usage_hrefs () {
echo ""
echo " Find broken href links in FILES in a Mallard document, or"
echo " broken ulink or XLink links in FILES in a DocBook document."
+ echo ""
+ echo "Options:"
+ echo " -s Treat pages as belonging to a Mallard site"
) 1>&2
}
yelp_usage_ids () {
@@ -274,54 +277,60 @@ yelp_check_iter_args () {
elif [ "x$check_db" != "x" -a \( "x$ext" = "xdocbook" -o "x$ext" = "xxml" \) ]; then
$check_db "$arg" || yelp_check_retval="$?"
else
- echo "Unrecognized page $arg" 2>&1
+ echo "Unrecognized page $arg" 1>&2
exit 1
fi
done
return $yelp_check_retval
}
-yelp_hrefs_db () {
- (
- echo '<xsl:stylesheet'
- echo ' xmlns:xsl="http://www.w3.org/1999/XSL/Transform"'
- echo ' xmlns:db="http://docbook.org/ns/docbook"'
- echo ' xmlns:xlink="www.w3.org/1999/xlink"'
- echo ' version="1.0">'
- echo '<xsl:output method="text"/>'
- echo '<xsl:template match="/">'
- echo '<xsl:for-each select="//ulink/@url | //*/xlink:href">'
- echo '<xsl:if test="not(starts-with(string(.), '\''mailto:'\''))">'
- echo '<xsl:value-of select="(ancestor-or-self::*/@id | ancestor-or-self::*/@xml:id)[last()]"/>'
- echo '<xsl:text> </xsl:text>'
- echo '<xsl:value-of select="string(.)"/>'
- echo '<xsl:text>&#x000A;</xsl:text>'
- echo '</xsl:if>'
- echo '</xsl:for-each>'
- echo '</xsl:template>'
- echo '</xsl:stylesheet>'
- ) | xsltproc --xinclude - "$1"
-}
-
yelp_hrefs_page () {
+ base=$(dirname "$1")
+ if [ "x$check_site" = "x1" ]; then
+ sdir=$(cd $(dirname "$1") && pwd)
+ sdir=${sdir##${check_site_root}}/
+ fi
(
echo '<xsl:stylesheet'
echo ' xmlns:xsl="http://www.w3.org/1999/XSL/Transform"'
echo ' xmlns:mal="http://projectmallard.org/1.0/"'
+ echo ' xmlns:db="http://docbook.org/ns/docbook"'
+ echo ' xmlns:xlink="www.w3.org/1999/xlink"'
echo ' version="1.0">'
echo '<xsl:output method="text"/>'
echo '<xsl:template match="/mal:page">'
- echo '<xsl:for-each select="//*[@href]">'
- echo '<xsl:if test="not(starts-with(@href, '\''mailto:'\''))">'
- echo '<xsl:value-of select="/mal:page/@id"/>'
- echo '<xsl:text> </xsl:text>'
- echo '<xsl:value-of select="@href"/>'
- echo '<xsl:text>&#x000A;</xsl:text>'
- echo '</xsl:if>'
- echo '</xsl:for-each>'
+ echo ' <xsl:for-each select="//*[@href]">'
+ echo ' <xsl:if test="not(starts-with(@href, '\''mailto:'\''))">'
+ echo ' <xsl:value-of select="/mal:page/@id"/>'
+ echo ' <xsl:text> </xsl:text>'
+ echo ' <xsl:value-of select="@href"/>'
+ echo ' <xsl:text>&#x000A;</xsl:text>'
+ echo ' </xsl:if>'
+ echo ' </xsl:for-each>'
+ echo '</xsl:template>'
+ echo '<xsl:template match="/*[namespace-uri(.) = '\'\''] | /db:*">'
+ echo ' <xsl:for-each select="//ulink/@url | //*/xlink:href">'
+ echo ' <xsl:if test="not(starts-with(string(.), '\''mailto:'\''))">'
+ echo ' <xsl:value-of select="(ancestor-or-self::*/@id | ancestor-or-self::*/@xml:id)[last()]"/>'
+ echo ' <xsl:text> </xsl:text>'
+ echo ' <xsl:value-of select="string(.)"/>'
+ echo ' <xsl:text>&#x000A;</xsl:text>'
+ echo ' </xsl:if>'
+ echo ' </xsl:for-each>'
echo '</xsl:template>'
echo '</xsl:stylesheet>'
- ) | xsltproc --xinclude - "$1"
+ ) | xsltproc --xinclude - "$1" | sort | uniq | \
+ while read id url; do
+ colon=`echo "$url" | cut -d: -f1`
+ if [ "x$colon" = "x$url" ]; then
+ test -f "$base/"$(urldecode "$url") || echo "$sdir$id: $url"
+ else
+ (curl -s -I -L "$url" | \
+ grep '^HTTP/' | tail -n 1 | head -n 1 | \
+ grep -q 'HTTP/.\.. 200 .*') || \
+ echo "$sdir$id: $url"
+ fi
+ done
}
yelp_hrefs () {
@@ -329,32 +338,27 @@ yelp_hrefs () {
yelp_usage_hrefs
exit 1
fi
+ while [ "$#" != "0" ]; do
+ case "$1" in
+ "-s")
+ check_site="1"
+ check_site_root=$(pwd)
+ shift
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
+ if [ "$#" = "0" -o "x$1" = "x--help" -o "x$1" = "x-h" ]; then
+ yelp_usage_hrefs
+ exit 1
+ fi
check_out_file=`mktemp "${TMPDIR:-/tmp}"/yelp-XXXXXXXX`
- for xml in "$@"; do
- if [ -d "$xml" ]; then
- for page in "$xml"/*.page; do
- yelp_hrefs_page "$page"
- done
- else
- ext=`echo "$1" | sed -e 's/.*\.//'`
- if [ "x$ext" = "xxml" -o "x$ext" = "xdocbook" ]; then
- yelp_hrefs_db "$xml"
- else
- yelp_hrefs_page "$xml"
- fi
- fi | while read id url; do
- echo "`dirname $xml`" "$id" "$url"
- done
- done | sort | uniq | while read base id url; do
- colon=`echo "$url" | cut -d: -f1`
- if [ "x$colon" = "x$url" ]; then
- test -f "$base/`urldecode $url`" || echo "$id: $url"
- else
- (curl -s -I -L "$url" | grep '^HTTP/' | tail -n 1 | head -n 1 | grep -q 'HTTP/.\.. 200 .*') ||
- echo "$id: $url"
- fi
- done > "$check_out_file"
- ret=`cat "$check_out_file" | wc -l`
+ check_db=yelp_hrefs_page
+ check_page=yelp_hrefs_page
+ yelp_check_iter_args $@ > "$check_out_file"
+ ret=$(cat "$check_out_file" | wc -l)
if test "x$ret" != "x0"; then ret="1"; fi
cat "$check_out_file"
rm "$check_out_file"