summaryrefslogtreecommitdiff
path: root/src/set-stylesheet.sh
diff options
context:
space:
mode:
authorlshprung <lshprung@tutanota.com>2023-06-28 16:06:59 -0700
committerGitHub <noreply@github.com>2023-06-28 16:06:59 -0700
commitbc624ea5f8fe4cfc6ea0a44d483ba57cb07cfcd6 (patch)
treefc923bca398566dec0b49bcc099bfcda97132c21 /src/set-stylesheet.sh
parenta4784bbacc356d381ff833e1c181b75c30f776c6 (diff)
parent0779d60460d99f8f950fd97bcef897ba6cbf1b8a (diff)
Merge pull request #1 from lshprung/local-css
Download and package (or disable) CSS as part of docset
Diffstat (limited to 'src/set-stylesheet.sh')
-rwxr-xr-xsrc/set-stylesheet.sh44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/set-stylesheet.sh b/src/set-stylesheet.sh
new file mode 100755
index 0000000..c2345a4
--- /dev/null
+++ b/src/set-stylesheet.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/sh
+
+unset LOCAL_CSS_PATH
+unset WEB_CSS_PATH
+CSS="$1"
+shift
+
+get_css_path() {
+ # Used to set WEB_CSS_PATH
+ pup "link[rel=stylesheet] attr{href}" -f "$1"
+}
+
+stylesheet_replace() {
+ # Replace each stylesheet href value with LOCAL_CSS_PATH
+ while [ -n "$1" ]; do
+ sed -i 's|'"$(pup link[rel=stylesheet] -f "$1")"'|<link rel="stylesheet" type="text/css" href="manual.css">|g' "$1"
+ shift
+ done
+}
+
+stylesheet_remove() {
+ # Remove the stylesheet link
+ while [ -n "$1" ]; do
+ sed -i 's|'"$(pup link[rel=stylesheet] -f "$1")"'||g' "$1"
+ shift
+ done
+}
+
+if [ "$CSS" = "yes" ]; then
+ WEB_CSS_PATH="$(get_css_path "$1")"
+ if [ -n "$WEB_CSS_PATH" ]; then
+ LOCAL_CSS_PATH="$(dirname "$1")"/manual.css
+ curl -o "$LOCAL_CSS_PATH" "$WEB_CSS_PATH"
+ fi
+ if [ -r "$LOCAL_CSS_PATH" ]; then
+ stylesheet_replace "$@"
+ else
+ CSS="no"
+ fi
+fi
+
+if [ "$CSS" = "no" ]; then
+ stylesheet_remove "$@"
+fi