-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathalter.sh
More file actions
executable file
·40 lines (33 loc) · 950 Bytes
/
alter.sh
File metadata and controls
executable file
·40 lines (33 loc) · 950 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
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# Check if directory argument is provided
if [ -z "$1" ]; then
echo "Usage: $0 <directory>"
exit 1
fi
DIR="$1"
# Check if directory exists
if [ ! -d "$DIR" ]; then
echo "Directory does not exist: $DIR"
exit 1
fi
# Lines to add
prepend="layout: \"../../layouts/page.astro\"
variant: \"article\""
# Loop through all .mdx files in the directory
for file in "$DIR"/*.mdx; do
# Skip if no files found
[ -e "$file" ] || continue
# Check if file contains front matter
if grep -q '^---' "$file"; then
# Check if lines are already present
if ! grep -q 'layout: "../../layouts/page.astro"' "$file"; then
# Insert lines after first ---
awk -v prepend="$prepend" 'NR==1{print; print prepend; next}1' "$file" > tmpfile && mv tmpfile "$file"
echo "Updated $file"
else
echo "Already contains layout/variant: $file"
fi
else
echo "No front matter found in $file, skipping..."
fi
done