-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteraction
More file actions
executable file
·60 lines (52 loc) · 1.42 KB
/
interaction
File metadata and controls
executable file
·60 lines (52 loc) · 1.42 KB
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
54
55
56
57
58
59
60
#!/usr/bin/env bash
while getopts ":blr" option; do
case "${option}" in
b)
interaction_title="Bookmarked"
interaction_tag="bookmark"
;;
l)
interaction_title="Liked"
interaction_tag=like
;;
r)
interaction_title="RSVP"
interaction_tag="rsvp"
;;
*)
echo "Error: invalid flag ${option}"
;;
esac
shift $((OPTIND - 1))
done
if [ ${1+x} ]; then
target_url=$1
fi
if [ ${target_url+x} ]; then
target_title=$(curl -s "$target_url" | grep -o "<title>[^<]*" | tail -c+8)
else
target_title="Interaction"
fi
# tr replace first w/ second; -c means "complement", -d "delete", -s "squeeze repeats"
# cut trims length; sed command strips trailing whitespace after trimming
# slug=$(echo "${interaction_title} ${target_title}" | tr '[:upper:]' '[:lower:]' | tr -cd '[:alnum:] ' | cut -c1-45 | sed -e 's/[[:space:]]*$//' | tr -s " " "-")
slug=$(echo "${interaction_title} ${target_title}" | tr '[:upper:]' '[:lower:]' | tr -cd '[:alnum:] ' | tr -s " " "-")
isodate=$(date +"%Y-%m-%dT%H:%M:%S%z")
year=$(date +"%Y")
month=$(date +"%m")
# -p: make intermediate directories and don't complain if the full path already exists
mkdir -p "pages/interactions/$year/$month"
fullpath="pages/interactions/$year/$month/$slug.md"
cat >>"$fullpath" <<EOF
---
title: "${interaction_title}: ${target_title}"
fedi_url:
date: $isodate
tags:
- interaction
- $interaction_tag
rsvp_value:
target_url: $target_url
target_title: $target_title
---
EOF