Skip to content

Commit

Permalink
simplify sed operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Alextopher committed Oct 15, 2024
1 parent 72306a7 commit cdcadef
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ COPY . .
# Hugo base url
ARG HUGO_BASEURL="https://tvhsfrc.org"

RUN HUGO_BASEURL=$HUGO_BASEURL hugo --environment production

RUN find public -type f -name "*.html" -exec sed -i "s|src=.*/img/dragons.png|src=\"/img/dragons.png|g" {} \;
RUN find public -type f -name "*.html" -exec sed -i "s|src=.*/img/logo.png|src=\"/img/logo.png|g" {} \;
RUN find public -type f -name "*.html" -exec sed -i "s|class=\"logo-link\" href=\".*\"|class=\"logo-link\" href=\"$HUGO_BASEURL\"|g" {} \;
RUN find public -type f -name "*.html" -exec sed -i "s|href=.*/support|href=\"$HUGO_BASEURL/support|g" {} \;

RUN find public -type f -name "*.html" -exec sed -i "s|src=\"/img|src=\"$HUGO_BASEURL/img|g" {} \;
RUN find public -type f -name "*.html" -exec sed -i "s|href=\"/css|href=\"$HUGO_BASEURL/css|g" {} \;
RUN find public -type f -name "*.html" -exec sed -i "s|src=\"/js|src=\"$HUGO_BASEURL/js|g" {} \;
RUN find public -type f -name "*.html" -exec sed -i "s|href=\"/fonts|href=\"$HUGO_BASEURL/fonts|g" {} \;

RUN find public -type f -name "*.css" -exec sed -i "s|url(/img|url($HUGO_BASEURL/img|g" {} \;
RUN find public -type f -name "*.css" -exec sed -i "s|url(/fonts|url($HUGO_BASEURL/fonts|g" {} \;
RUN hugo --environment production

# Remove BaseURL from all hrefs, srcs, and urls. Making the site uniformly relative.
RUN find public -type f -name "*.html" -exec sed -i "s|$HUGO_BASEURL||g" {} \;
# Remove the BaseURL path from all hrefs, srcs, and urls. Making the site uniformly relative.
RUN BASEPATH=$(echo "$HUGO_BASEURL" | sed 's|https://[^/]*||') && \
find public -type f -name "*.html" -exec sed -i "s|$BASEPATH||g" {} \;

# Add back the BaseURL to all hrefs, srcs, and urls
RUN find public -type f -name "*.html" -exec sed -i "s|href=\"/|href=\"$HUGO_BASEURL/|g" {} \;
RUN find public -type f -name "*.html" -exec sed -i "s|src=\"/|src=\"$HUGO_BASEURL/|g" {} \;
RUN find public -type f -name "*.html" -exec sed -i "s|url(/|url($HUGO_BASEURL/|g" {} \;

FROM nginx:alpine

Expand Down

0 comments on commit cdcadef

Please sign in to comment.