-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·114 lines (90 loc) · 3.29 KB
/
build.sh
File metadata and controls
executable file
·114 lines (90 loc) · 3.29 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
# Build script for BitDevs Melbourne site
# Converts markdown posts to HTML using pandoc and formats with prettier
echo "🚀 Building BitDevs Melbourne site..."
# Create posts directory if it doesn't exist
mkdir -p posts
# Convert all markdown posts
echo "📝 Converting markdown posts to HTML..."
for md_file in _posts/*.md; do
if [[ -f "$md_file" ]]; then
# Extract filename without path and extension
filename=$(basename "$md_file" .md)
# Skip template file
if [[ "$filename" == "2023-01-01-template" ]]; then
continue
fi
echo " Converting $filename.md..."
# Extract title and date from frontmatter
title=$(grep '^title:' "$md_file" | sed 's/title: *"\?\([^"]*\)"\?/\1/')
date=$(grep '^date:' "$md_file" | sed 's/date: *"\?\([^"]*\)"\?.*/\1/' | cut -d' ' -f1)
# Fallback if no frontmatter found
if [[ -z "$title" ]]; then
title="$filename"
fi
if [[ -z "$date" ]]; then
date="${filename%%-*}-${filename#*-}"
fi
# Convert with pandoc using our template
pandoc "$md_file" \
--template=template.html \
--metadata title="$title" \
--metadata date="$date" \
-o "posts/$filename.html"
fi
done
# Generate post list for JavaScript files
echo "📋 Generating post list..."
python3 << 'EOF'
import os
import glob
import json
import re
from datetime import datetime
posts = []
for md_file in glob.glob('_posts/*.md'):
filename = os.path.basename(md_file)[:-3] # Remove .md
if filename == '2023-01-01-template':
continue
# Extract title and date from frontmatter
with open(md_file, 'r') as f:
content = f.read()
title_match = re.search(r'^title:\s*["\']?([^"\']*)["\']?', content, re.MULTILINE)
date_match = re.search(r'^date:\s*["\']?([^"\']*)["\']?', content, re.MULTILINE)
if title_match:
title = title_match.group(1).strip()
else:
title = filename
if date_match:
date_str = date_match.group(1).split()[0] # Take just the date part
else:
date_str = filename[:10] # YYYY-MM-DD from filename
posts.append({
'date': date_str,
'title': title,
'url': f'posts/{filename}.html'
})
# Sort by date descending
posts.sort(key=lambda x: x['date'], reverse=True)
# Update index.html (all posts)
with open('index.html', 'r') as f:
content = f.read()
js_all_posts = json.dumps(posts, indent=8)
pattern = r'const allPosts = \[.*?\];'
replacement = f'const allPosts = {js_all_posts};'
content = re.sub(pattern, replacement, content, flags=re.DOTALL)
with open('index.html', 'w') as f:
f.write(content)
print(f"Generated {len(posts)} posts")
EOF
# Format all HTML files with prettier
echo "✨ Formatting with prettier..."
if command -v npx >/dev/null 2>&1; then
npx prettier --write "*.html" "posts/*.html" 2>/dev/null || echo " Prettier formatting skipped (not available)"
else
echo " Prettier not available, skipping formatting"
fi
# Clean up any temp files
rm -f posts.html 2>/dev/null
echo "✅ Build complete! Generated $(ls posts/*.html | wc -l) posts"
echo "📁 Open index.html in a browser to view the site"