-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
94 lines (77 loc) · 2.57 KB
/
Rakefile
File metadata and controls
94 lines (77 loc) · 2.57 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
# Rakefile for Jekyll site
# Compatible with Ruby 3.4.2 and Bundler
# Matches Gemfile + GitHub Actions configuration
require "rake"
require "fileutils"
abort("✗ You must run this with Ruby 3.4.2!") unless RUBY_VERSION.start_with?("3.4.2")
JEKYLL_ENV = ENV["JEKYLL_ENV"] || "production"
CONFIG_FILE = JEKYLL_ENV == "development" ? "_config_dev.yml" : "_config.yml"
SITE_DIR = "_site"
CACHE_DIRS = [".jekyll-cache", ".sass-cache"]
def sh_with_env(command)
puts "\n==> [#{JEKYLL_ENV}] Running: #{command}\n\n"
system({ "JEKYLL_ENV" => JEKYLL_ENV }, command) || abort("\n✗ Command failed: #{command}")
end
desc "Build the site for the current environment"
task :build do
sh_with_env("bundle exec jekyll build --config #{CONFIG_FILE}")
end
desc "Serve the site locally with drafts (development only)"
task :serve do
ENV["JEKYLL_ENV"] = "development"
sh_with_env("bundle exec jekyll serve --config _config_dev.yml,_config.yml --future --drafts --incremental --livereload")
end
desc "Clean build and cache directories"
task :clean do
puts "Cleaning build and cache directories..."
FileUtils.rm_rf(SITE_DIR)
CACHE_DIRS.each { |dir| FileUtils.rm_rf(dir) }
puts "✓ Clean complete."
end
desc "Clean generated responsive images"
task :clean_images do
FileUtils.rm_rf("assets/generated")
puts "✓ Removed generated responsive images."
end
desc "Check Jekyll configuration and output directories"
task :check do
puts "\nChecking Jekyll configuration..."
sh_with_env("bundle exec jekyll doctor")
end
desc "Ping search engines with updated sitemaps"
task :ping do
require "net/http"
urls = [
"https://www.google.com/ping?sitemap=https://jameshoward.us/sitemap.xml",
"https://www.bing.com/ping?sitemap=https://jameshoward.us/sitemap.xml"
]
urls.each do |url|
uri = URI(url)
res = Net::HTTP.get_response(uri)
puts "→ #{url}: #{res.code}"
end
end
desc "Show Ruby, Bundler, and Jekyll versions"
task :env do
puts "\n== Environment Info =="
system("ruby -v")
system("bundle -v")
system("bundle exec jekyll -v")
puts "JEKYLL_ENV=#{JEKYLL_ENV}"
puts "Config file: #{CONFIG_FILE}"
end
desc "Create a post from template using: rake create_post YYYY-MM-DD \"Title of Post\""
task :create_post do
if ARGV.length < 3
puts "Usage: rake create_post YYYY-MM-DD \"Title of Post\""
exit 1
end
date = ARGV[1]
title = ARGV[2..-1].join(" ")
ruby_script = File.expand_path("_scripts/create_post.rb")
unless File.exist?(ruby_script)
raise "Script not found at #{ruby_script}"
end
exec("ruby", ruby_script, date, title)
end
task default: :build