-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify-site.sh
100 lines (86 loc) · 2.89 KB
/
verify-site.sh
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
BASE_DIR=./osc
# Initialize an empty array to store error messages
errors=()
# Function to check if the file has the correct extension
check_extension() {
for file in $(find "$BASE_DIR" -type f -name "*.markdown"); do
errors+=("File '$file' should have a .md extension, .markdown extension is not allowed.")
done
for file in $(find "$BASE_DIR/_posts" -type f ! -name "*.md"); do
errors+=("File '$file' should have a .md extension.")
done
}
# Function to check if markdown files in _posts have the required front matter
check_front_matter() {
for file in $(find "$BASE_DIR/_posts" -type f -name "*.md"); do
# Check for layout: post
if ! grep -q "^layout: post" "$file"; then
errors+=("File '$file' is missing 'layout: post'.")
fi
# Check for a date
if ! grep -q "^date: [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}" "$file"; then
errors+=("File '$file' is missing a valid date (YYYY-MM-DD).")
fi
# Check for a title
if ! grep -q "^title:" "$file"; then
errors+=("File '$file' is missing a 'title' field.")
fi
# Check for a category
if ! grep -q "^category:" "$file"; then
errors+=("File '$file' is missing a 'category' field.")
fi
# Check for an author
if ! grep -q "^author:" "$file"; then
errors+=("File '$file' is missing a 'author' field.")
fi
done
}
# Function to check if the categories are valid
check_categories() {
valid_categories=("news" "diary" "release", "session")
for file in $(find "$BASE_DIR/_posts" -type f -name "*.md"); do
# Extract the category field and trim leading/trailing spaces
category=$(grep "^category:" "$file" | sed 's/category:[[:space:]]*//')
# Check category
if [[ ! " ${valid_categories[@]} " =~ " ${category} " ]]; then
errors+=("File '$file' has an invalid category '$category'. Allowed categories: ${valid_categories[*]}")
fi
done
}
# Function to check markdown formatting (using markdownlint or similar)
check_formatting() {
for file in $(find "$BASE_DIR" -type f -name "*.md"); do
# Using markdownlint to check file formatting
lint_output=$(markdownlint "$file" 2>&1)
if [ $? -ne 0 ]; then
errors+=("File '$file' has markdownlint issues:\n$lint_output")
fi
done
}
# Check markdown links validity
check_links() {
for file in $(find "$BASE_DIR" -type f -name "*.md"); do
echo "Checking links in $file..."
lint_output=$(markdown-link-check "$file" 2>&1)
if [ $? -ne 0 ]; then
errors+=("File '$file' contains invalid links:\n$lint_output")
fi
done
}
# Run all checks
check_extension
check_front_matter
check_categories
check_formatting
check_links
# If there are errors, print them and exit with a failure status
if [ ${#errors[@]} -ne 0 ]; then
echo "The following errors were found:"
for error in "${errors[@]}"; do
echo "- $error"
done
exit 1
else
echo "All checks passed successfully."
fi