1+ #! /bin/bash
2+
3+ # Jekyll Local Development Server Script
4+ # This script sets up and runs the Jekyll site locally for development
5+
6+ set -e # Exit on any error
7+
8+ # Color codes for output formatting
9+ RED=' \033[0;31m'
10+ GREEN=' \033[0;32m'
11+ YELLOW=' \033[1;33m'
12+ BLUE=' \033[0;34m'
13+ NC=' \033[0m' # No Color
14+
15+ # Function to print colored output
16+ print_info () {
17+ echo -e " ${BLUE} [INFO]${NC} $1 "
18+ }
19+
20+ print_success () {
21+ echo -e " ${GREEN} [SUCCESS]${NC} $1 "
22+ }
23+
24+ print_warning () {
25+ echo -e " ${YELLOW} [WARNING]${NC} $1 "
26+ }
27+
28+ print_error () {
29+ echo -e " ${RED} [ERROR]${NC} $1 "
30+ }
31+
32+ # Check if bundle command is available
33+ check_bundle () {
34+ if ! command -v bundle & > /dev/null; then
35+ print_error " bundle command not found!"
36+ print_info " Please install Ruby and Bundler:"
37+ print_info " - Install Ruby: https://www.ruby-lang.org/en/documentation/installation/"
38+ print_info " - Install Bundler: gem install bundler"
39+ exit 1
40+ fi
41+ print_success " Bundler is installed"
42+ }
43+
44+ # Check if Gemfile exists
45+ check_gemfile () {
46+ if [ ! -f " Gemfile" ]; then
47+ print_error " Gemfile not found in current directory!"
48+ print_info " Please run this script from the Jekyll project root"
49+ exit 1
50+ fi
51+ print_success " Gemfile found"
52+ }
53+
54+ # Install dependencies
55+ install_dependencies () {
56+ print_info " Installing dependencies..."
57+ bundle install
58+ print_success " Dependencies installed successfully"
59+ }
60+
61+ # Clean previous builds (optional)
62+ clean_build () {
63+ read -p " Do you want to clean previous builds? (y/n): " -n 1 -r
64+ echo
65+ if [[ $REPLY =~ ^[Yy]$ ]]; then
66+ print_info " Cleaning previous builds..."
67+ rm -rf _site
68+ rm -rf .jekyll-cache
69+ print_success " Build directory cleaned"
70+ fi
71+ }
72+
73+ # Start Jekyll development server
74+ start_server () {
75+ print_info " Starting Jekyll development server..."
76+ print_info " Server will be available at: http://localhost:4000"
77+ print_info " Press Ctrl+C to stop the server"
78+ echo
79+
80+ # Start Jekyll with live reload
81+ bundle exec jekyll serve --watch --livereload
82+ }
83+
84+ # Main execution
85+ main () {
86+ echo " ========================================="
87+ echo " Jekyll Local Development Server"
88+ echo " ========================================="
89+ echo
90+
91+ # Run checks and setup
92+ check_bundle
93+ check_gemfile
94+ install_dependencies
95+ clean_build
96+
97+ echo
98+ print_info " Starting server..."
99+ echo
100+
101+ # Start the server
102+ start_server
103+ }
104+
105+ # Run main function
106+ main
0 commit comments