Initial commit
This commit is contained in:
commit
129fa93453
|
@ -0,0 +1,56 @@
|
|||
#!/bin/sh -e
|
||||
# TODO: try to get lang from the original document since we download it anyway
|
||||
# TODO: switch for not downloading the original too
|
||||
# TODO: switch for custom language
|
||||
# TODO: support multiple URLs in one command
|
||||
# TODO: flag for custom cache dir
|
||||
# TODO: optionally minify HTML
|
||||
# TODO: download required resources too - images...
|
||||
# TODO: do not create a new file if the name is the same and the content is the same too
|
||||
# TODO: cache download date/time too
|
||||
lang=en
|
||||
url="$1"
|
||||
|
||||
mkdir -p ~/offline/cache/
|
||||
cd ~/offline/cache/
|
||||
|
||||
# get name
|
||||
name=$(echo "$url" | rev | cut -d'/' -f 1 | rev)
|
||||
if [ "$name" = "" ]; then
|
||||
name=$(echo "$url" | rev | cut -d'/' -f 2 | rev)
|
||||
fi
|
||||
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")
|
||||
|
||||
echo '<!DOCTYPE html>
|
||||
<html lang="'"$lang"'">
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta charset="UTF-8">
|
||||
<meta name="url" content="'"$url"'">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/dark.min.css">
|
||||
</head>
|
||||
<body class="container">
|
||||
' > "$name"
|
||||
# cut the first line - bug of readability-cli
|
||||
echo "$readable" >> "$name"
|
||||
echo '
|
||||
</body>
|
||||
</html>' >> "$name"
|
Loading…
Reference in New Issue