Skip to content

Commit 54a6b12

Browse files
committed
Simplify publishing workflows
* Shift to three primary 'make' recipes: * 'make website': Generates and locally hosts website content, echoing the latest entry for easy access * 'make copy-website-contents: Takes above generated website, and syncs state with the input directory * 'make email': Generates website content formatted for email, then uses 'juice' for creating optimized format. Lands final email in new directory, and echos the location * Separate output directories to "output-website/" and "output-email-format/" to avoid potential confusion Notably, email generation no longer requires bringing up two windows, nor does it require updating the variable. All is handled automatically
1 parent df681b0 commit 54a6b12

8 files changed

+116
-68
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ cache
1010
.DS_Store
1111

1212
# Publishing creations...
13-
publishing/output
13+
publishing/email
14+
publishing/output*
1415
publishing/juice

publishing/Makefile

+50-54
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,77 @@
11
#!/bin/sh
22

33
# TODO: Make sure running from latest "main" branch commit
4-
# TODO: Remove `BLOG_DOWNLOAD` variable requirement. Adjust "email" logic to:
5-
# - Run generate container
6-
# - Curl website
7-
# - Run HTML-friendly container
84

95
# Typical flows:
10-
#
11-
# 1. The first workflow will generate the desired website, landing
12-
# the end contents in the local "output/" directory. This is the
6+
#
7+
# 1. `make website`
8+
# The first workflow will generate the desired website, landing
9+
# the end contents in the local "output-website/" directory. This is the
1310
# equivalent of running `pelican --delete-output-directory content`
1411
# from a properly instantantiated environment.
1512
#
16-
# $ make build && make generate-website && make host-content
17-
#
13+
# $ generate-website host-website
14+
#
1815
# Then, visit the printed URL from a browser to verify.
19-
#
20-
# 2. This workflow will generate the desired email template, landing
21-
# the end contents in the local "output/" directory. This is the
16+
#
17+
# Output: `output-website/`
18+
#
19+
# 2. `make copy-website-contents`
20+
# This workflow will sync the `output-website/` directory from above, and sync
21+
# it with the directory passed to it. Used for syncing state with
22+
# this-week-in-rust.github.io repo.
23+
#
24+
# 3. `make email`
25+
# This workflow will generate the desired email template, landing
26+
# the end contents in the local "email/" directory. This is the
2227
# equivalent of running `USE_EMAIL_THEME=1 pelican --delete-output-directory content`
23-
# from a properly instantantiated environment.
28+
# from a properly instantantiated environment, and running
29+
# `juice --web-resources-images false /juice/in.html /juice/out.html` on the latest content post.
2430
#
25-
# $ make build && make generate-email && make host-content
31+
# $ build clean generate-email optimize-email
2632
#
27-
# Then, visit the printed URL from a browser to verify.
28-
# Once verified, one can adjust the "BLOG_DOWNLOAD" variable below, and
29-
# we can create an email-friendly HTML version of the latest Blog page.
30-
# **While the above container is still running**, open another terminal.
31-
# This is the equivalent of running
32-
# `curl ${BLOG_DOWNLOAD} > juice/in.html && juice --web-resources-images false /juice/in.html /juice/out.html`
33-
#
34-
# $ make optimize-email
33+
# Output: `email/<NUMBER>-<YEAR>-<MONTH>-<DAY>-email.html`
3534
#
36-
# This results in the desired email-friendly HTML version: "juice/out.html".
37-
38-
# TODO: The BLOG_DOWNLOAD is only needed because one dockerfile will have to communicate
39-
# with another, and I don't want to deal with building out the networking logic... yet...
40-
# CHANGE ME! vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
41-
BLOG_DOWNLOAD=http://localhost:8000/blog/2024/09/04/this-week-in-rust-563/
4235

43-
website-workflow: build clean generate-website host-content
44-
45-
email-workflow-1: build clean generate-email host-content
46-
email-workflow-2: optimize-email
36+
website: generate-website host-website
37+
copy-website-contents:
38+
@./copy_website_content_to_repo.sh
39+
email: generate-email optimize-email
4740

4841
build:
4942
cd .. && docker build -t twir -f publishing/Dockerfile . && cd -
5043

51-
clean:
52-
rm -rf output/
44+
clean-website:
45+
@rm -rf output/ && rm -rf output-website/ && rm -rf juice/
46+
clean-email:
47+
@rm -rf output/ && rm -rf output-email-format/ && rm -rf email/ && rm -rf juice/
5348

54-
generate-website: clean
55-
docker run -it \
56-
-v $(shell pwd)/output:/usr/twir/output \
49+
generate-website: build clean-website
50+
@echo "Generating website..."
51+
@docker run -it \
52+
-v $(shell pwd)/output-website:/usr/twir/output \
5753
twir:latest
54+
@echo "Finished generating website."
5855

59-
generate-email: clean
60-
docker run -it \
61-
-e USE_EMAIL_THEME=1 \
62-
-v $(shell pwd)/output:/usr/twir/output \
63-
twir:latest
64-
65-
host-content:
66-
docker run -it \
56+
host-website:
57+
@echo "Hosting website..."
58+
@docker run -it \
6759
-p 8000:8000 \
68-
-v $(shell pwd)/output:/usr/twir/output:ro \
60+
-v $(shell pwd)/output-website:/usr/twir/output:ro \
6961
-it \
7062
twir:latest \
7163
bash run_server.sh
64+
@echo "Finished hosting website."
65+
@echo ""
66+
@echo "To sync contents with your local 'this-week-in-rust.github.io' repo, run \033[1;33m'make copy-website-contents'\033[0m"
67+
68+
generate-email: build clean-email
69+
@echo "Generating email..."
70+
@docker run -it \
71+
-e USE_EMAIL_THEME=1 \
72+
-v $(shell pwd)/output-email-format:/usr/twir/output \
73+
twir:latest
7274

7375
optimize-email:
74-
@echo -n "Is this '${BLOG_DOWNLOAD}' your desired blog? [y/N] " && read ans && [ $${ans:-N} = y ]
75-
rm -rf juice
76-
mkdir juice
77-
curl ${BLOG_DOWNLOAD} > juice/in.html
78-
docker run \
79-
-v $(shell pwd)/juice:/usr/twir/juice \
80-
twir:latest \
81-
bash create_html_friendly_page.sh
76+
@echo "Generating optimized email..."
77+
@OUTPUT_PREFIX=output-email-format ./create_optimized_email.sh
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
read -p "Enter the directory to copy website contents to (likely ending in 'this-week-in-rust.github.io'): " directory
4+
5+
# Check if the provided input is a valid directory
6+
if [ ! -d "$directory" ]; then
7+
echo "Error: $directory is not a valid directory."
8+
exit 1
9+
fi
10+
11+
# Check if the file "CNAME" exists in the directory
12+
if [ -f "$directory/CNAME" ]; then
13+
rsync -razvP --delete --exclude /CNAME --exclude /.git output-website/ $directory
14+
echo "Finished syncing with directory '$directory'"
15+
else
16+
echo "ERROR: This does not seem to be the 'this-week-in-rust.github.io' repo..."
17+
echo "Please copy contents manually using 'rsync -razvP --delete --exclude /CNAME --exclude /.git output-website/ /path/to/this-week-in-rust.github.io/'"
18+
fi
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#!/bin/sh
22

3-
juice --web-resources-images false juice/in.html juice/out.html
4-
rm juice/in.html
3+
juice --web-resources-images false ${LOCAL_EMAIL_PREFIX}-in.html ${LOCAL_EMAIL_PREFIX}-email.html

publishing/create_optimized_email.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
source utils.sh
4+
5+
LOCAL_EMAIL_PREFIX="email/${LATEST_ISSUE_NUMBER}-${LATEST_YEAR}-${LATEST_MONTH}-${LATEST_DAY}"
6+
echo "Creating email for ${LATEST_ISSUE_NUMBER}-${LATEST_YEAR}-${LATEST_MONTH}-${LATEST_DAY}"
7+
8+
# Prepare email directory
9+
mkdir -p email
10+
rm -f ${LOCAL_EMAIL_PREFIX}-in.html
11+
cp ${LATEST_ISSUE_FULL_PATH} ${LOCAL_EMAIL_PREFIX}-in.html
12+
13+
docker run \
14+
-v $(pwd)/email:/usr/twir/email \
15+
-e LOCAL_EMAIL_PREFIX=${LOCAL_EMAIL_PREFIX} \
16+
twir:latest \
17+
bash create_html_friendly_page.sh
18+
19+
rm ${LOCAL_EMAIL_PREFIX}-in.html
20+
21+
printf "\n\n${CYAN_FONT}*****${PURPLE_FONT}*****${CYAN_FONT}*****${PURPLE_FONT}*****${NC}"
22+
printf "\n${CYAN_FONT}*****${PURPLE_FONT}*****${CYAN_FONT}*****${PURPLE_FONT}*****${NC}"
23+
printf "\n${CYAN_FONT}*****${PURPLE_FONT}*****${CYAN_FONT}*****${PURPLE_FONT}*****${NC}"
24+
printf "\n📧 HEY TWiR PUBLISHER..."
25+
printf "\nLatest email template found at: ${YELLOW_FONT}'$(pwd)/${LOCAL_EMAIL_PREFIX}-email.html'${NC}"
26+
printf "\n${CYAN_FONT}*****${PURPLE_FONT}*****${CYAN_FONT}*****${PURPLE_FONT}*****${NC}"
27+
printf "\n${CYAN_FONT}*****${PURPLE_FONT}*****${CYAN_FONT}*****${PURPLE_FONT}*****${NC}"
28+
printf "\n${CYAN_FONT}*****${PURPLE_FONT}*****${CYAN_FONT}*****${PURPLE_FONT}*****${NC}\n\n"

publishing/form_latest_url.sh

-9
This file was deleted.

publishing/run_server.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/bin/sh
22

3-
source form_latest_url.sh
3+
source utils.sh
44

55
printf "\n\n${CYAN_FONT}*****${PURPLE_FONT}*****${CYAN_FONT}*****${PURPLE_FONT}*****${NC}"
66
printf "\n${CYAN_FONT}*****${PURPLE_FONT}*****${CYAN_FONT}*****${PURPLE_FONT}*****${NC}"
77
printf "\n${CYAN_FONT}*****${PURPLE_FONT}*****${CYAN_FONT}*****${PURPLE_FONT}*****${NC}"
88
printf "\nHEY TWiR PUBLISHER..."
99
printf "\nLatest blog found at: ${YELLOW_FONT}'${LATEST_BLOG_URL}'${NC}"
10-
printf "\nIf publishing for email, copy the blog into the ${YELLOW_FONT}BLOG_DOWNLOAD${NC} variable in the Makefile!"
1110
printf "\n${CYAN_FONT}*****${PURPLE_FONT}*****${CYAN_FONT}*****${PURPLE_FONT}*****${NC}"
1211
printf "\n${CYAN_FONT}*****${PURPLE_FONT}*****${CYAN_FONT}*****${PURPLE_FONT}*****${NC}"
1312
printf "\n${CYAN_FONT}*****${PURPLE_FONT}*****${CYAN_FONT}*****${PURPLE_FONT}*****${NC}\n\n"

publishing/utils.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Default OUTPUT_PREFIX, but allow overriding for email workflows.
2+
if [ -z "$OUTPUT_PREFIX" ]; then
3+
OUTPUT_PREFIX="output"
4+
fi
5+
6+
LATEST_YEAR=$(ls ${OUTPUT_PREFIX}/blog/ | sort | tail -2 | head -1)
7+
LATEST_MONTH=$(ls ${OUTPUT_PREFIX}/blog/${LATEST_YEAR} | sort | tail -1)
8+
LATEST_DAY=$(ls ${OUTPUT_PREFIX}/blog/${LATEST_YEAR}/${LATEST_MONTH} | sort | tail -1)
9+
LATEST_ISSUE_NUMBER=$(ls ${OUTPUT_PREFIX}/blog/${LATEST_YEAR}/${LATEST_MONTH}/${LATEST_DAY}/ | awk -F'-' '{print $5}')
10+
LATEST_ISSUE_FULL_PATH="${OUTPUT_PREFIX}/blog/${LATEST_YEAR}/${LATEST_MONTH}/${LATEST_DAY}/this-week-in-rust-${LATEST_ISSUE_NUMBER}/index.html"
11+
LATEST_BLOG_URL="http://localhost:8000/blog/${LATEST_YEAR}/${LATEST_MONTH}/${LATEST_DAY}/this-week-in-rust-${LATEST_ISSUE_NUMBER}/"
12+
13+
YELLOW_FONT='\033[1;32m'
14+
CYAN_FONT='\033[0;36m'
15+
PURPLE_FONT='\033[1;35m'
16+
NC='\033[0m' # No Color

0 commit comments

Comments
 (0)