people formatter refactor
This commit is contained in:
@@ -1,13 +1,16 @@
|
|||||||
#/bin/bash
|
#/bin/bash
|
||||||
|
|
||||||
echo "Running threefold_data formatter:"
|
|
||||||
echo "Formatting people..."
|
|
||||||
dir="threefold_data/content/person"
|
|
||||||
|
|
||||||
# function that checks whether given file is formatted
|
# readable shorthand for adding tab
|
||||||
# simply compares if keyword excerpt or description is used
|
add_tab() {
|
||||||
# $1: file
|
sed -i "" "s|$1| $1|g" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
# readable shorthand for sed replace
|
||||||
|
replace() {
|
||||||
|
sed -i "" "s|$1|$2|g" "$3"
|
||||||
|
}
|
||||||
|
|
||||||
|
# check if certain word exists in a file
|
||||||
exists() {
|
exists() {
|
||||||
if grep "$1" $2 > /dev/null
|
if grep "$1" $2 > /dev/null
|
||||||
then
|
then
|
||||||
@@ -17,6 +20,8 @@ exists() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# move line with a certain word $1
|
||||||
|
# below another line with certain word $2
|
||||||
move_below() {
|
move_below() {
|
||||||
if exists $1 $3; then
|
if exists $1 $3; then
|
||||||
TARGET="$(grep -n "$1" "$3" | sed -n -e "s/^.*\(\($1\).*\)/\1/p")"
|
TARGET="$(grep -n "$1" "$3" | sed -n -e "s/^.*\(\($1\).*\)/\1/p")"
|
||||||
@@ -30,13 +35,11 @@ $TARGET\\
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
replace() {
|
echo "Formatting people..."
|
||||||
sed -i "" "s|$1|$2|g" "$file"
|
dir="threefold_data/content/person"
|
||||||
}
|
|
||||||
|
|
||||||
for file in $(grep -ril 'name:' $dir);
|
for file in $(grep -ril 'name:' $dir);
|
||||||
do
|
do
|
||||||
echo $file
|
|
||||||
|
|
||||||
sed -i "" "s|private: 1| private: 1\\
|
sed -i "" "s|private: 1| private: 1\\
|
||||||
socialLinks: {\\
|
socialLinks: {\\
|
||||||
@@ -48,6 +51,7 @@ do
|
|||||||
move_below projects: image: $file
|
move_below projects: image: $file
|
||||||
move_below linkedin: socialLinks: $file
|
move_below linkedin: socialLinks: $file
|
||||||
move_below github: linkedin: $file
|
move_below github: linkedin: $file
|
||||||
|
move_below id: excerpt: $file
|
||||||
|
|
||||||
# move bio field below toml
|
# move bio field below toml
|
||||||
BIO="$(grep -n 'bio:' "$file" | sed -n -e 's/^.*\(\(bio:\).*\)/\1/p')"
|
BIO="$(grep -n 'bio:' "$file" | sed -n -e 's/^.*\(\(bio:\).*\)/\1/p')"
|
||||||
@@ -56,42 +60,43 @@ do
|
|||||||
echo "\n$BIO" >> $file
|
echo "\n$BIO" >> $file
|
||||||
sed -i "" "s|bio: ||g" "$file"
|
sed -i "" "s|bio: ||g" "$file"
|
||||||
|
|
||||||
|
# adds comma after social links
|
||||||
WEBSITES="$(grep -n 'websites:' "$file" | sed -n -e 's/^.*\(\(websites:\).*\)/\1/p')"
|
WEBSITES="$(grep -n 'websites:' "$file" | sed -n -e 's/^.*\(\(websites:\).*\)/\1/p')"
|
||||||
sed -i "" "s|$WEBSITES|$WEBSITES,|g" "$file"
|
sed -i "" "s|$WEBSITES|$WEBSITES,|g" "$file"
|
||||||
|
LINKEDIN="$(grep -n 'linkedin:' "$file" | sed -n -e 's/^.*\(\(linkedin:\).*\)/\1/p')"
|
||||||
|
sed -i "" "s|$LINKEDIN|$LINKEDIN,|g" "$file"
|
||||||
|
|
||||||
# move id field below excerpt
|
# put id into square brackets for people taxonomy
|
||||||
ID="$(grep -n 'id:' "$file" | sed -n -e 's/^.*\(\(id:\).*\)/\1/p')"
|
ID="$(grep -n 'id:' "$file" | sed -n -e 's/^.*\(\(id:\).*\)/\1/p')"
|
||||||
LINE_NUM="$(grep -n 'id:' "$file" | head -n1 | sed 's/:.*//')"
|
|
||||||
NAME="${ID#* }"
|
NAME="${ID#* }"
|
||||||
echo $NAME
|
|
||||||
NAME="[$NAME]"
|
NAME="[$NAME]"
|
||||||
sed -i "" "${LINE_NUM}d" "$file"
|
sed -i "" "s|$ID|id: $NAME|g" "$file"
|
||||||
LINE_NUM="$(grep -n 'excerpt:' "$file" | head -n1 | sed 's/:.*//')"
|
|
||||||
LINE_NUM="$(($LINE_NUM + 1))"
|
|
||||||
sed -a -i "" "${LINE_NUM}i\\
|
|
||||||
id: ${NAME}\\
|
|
||||||
" "$file"
|
|
||||||
|
|
||||||
|
|
||||||
# Change field names
|
# Change field names
|
||||||
sed -i "" "s|category:|categories:|g" "$file"
|
replace "category:" "categories:" $file
|
||||||
sed -i "" "s|rank:|weight:|g" "$file"
|
replace "rank:" "weight:" $file
|
||||||
sed -i "" "s|excerpt:|description:|g" "$file"
|
replace "excerpt:" "description:" $file
|
||||||
sed -i "" "s| ---|---|g" "$file"
|
replace "name:" "title:" $file
|
||||||
|
replace "linkedin:" "LinkedIn:" $file
|
||||||
|
replace "projects:" "organizations:" $file
|
||||||
|
replace "projects:" "organizations:" $file
|
||||||
|
replace "image: ./" "imgPath: " $file
|
||||||
|
|
||||||
sed -i "" "s|image:|extra:\\
|
sed -i "" "s|image:|extra:\\
|
||||||
image:|g" "$file"
|
image:|g" "$file"
|
||||||
sed -i "" "s|id:|taxonomies:\\
|
sed -i "" "s|id:|taxonomies:\\
|
||||||
people:|g" "$file"
|
people:|g" "$file"
|
||||||
sed -i "" "s| extra:|extra:|g" "$file"
|
|
||||||
|
|
||||||
sed -i "" "s|websites:| websites:|g" "$file"
|
add_tab "cities:" $file
|
||||||
sed -i "" "s|name:|title:|g" "$file"
|
add_tab "countries:" $file
|
||||||
sed -i "" "s|linkedin:| LinkedIn:|g" "$file"
|
add_tab "extra:" $file
|
||||||
sed -i "" "s|projects:|organizations:|g" "$file"
|
|
||||||
sed -i "" "s|image: ./|imgPath: |g" "$file"
|
#dir_path=${file%/*}
|
||||||
sed -i "" "s|countries:| countries:|g" "$file"
|
#fname=${dir_path##*/}
|
||||||
sed -i "" "s|cities:| cities:|g" "$file"
|
#mkdir content/people/$fname
|
||||||
|
#mv -s $file content/people/$fname/index.md
|
||||||
|
#ln -s ${file%/*} content/people
|
||||||
|
|
||||||
|
|
||||||
mv $file ${file%/*}/index.md
|
mv $file ${file%/*}/index.md
|
||||||
mv ${file%/*} content/people
|
mv ${file%/*} content/people
|
||||||
|
|||||||
Submodule threefold_data updated: 7cf3eeda8d...e88404a758
Reference in New Issue
Block a user