Change readability-cli dependency

This commit is contained in:
Paper 2020-07-10 14:49:08 +02:00
parent 8669118246
commit 8fe2bda48c
1 changed files with 38 additions and 21 deletions

View File

@ -9,7 +9,12 @@
# TODO: extract txt-only/markdown # TODO: extract txt-only/markdown
# TODO: add an option to use a local CSS file # TODO: add an option to use a local CSS file
# TODO: add an option to embed a CSS file inside the HTML # TODO: add an option to embed a CSS file inside the HTML
# dependencies: curl, readability-cli (https://github.com/dergigi/readability-cli) # TODO: check if dependencies are installed
# TODO: replace readability-cli with something better
# dependencies:
# - curl
# - readability-cli (https://git.tilde.institute/paper/readability-cli)
usage() { usage() {
echo 'usage: tamias [-c cachedir] [-l lang] <url>' echo 'usage: tamias [-c cachedir] [-l lang] <url>'
} }
@ -53,15 +58,13 @@ if [ -z "$url" ]; then
exit 1 exit 1
fi fi
mkdir -p "$CACHEDIR" getname() {
cd "$CACHEDIR" url="$1"
#echo "$url"
# get name
name=$(echo "$url" | rev | cut -d'/' -f 1 | rev) name=$(echo "$url" | rev | cut -d'/' -f 1 | rev)
if [ "$name" = "" ]; then if [ "$name" = "" ]; then
name=$(echo "$url" | rev | cut -d'/' -f 2 | rev) name=$(echo "$url" | rev | cut -d'/' -f 2 | rev)
fi fi
echo "$name"
originalname="$name" originalname="$name"
i=1 i=1
@ -73,13 +76,28 @@ while :; do
fi fi
i=$(echo "$i+1" | bc) i=$(echo "$i+1" | bc)
done done
echo "$name"
}
mkdir -p "$CACHEDIR"
cd "$CACHEDIR"
name=$(getname "$url")
echo "$name"
# download original # download original
curl -s "$url" > "$name.orig" curl -s "$url" > "$name.orig"
readability-cli "$url" > "$name" # use readability on it
# cut the first line - bug of readability-cli readable=$(readability-cli "$url")
readable=$(tail +2 "$name")
images=$(echo "$readable" | pup img 'attr{src}' | sort -u)
echo "$images"
for image in $images; do
imgname="$(getname "$image")"
echo "$imgname"
curl -s "$image" > "$imgname"
done
echo '<!DOCTYPE html> echo '<!DOCTYPE html>
<html lang="'"$lang"'"> <html lang="'"$lang"'">
@ -91,7 +109,6 @@ echo '<!DOCTYPE html>
</head> </head>
<body class="container"> <body class="container">
' > "$name" ' > "$name"
# cut the first line - bug of readability-cli
echo "$readable" >> "$name" echo "$readable" >> "$name"
echo ' echo '
</body> </body>