Skip to content

Commit

Permalink
Switch to using awk and trim string down to 25 chars to avoid URLs th…
Browse files Browse the repository at this point in the history
…at are too long.
  • Loading branch information
q0rban committed Feb 25, 2021
1 parent ccc2801 commit f66cf1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
10 changes: 3 additions & 7 deletions .tugboat/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ services:
init:
- printf "\nInclude $TUGBOAT_ROOT/.tugboat/proxy-httpd.conf\n" >> /usr/local/apache2/conf/httpd.conf
build:
- printf 'SetEnvIf Request_URI ".*" QA_SUBDOMAIN=%s\n'
"$(echo "$TUGBOAT_PREVIEW_NAME" |
tr '[:upper:]' '[:lower:]' |
sed -e 's/[^a-z0-9]/-/g'
-e 's/-\+/-/g'
-e 's/\(^-\)\|\(-$\)//g')"
> $TUGBOAT_ROOT/qa_subdomain.conf
- echo "$TUGBOAT_PREVIEW_NAME"
| awk -f .tugboat/qa-subdomain.awk
> $TUGBOAT_ROOT/qa_subdomain.conf
# What to call the service hosting the site.
php:
# Use PHP 7.x with Apache; this syntax pulls in the latest version of PHP 7
Expand Down
16 changes: 16 additions & 0 deletions .tugboat/qa-subdomain.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
# Convert to lowercase.
str = tolower($0);
# Replace all special chars with hyphens.
gsub(/[^a-z0-9]/, "-", str);
# Deduplicate hyphens.
gsub(/-+/, "-", str);
# Remove leading hyphens.
gsub(/^-/, "", str);
# Trim the string down to 25 characters.
str = substr(str, 0, 25);
# Remove trailing hyphens.
gsub(/-$/, "", str);
# Print out the SetEnvIf line.
printf "SetEnvIf Request_URI \".*\" QA_SUBDOMAIN=%s\n", str
}

0 comments on commit f66cf1f

Please sign in to comment.