Compare commits

...

2 Commits

Author SHA1 Message Date
Paper 398480a229 Update README.md 2020-07-10 14:52:19 +02:00
Paper 8fe2bda48c Change readability-cli dependency 2020-07-10 14:49:08 +02:00
2 changed files with 40 additions and 23 deletions

View File

@ -1,11 +1,11 @@
# Tamias [WIP]
# Tamias
Have you ever bookmarked an article?
Do you think it will be there in a year? or 2?
Tamias stores the articles in a folder on your computer, so you won't lose them.
# Installation
dependencies:
- readability-cli: from the original repository <https://github.com/dergigi/readability-cli> or my fork <https://tildegit.org/paper/readability-cli>
- readability-cli: <https://git.tilde.institute/paper/readability-cli/>
- curl
```sh

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>