From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- js/src/doc/lib/common.sh | 23 +++++++++++ js/src/doc/lib/dummy-config.sh | 24 +++++++++++ js/src/doc/lib/extract-watermark.sh | 24 +++++++++++ js/src/doc/lib/make-bibliography.sh | 81 +++++++++++++++++++++++++++++++++++++ js/src/doc/lib/make-watermark.sh | 31 ++++++++++++++ 5 files changed, 183 insertions(+) create mode 100644 js/src/doc/lib/common.sh create mode 100644 js/src/doc/lib/dummy-config.sh create mode 100755 js/src/doc/lib/extract-watermark.sh create mode 100755 js/src/doc/lib/make-bibliography.sh create mode 100755 js/src/doc/lib/make-watermark.sh (limited to 'js/src/doc/lib') diff --git a/js/src/doc/lib/common.sh b/js/src/doc/lib/common.sh new file mode 100644 index 000000000..785f7dec1 --- /dev/null +++ b/js/src/doc/lib/common.sh @@ -0,0 +1,23 @@ +# Common utility functions for js/src/doc scripts. + +# `relative BASE ABSOLUTE` prints the URL relative to BASE that is +# equivalent to ABSOLUTE. BASE must end with a '/'. This function will +# introduce at most one level of '..'. +relative() { + local parent=$(dirname "$1") + case "$2" in + "$1"*) + # ABSOLUTE is within BASE; just remove BASE. + echo "$2" | sed -e "s|^$1||" + ;; + "$parent/"*) + # ABSOLUTE is within BASE/.. + echo "$2" | sed -e "s|^$parent/|../|" + ;; + *) + # ABSOLUTE is unrelated to BASE. + echo "$2" + ;; + esac +} + diff --git a/js/src/doc/lib/dummy-config.sh b/js/src/doc/lib/dummy-config.sh new file mode 100644 index 000000000..dd9d39a4b --- /dev/null +++ b/js/src/doc/lib/dummy-config.sh @@ -0,0 +1,24 @@ +# Dummy definitions of functions used in doc directory config.sh files. +# Scripts reading config.sh files should source this first, and then +# override the definitions of the functions they care about. + +base-url() { + BASE_URL=$1 +} + +markdown() { + INPUT_FILE=$1 + RELATIVE_URL=$2 +} + +label() { + : +} + +absolute-label() { + : +} + +resource() { + : +} diff --git a/js/src/doc/lib/extract-watermark.sh b/js/src/doc/lib/extract-watermark.sh new file mode 100755 index 000000000..9f1de8642 --- /dev/null +++ b/js/src/doc/lib/extract-watermark.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# Extract the js/src/doc watermark from standard input, assumed to be the +# text of a page formatted for publication on MDN. +# +# We can apply this to both the output of the formatter, and to pages +# retrieved from MDN, to see if anything needs to be updated. +# +# Usage: +# +# extract-watermark.sh +# +# For example: +# +# $ curl --silent 'https://developer.mozilla.org/en-US/docs/Tools/Debugger-API' | ./doc/lib/extract-watermark.sh +# sha256:168224ee2d58521b7c8368eddf4ac4fa53a897fa803ae484007af4e61a00ddcd +# $ + +set -eu + +# Since $(foo) trims any final newline in foo's output, this 'echo' ensures +# that our output is terminated by a newline, whether or not curl | sed's +# is. +echo $(sed -n -e "s|.*
\([^<]*\)
.*|\1|p") diff --git a/js/src/doc/lib/make-bibliography.sh b/js/src/doc/lib/make-bibliography.sh new file mode 100755 index 000000000..33068ca9c --- /dev/null +++ b/js/src/doc/lib/make-bibliography.sh @@ -0,0 +1,81 @@ +#!/usr/bin/env bash + +# Generate a Markdown bibliography file --- that is, definitions for +# reference-style link labels --- from a documentation directory's +# config.sh file. +# +# Usage: +# make-bibliography.sh [--mdn] CONFIG CITING-URL +# +# where: +# - CONFIG is the name of the config.sh file to process; and +# - CITING-URL is the absolute URL at which the document using these labels +# will appear. The links we output use URLs relative to CITING-URL to +# refer to the URLs given in CONFIG. +# +# If given the --mdn flag, generate links that are correct for files +# as they appear in format.sh's OUTPUTDIR, not for publishing on MDN. + +set -eu + +mdn=false + +while true; do + case "${1-}" in + '--mdn') + mdn=true + shift + ;; + *) + break + ;; + esac +done + +lib=$(dirname $0) +config=$1 +citing=$2 + +source "$lib/common.sh" + +source "$lib/dummy-config.sh" + +label() { + local label=$1; shift + local fragment= + case "$1" in + '#'*) + fragment=$1; shift + ;; + esac + local title=${1:+ \"$1\"} + + citing_prefix=$(dirname "$citing")/ + if $mdn; then + echo "[$label]: $(relative "$citing_prefix" "$BASE_URL$RELATIVE_URL")$fragment$title" + else + echo "[$label]: ${INPUT_FILE/md/html}$fragment$title" + fi +} + +absolute-label() { + local label=$1 + local absolute_url=$2 + local title=$3 + + echo "[$label]: $absolute_url${title:+ \"$title\"}" +} + +resource() { + local label=$1 file=$2 absolute_url=$3 + + if [ -n "$label" ]; then + if $mdn; then + echo "[$label]: $absolute_url" + else + echo "[$label]: $file" + fi + fi +} + +source "$config" diff --git a/js/src/doc/lib/make-watermark.sh b/js/src/doc/lib/make-watermark.sh new file mode 100755 index 000000000..a39ff5436 --- /dev/null +++ b/js/src/doc/lib/make-watermark.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +# Generate an HTML watermark for the given file. Claim the text was +# generated from SOURCE. +# +# Usage: +# +# make-watermark.sh FILE SOURCE + +set -eu + +# Include the watermark as visible text in the page, as suggested in bug 990662. + +echo '

Source Metadata

' +echo '
' +echo '
Generated from file:
' +echo "
$2
" +echo '
Watermark:
' +echo "
sha256:$(cat "$1" | shasum -a 256 | sed 's/ .*$//')
" + +# If we have Mercurial changeset ID, include it. +if [ "${JS_DOC_HG_IDENTIFY:+set}" = set ]; then + # If the changeset ID has a '+' on the end (indicating local + # modifications), omit that from the link. + cat <Changeset: +
${JS_DOC_HG_IDENTIFY}
+EOF +fi + +echo '
' -- cgit v1.2.3