-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-bookmark.sh
executable file
·53 lines (41 loc) · 1.04 KB
/
gen-bookmark.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
set -eo pipefail
if [ -z "$1" ]; then
echo "Usage: $0 <URL>"
exit 1
fi
# Download the HTML from the URL.
rawhtml=$(mktemp)
curl -s "$1" > "$rawhtml"
function get_content() {
htmlq -f "$rawhtml" -a "$1" "meta[$2=\"$3\"]"
}
function get_og() {
get_content content property "og:$1"
}
title=$(get_og title)
if [ -z "$title" ]; then
title=$(get_content content name "twitter:title")
fi
description=$(get_og description)
if [ -z "$description" ]; then
description=$(get_content content name "twitter:description")
fi
if [ -z "$description" ]; then
description=$(get_content content name "description")
fi
thumbnail=$(get_og image)
publisher=$(get_og site_name)
icon=$(htmlq -f "$rawhtml" -a href 'link[rel="icon"]')
author=$(get_content content name "author")
rm "$rawhtml"
echo "{{< bookmark"
echo " url=\"$1\""
echo " title=\"$title\""
echo " description=\"$description\""
if [ -n "$author" ]; then
echo " author=\"$author\""
fi
echo " publisher=\"$publisher\""
echo " thumbnail=\"$thumbnail\""
echo " icon=\"$icon\" >}}"