-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.sh
More file actions
executable file
·30 lines (23 loc) · 866 Bytes
/
convert.sh
File metadata and controls
executable file
·30 lines (23 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
# Change to the _posts directory
cd _posts || exit
# Process each Markdown file
for file in `find . -name "*.md"`; do
# Remove the {{ page.title }} line and the following line with "---"
sed -i '' '/{{ page.title }}/d' "$file"
# Extract the date and city information
meta_data=$(sed -n 's/<p class="meta">\(.*\)<\/p>/\1/p' "$file")
day=$(echo "$meta_data" | awk '{print $1}')
month=$(echo "$meta_data" | awk '{print $2}')
year=$(echo "$meta_data" | awk '{print $3}')
city=$(echo "$meta_data" | awk '{print $5}')
# Remove the original <p class="meta"></p> line
sed -i '' '/<p class="meta">/d' "$file"
# Add city and date lines
sed -i '' "/title:/a\\
city: $city" "$file"
sed -i '' "/city: $city/a\\
date: $day $month $year" "$file"
done
# Return to the original directory (optional)
cd - || exit