Created
February 26, 2024 12:22
-
-
Save davidsneighbour/fb8c0d0188cb9340feab83f77a443093 to your computer and use it in GitHub Desktop.
Refactoring GoHugo aliases into proper methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float = "cast.toFloat" | |
int = "cast.toInt" | |
string = "cast.toString" | |
after = "collections.After" | |
append = "collections.Append" | |
apply = "collections.Apply" | |
complement = "collections.Complement" | |
delimit = "collections.Delimit" | |
dictionary = "collections.Dictionary" | |
first = "collections.First" | |
group = "collections.Group" | |
in = "collections.In" | |
index = "collections.Index" | |
intersect = "collections.Intersect" | |
isset = "collections.IsSet" | |
keyvals = "collections.KeyVals" | |
last = "collections.Last" | |
merge = "collections.Merge" | |
newscratch = "collections.NewScratch" | |
querify = "collections.Querify" | |
reverse = "collections.Reverse" | |
seq = "collections.Seq" | |
shuffle = "collections.Shuffle" | |
slice = "collections.Slice" | |
sort = "collections.Sort" | |
symdiff = "collections.SymDiff" | |
union = "collections.Union" | |
uniq = "collections.Uniq" | |
where = "collections.Where" | |
cond = "compare.Conditional" | |
default = "compare.Default" | |
eq = "compare.Eq" | |
ge = "compare.Ge" | |
gt = "compare.Gt" | |
le = "compare.Le" | |
lt = "compare.Lt" | |
ne = "compare.Ne" | |
sha256 = "crypto.SHA256" | |
sha1 = "crypto.SHA1" | |
md5 = "crypto.MD5" | |
hmac = "crypto.HMAC" | |
base64Decode = "encoding.Base64Decode" | |
base64Encode = "encoding.Base64Encode" | |
jsonify = "encoding.Jsonify" | |
warnf = "fmt.Warnf" | |
warnidf = "fmt.Warnidf" | |
errorf = "fmt.Errorf" | |
erroridf = "fmt.Erroridf" | |
printf = "fmt.Printf" | |
print = "fmt.Print" | |
println = "fmt.Println" | |
humanize = "inflect.Humanize" | |
pluralize = "inflect.Pluralize" | |
singularize = "inflect.Singularize" | |
i18n = "lang.Translate" | |
T = "lang.Translate" | |
add = "math.Add" | |
div = "math.Div" | |
mod = "math.Mod" | |
modBool = "math.ModBool" | |
mul = "math.Mul" | |
pow = "math.Pow" | |
sub = "math.Sub" | |
fileExists = "os.FileExists" | |
getenv = "os.Getenv" | |
readDir = "os.ReadDir" | |
readFile = "os.ReadFile" | |
partial = "partials.Include" | |
partialCached = "partials.IncludeCached" | |
babel = "resources.Babel" | |
fingerprint = "resources.Fingerprint" | |
minify = "resources.Minify" | |
postCSS = "resources.PostCSS" | |
toCSS = "resources.ToCSS" | |
safeCSS = "safe.CSS" | |
safeHTML = "safe.HTML" | |
safeHTMLAttr = "safe.HTMLAttr" | |
safeJS = "safe.JS" | |
safeJSStr = "safe.JSStr" | |
safeURL = "safe.URL" | |
chomp = "strings.Chomp" | |
countrunes = "strings.CountRunes" | |
countwords = "strings.CountWords" | |
findRE = "strings.FindRE" | |
findRESubmatch = "strings.FindRESubmatch" | |
hasPrefix = "strings.HasPrefix" | |
hasSuffix = "strings.HasSuffix" | |
replace = "strings.Replace" | |
replaceRE = "strings.ReplaceRE" | |
slicestr = "strings.SliceString" | |
split = "strings.Split" | |
substr = "strings.Substr" | |
title = "strings.Title" | |
lower = "strings.ToLower" | |
upper = "strings.ToUpper" | |
trim = "strings.Trim" | |
truncate = "strings.Truncate" | |
time = "time.AsTime" | |
duration = "time.Duration" | |
dateFormat = "time.Format" | |
now = "time.Now" | |
emojify = "transform.Emojify" | |
highlight = "transform.Highlight" | |
htmlEscape = "transform.HTMLEscape" | |
htmlUnescape = "transform.HTMLUnescape" | |
markdownify = "transform.Markdownify" | |
plainify = "transform.Plainify" | |
unmarshal = "transform.Unmarshal" | |
absLangURL = "urls.AbsLangURL" | |
absURL = "urls.AbsURL" | |
anchorize = "urls.Anchorize" | |
ref = "urls.Ref" | |
relLangURL = "urls.RelLangURL" | |
relRef = "urls.RelRef" | |
relURL = "urls.RelURL" | |
urlize = "urls.URLize" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage() { | |
echo "Usage: $0 <directory>" | |
exit 1 | |
} | |
if [ $# -ne 1 ]; then | |
usage | |
fi | |
directory=$1 | |
script_directory="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" | |
conversion_file="$script_directory/aliases.toml" | |
if [ ! -d "$directory" ]; then | |
echo "Directory '$directory' not found." | |
exit 1 | |
fi | |
if [ ! -f "$conversion_file" ]; then | |
echo "Conversion file '$conversion_file' not found." | |
exit 1 | |
fi | |
while IFS='=' read -r search_string replace_string; do | |
search_string=$(echo "$search_string" | tr -d '[:space:]' | tr -d '-') | |
replace_string=$(echo "$replace_string" | tr -d '[:space:]' | tr -d '"' | tr -d '-') | |
find "$directory" -type f -exec sed -i -E "s/(\s|\(|\{)($search_string)(\s|\)|\})/\1$replace_string\3/g" {} + | |
echo "Replaced '$search_string' with '$replace_string'" | |
done <"$conversion_file" | |
echo "Replacement complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment