Skip to content

Commit 9d286fb

Browse files
committed
publish_edition: use fewer perl calls
1 parent 34ba1b7 commit 9d286fb

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

publish_edition.sh

+22-6
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,32 @@ git cherry-pick "$last_draft_commit"
7070

7171
git mv "$src_dir"/edition-$cur.md "$src_dir"/edition-$next.md
7272

73-
# TODO: Use only one Perl invocation
73+
add_order_suffix() {
74+
perl -e '
75+
my $nb = $ARGV[0];
76+
if ($nb =~ m/[02-9]1$/) {
77+
print $nb . "st\n";
78+
} elsif ($nb =~ m/[02-9]2$/) {
79+
print $nb . "nd\n";
80+
} elsif ($nb =~ m/[02-9]3$/) {
81+
print $nb . "rd\n";
82+
} else {
83+
print $nb . "th\n";
84+
}
85+
' "$1"
86+
}
7487

75-
perl -pi -e "s/Edition $cur/Edition $next/g" "$src_dir"/edition-$next.md
88+
cur_ord=$(add_order_suffix "$cur")
89+
next_ord=$(add_order_suffix "$next")
7690

77-
# TODO: fix "th" when $cur or $next end with 1, 2 or 3
78-
perl -pi -e "s/${cur}th edition/${next}th edition/g" "$src_dir"/edition-$next.md
91+
perl -pi -e "
7992
80-
perl -pi -e "s/$today/$nextdate/g" "$src_dir"/edition-$next.md
93+
s/Edition $cur/Edition $next/g;
94+
s/${cur_ord} edition/${next_ord} edition/g;
95+
s/$today/$nextdate/g;
96+
s/$prev_month/$next_month/g;
8197
82-
perl -pi -e "s/$prev_month/$next_month/g" "$src_dir"/edition-$next.md
98+
" "$src_dir"/edition-$next.md
8399

84100
git commit --amend -m "Add draft for rn-$next" "$src_dir"/edition-$cur.md "$src_dir"/edition-$next.md
85101

0 commit comments

Comments
 (0)