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: add an option to use a local CSS file
# 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() {
echo 'usage: tamias [-c cachedir] [-l lang] <url>'
}
@ -53,33 +58,46 @@ if [ -z "$url" ]; then
exit 1
fi
getname() {
url="$1"
#echo "$url"
name=$(echo "$url" | rev | cut -d'/' -f 1 | rev)
if [ "$name" = "" ]; then
name=$(echo "$url" | rev | cut -d'/' -f 2 | rev)
fi
originalname="$name"
i=1
while :; do
if [ -e "$name" ] || [ -e "$name.orig" ]; then
name="$originalname$i"
else
break
fi
i=$(echo "$i+1" | bc)
done
echo "$name"
}
mkdir -p "$CACHEDIR"
cd "$CACHEDIR"
# get name
name=$(echo "$url" | rev | cut -d'/' -f 1 | rev)
if [ "$name" = "" ]; then
name=$(echo "$url" | rev | cut -d'/' -f 2 | rev)
fi
name=$(getname "$url")
echo "$name"
originalname="$name"
i=1
while :; do
if [ -e "$name" ] || [ -e "$name.orig" ]; then
name="$originalname$i"
else
break
fi
i=$(echo "$i+1" | bc)
done
# download original
curl -s "$url" > "$name.orig"
readability-cli "$url" > "$name"
# cut the first line - bug of readability-cli
readable=$(tail +2 "$name")
# use readability on it
readable=$(readability-cli "$url")
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>
<html lang="'"$lang"'">
@ -91,7 +109,6 @@ echo '<!DOCTYPE html>
</head>
<body class="container">
' > "$name"
# cut the first line - bug of readability-cli
echo "$readable" >> "$name"
echo '
</body>