Skip to content

Commit

Permalink
Removed sed from header build function since native substitution is s…
Browse files Browse the repository at this point in the history
…afer (#4)
  • Loading branch information
neonspectra authored Nov 9, 2023
1 parent 302dca0 commit 797b55c
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions lib/functions/inline/build_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,21 @@ build_header() {
# If enabled (default:true), add a configurable content header after the metadata header. The purpose of this is to enable a standardised header for stuff like post dates that should be on *most* pages, but can be disabled on pages the user considers special and wants to build out completely on their own.
[[ $content_header == "true" ]] && cat $config/content_header.html >> $1

# Replace all tags with their value. Ampersands are a special character in sed, so we have to clean them up using bash string manipulation before running the sed global replace.
title=${title//&/\\&}
sed -i "s^{{title}}^$title^g" $1
# Replace all tags in {{this format}} with their value. We do this using Bash pattern replacement.
page_contents="$(cat $1)"

author=${author//&/\\&}
sed -i "s^{{author}}^$author^g" $1

description=${description//&/\\&}
sed -i "s^{{description}}^$description^g" $1

language=${language//&/\\&}
sed -i "s^{{language}}^$language^g" $1

thumbnail=${thumbnail//&/\\&}
sed -i "s^{{thumbnail}}^$thumbnail^g" $1

sed -i "s^{{published_date}}^$published_date^g" $1

sed -i "s^{{modified_date}}^$modified_date^g" $1

canonical_url=${canonical_url//&/\\&}
sed -i "s^{{canonical_url}}^$canonical_url^g" $1

base_url=${base_url//&/\\&}
sed -i "s^{{base_url}}^$base_url^g" $1

global_name=${global_name//&/\\&}
sed -i "s^{{global_name}}^$global_name^g" $1
page_contents="${page_contents//\{\{title\}\}/"$title"}"
page_contents="${page_contents//\{\{author\}\}/"$author"}"
page_contents="${page_contents//\{\{description\}\}/"$description"}"
page_contents="${page_contents//\{\{language\}\}/"$language"}"
page_contents="${page_contents//\{\{thumbnail\}\}/"$thumbnail"}"
page_contents="${page_contents//\{\{published_date\}\}/"$published_date"}"
page_contents="${page_contents//\{\{modified_date\}\}/"$modified_date"}"
page_contents="${page_contents//\{\{canonical_url\}\}/"$canonical_url"}"
page_contents="${page_contents//\{\{base_url\}\}/"$base_url"}"
page_contents="${page_contents//\{\{global_name\}\}/"$global_name"}"

echo "$page_contents" > $1
page_contents=""
}
}

0 comments on commit 797b55c

Please sign in to comment.