-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_random_entry_webpage.bash
49 lines (43 loc) · 1.53 KB
/
create_random_entry_webpage.bash
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
#!/bin/bash
# create_random_entry_webpage.bash
# Create an HTML page that will take you to a random DayOne post.
# 02/17/2019 spitman script created.
# 02/17/2021 spitman made it more self contained. Renamed from make_links.bash.
# Setup Stuff
thisDir=`pwd`
mkdir ${thisDir}/work 2> /dev/null
rndPg="${thisDir}/random_entry.html"
troubleshoot_me () {
set -x
}
get_uuids () {
grep "\"uuid\" :" Export*/*.json | grep "," | cut -d"\"" -f4 > ${thisDir}/work/uuids.txt
}
make_pushlines () {
echo > ${thisDir}/work/pushlines.txt
while read line ; do
echo "i.push(\"${line}\");" >> ${thisDir}/work/pushlines.txt
done < ${thisDir}/work/uuids.txt
}
create_html_page () {
echo "<html>" > ${rndPg}
echo "<p><script type="text/javascript">" >> ${rndPg}
echo "var i = new Array();" >> ${rndPg}
while read line2 ; do
echo "${line2}" >> ${rndPg}
done < ${thisDir}/work/pushlines.txt
echo "var item = i[Math.floor(Math.random()*i.length)];" >> ${rndPg}
echo "document.write(\"You have \" + i.length + \" entries... here we go to a <a href=dayone2://view?entryId=\" + item + \" style='text-decoration:none'>random</a> one... <meta http-equiv='refresh' content='3; url=dayone2://view?entryId=\" + item + \"'>\");" >> ${rndPg}
echo "</script>" >> ${rndPg}
echo "<p>Refresh this page to go to a different random entry.</p>" >> ${rndPg}
echo "</html>" >> ${rndPg}
echo "Complete. Open random_entry.html in your favorite browser."
}
##########
## MAIN ##
##########
# troubleshoot_me
make_pushlines
get_uuids
make_pushlines
create_html_page