Skip to content

Commit c045c89

Browse files
committed
Rename and update Tailwind incremental fix plugin to PostCSS incremental fix, expand detection to CSS partials, and update associated tests and tasks.
1 parent ec738a9 commit c045c89

File tree

3 files changed

+60
-14
lines changed

3 files changed

+60
-14
lines changed

Rakefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CONFIG = "_config.yml"
1414
task default: [:build]
1515

1616
desc "Run tests (test-linter, lint, build)"
17-
task test: %i[test-news-plugin test-html-lang-plugin test-tailwind-incremental-fix-plugin test-linter lint build]
17+
task test: %i[test-news-plugin test-html-lang-plugin test-postcss-incremental-fix-plugin test-linter lint build]
1818

1919
desc "Build the Jekyll site"
2020
task :build do
@@ -139,9 +139,9 @@ Rake::TestTask.new(:"test-html-lang-plugin") do |t|
139139
end
140140

141141
require "rake/testtask"
142-
Rake::TestTask.new(:"test-tailwind-incremental-fix-plugin") do |t|
143-
t.description = "Run tests for the Tailwind incremental fix plugin"
142+
Rake::TestTask.new(:"test-postcss-incremental-fix-plugin") do |t|
143+
t.description = "Run tests for the PostCSS incremental fix plugin"
144144
t.libs = ["test"]
145-
t.test_files = FileList['test/test_plugin_tailwind_incremental_fix.rb']
145+
t.test_files = FileList['test/test_plugin_postcss_incremental_fix.rb']
146146
t.verbose = true
147-
end
147+
end
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Regenerate CSS only when HTML/Markdown files change
1+
# Regenerate CSS when HTML/Markdown files or imported CSS partials change
2+
# Detects changes in content files and CSS partials (e.g., _components/*.css, _variables.css)
3+
# to trigger PostCSS rebuild via jekyll-postcss-v2 plugin
24

35
module Jekyll
46
module PostcssTrigger
@@ -22,8 +24,8 @@ class << self
2224
# Skip if CSS was already touched in this build
2325
next if Jekyll::PostcssTrigger.css_touched
2426

25-
# Check if any HTML/Markdown files have changed
26-
content_patterns = %w[_layouts/**/*.html _includes/**/*.html *.html *.md */**/*.html */**/*.md]
27+
# Check if any HTML/Markdown files or included CSS files have changed
28+
content_patterns = %w[_layouts/**/*.html _includes/**/*.html *.html *.md */**/*.html */**/*.md stylesheets/**/_*.css stylesheets/_*/**/*.css]
2729

2830
html_changed = false
2931
last_check = Jekyll::PostcssTrigger.last_check_time

test/test_plugin_tailwind_incremental_fix.rb renamed to test/test_plugin_postcss_incremental_fix.rb

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require "jekyll"
55
require "fileutils"
66
require "time"
7-
require_relative "../_plugins/tailwind_incremental_fix"
7+
require_relative "../_plugins/postcss_incremental_fix"
88

99
describe Jekyll::PostcssTrigger do
1010
before do
@@ -37,7 +37,7 @@
3737
end
3838
end
3939

40-
describe "integration: HTML change triggers CSS rebuild" do
40+
describe "integration: HTML change triggers CSS rebuild" do
4141
before do
4242
chdir_tempdir
4343
create_file("stylesheets/main.css", "/* css */")
@@ -61,7 +61,7 @@
6161

6262
Jekyll::Hooks.trigger :site, :post_read, @site
6363

64-
_(Jekyll::PostcssTrigger. last_check_time).wont_be_nil
64+
_(Jekyll::PostcssTrigger.last_check_time).wont_be_nil
6565
_(Jekyll::PostcssTrigger.css_touched).must_equal false
6666
end
6767

@@ -71,13 +71,13 @@
7171

7272
# First build - establish baseline
7373
Jekyll::Hooks.trigger :site, :post_read, @site
74-
first_check_time = Jekyll::PostcssTrigger. last_check_time
74+
first_check_time = Jekyll::PostcssTrigger.last_check_time
7575

7676
sleep 0.2
7777

7878
# NOW modify HTML file (after first build)
7979
create_file("index.html", "<html>modified</html>")
80-
css_original_mtime = File. mtime("stylesheets/main.css")
80+
css_original_mtime = File.mtime("stylesheets/main.css")
8181

8282
sleep 0.1
8383

@@ -90,7 +90,7 @@
9090

9191
it "touches CSS when markdown file changes" do
9292
# Create markdown file first
93-
create_file("about. md", "# About Page")
93+
create_file("about.md", "# About Page")
9494

9595
# First build
9696
Jekyll::Hooks.trigger :site, :post_read, @site
@@ -110,6 +110,50 @@
110110
_(File.mtime("stylesheets/main.css") > css_original_mtime).must_equal true
111111
end
112112

113+
it "touches CSS when CSS partial (e.g. _variables.css) changes" do
114+
# Create CSS partial first
115+
create_file("stylesheets/_variables.css", ":root { --color: red; }")
116+
117+
# First build
118+
Jekyll::Hooks.trigger :site, :post_read, @site
119+
120+
sleep 0.2
121+
122+
# Modify CSS partial
123+
create_file("stylesheets/_variables.css", ":root { --color: blue; }")
124+
css_original_mtime = File.mtime("stylesheets/main.css")
125+
126+
sleep 0.1
127+
128+
# Second build
129+
Jekyll::Hooks.trigger :site, :post_read, @site
130+
131+
_(Jekyll::PostcssTrigger.css_touched).must_equal true
132+
_(File.mtime("stylesheets/main.css") > css_original_mtime).must_equal true
133+
end
134+
135+
it "touches CSS when CSS file in sub-directory (e.g. _components/*.css) changes" do
136+
# Create CSS file in sub-directory first
137+
create_file("stylesheets/_components/base.css", ".btn { color: red; }")
138+
139+
# First build
140+
Jekyll::Hooks.trigger :site, :post_read, @site
141+
142+
sleep 0.2
143+
144+
# Modify CSS file in sub-directory
145+
create_file("stylesheets/_components/base.css", ".btn { color: blue; }")
146+
css_original_mtime = File.mtime("stylesheets/main.css")
147+
148+
sleep 0.1
149+
150+
# Second build
151+
Jekyll::Hooks.trigger :site, :post_read, @site
152+
153+
_(Jekyll::PostcssTrigger.css_touched).must_equal true
154+
_(File.mtime("stylesheets/main.css") > css_original_mtime).must_equal true
155+
end
156+
113157
it "touches CSS when layout file changes" do
114158
# Create layout file first
115159
create_file("_layouts/default.html", "<html>{{ content }}</html>")

0 commit comments

Comments
 (0)