Skip to content

Commit 82710fb

Browse files
committed
chore(deploy): deploy to tiddlyhost
1 parent 765aec6 commit 82710fb

File tree

3 files changed

+95
-18
lines changed

3 files changed

+95
-18
lines changed

.github/workflows/release.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,19 @@ jobs:
2828
- name: Build library and static website
2929
run: npm run publish
3030

31-
- name: Release
32-
env:
33-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
35-
run: npx semantic-release
36-
37-
- name: Deploy
31+
- name: Deploy to gh-pages
3832
uses: peaceiris/actions-gh-pages@v3
3933
with:
4034
github_token: ${{ secrets.GITHUB_TOKEN }}
4135
publish_dir: ./dist
4236

37+
- name: Deploy to tiddlyhost
38+
env:
39+
THOST_TOKEN: ${{ secrets.TH_PASSWORD }}
40+
run: for file in $(find ./dist/empty -type f -regex ".*\.html"); do site=${file%.html}; site=${site#dist/empty/}; if [ "$site" == "index" ]; then site="tidme"; else site="tidme-${site,,}"; fi; ./bin/thost-uploader $site $file $THOST_EMAIL $TH_PASSWORD; done
41+
42+
- name: Release
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
46+
run: npx semantic-release

.gitignore

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ public-dist
130130
# for TiddlyWiki
131131
dist/
132132
output/
133-
*/tiddlers/$__language.tid
134-
*/tiddlers/$__StoryList.tid
135-
*/tiddlers/$__StoryList_*.tid
136-
*/tiddlers/$__keepstate_*
137-
*/tiddlers/$__Import.tid
138-
*/tiddlers/$__UpgradeLibrary
139-
*/tiddlers/$__UpgradeLibrary_List
140-
*/tiddlers/$__temp_*
141-
*/tiddlers/$__view.tid
142-
*/tiddlers/$__config_Navigation_openLinkFromInsideRiver.tid
143-
*/tiddlers/$__config_Navigation_openLinkFromOutsideRiver.tid
133+
**/\$__language.tid
134+
**/\$__StoryList.tid
135+
**/\$__StoryList_*.tid
136+
**/\$__keepstate_*
137+
**/\$__Import.tid
138+
**/\$__UpgradeLibrary
139+
**/\$__UpgradeLibrary_List
140+
**/\$__temp_*
141+
**/\$__view.tid
142+
**/\$__config_Navigation_openLinkFromInsideRiver.tid
143+
**/\$__config_Navigation_openLinkFromOutsideRiver.tid

bin/thost-uploader

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
#
3+
# Bash script showing how to use curl to save to a Tiddlyhost site.
4+
#
5+
# Example usage:
6+
# ./thost-uploader yoursite newcontent.html [email protected] yourpassword
7+
#
8+
# To avoid including your password in scripts, you could do something like
9+
# this for example:
10+
# echo yourpassword > ~/.thostpass
11+
# chmod 600 ~/.thostpass
12+
#
13+
# Then:
14+
# ./thost-uploader yoursite newcontent.html [email protected] $(cat ~/.thostpass)
15+
#
16+
17+
show_usage() {
18+
echo Usage:
19+
echo " $0 <sitename> <tiddlywikifile> <email> <password>"
20+
exit 1
21+
}
22+
23+
SITE=$1
24+
FILE=$2
25+
EMAIL=$3
26+
PASSWD=$4
27+
28+
DOWNLOAD_DIR=${DOWNLOAD_DIR:-.}
29+
mkdir -p $DOWNLOAD_DIR
30+
31+
[[ -z "$SITE" ]] && show_usage
32+
[[ -z "$FILE" ]] && show_usage
33+
[[ -z "$EMAIL" ]] && show_usage
34+
[[ -z "$PASSWD" ]] && show_usage
35+
36+
[[ ! -r "$FILE" ]] && echo "Can't read file $FILE!" && exit 1
37+
38+
TIDDLYHOST=tiddlyhost.com
39+
SIGN_IN=https://$TIDDLYHOST/users/sign_in
40+
COOKIES=$(mktemp)
41+
CURL="curl -s --cookie-jar $COOKIES --cookie $COOKIES"
42+
43+
# Read authenticity_token
44+
TOKEN=$( $CURL $SIGN_IN | grep '"csrf-token"' | cut -d'"' -f4 )
45+
46+
# Log in
47+
$CURL -X POST $SIGN_IN \
48+
-d "authenticity_token=$TOKEN" \
49+
-d "user[email]=$EMAIL" \
50+
-d "user[password]=$PASSWD" \
51+
> /dev/null
52+
53+
# Confirm that auth worked
54+
OK=$( $CURL -I "https://$TIDDLYHOST/sites" | head -1 | grep '200 OK' )
55+
[[ -z "$OK" ]] && echo "Authentication failed." && exit 1
56+
57+
# Download a copy just in case something goes wrong
58+
# $CURL "https://$SITE.$TIDDLYHOST/download" -o $DOWNLOAD_DIR/$SITE.$(date +%Y%m%d%H%M%S).backup.html
59+
60+
# Now upload the new TiddlyWiki file
61+
OK=$( $CURL -i -X PUT --data-binary "@$FILE" \
62+
-H "Content-Type: text/html;charset=UTF-8" \
63+
"https://$SITE.$TIDDLYHOST/" | grep '204 No Content')
64+
65+
# 204 means it worked
66+
if [[ -z "$OK" ]]; then
67+
echo "Upload failed." && exit 1
68+
else
69+
echo "Uploaded $FILE to https://$SITE.$TIDDLYHOST/"
70+
fi
71+
72+
# Clean up
73+
rm $COOKIES

0 commit comments

Comments
 (0)