jekyll-tailwindcss 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +58 -51
- data/lib/jekyll/converters/css.rb +70 -0
- data/lib/jekyll/converters/tailwindcss.rb +28 -22
- data/lib/jekyll-tailwindcss/version.rb +1 -1
- data/lib/jekyll-tailwindcss.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ee5a9792a9b5cf2255d635a81aec5e938c6cda3b3ec233d9fac8e04ce92291f
|
4
|
+
data.tar.gz: 9b12d099c03f0d30c964af19b3ee416963ea832c17c56b3d3c0dda6fb61d3069
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96fe15592fa421840b7c76dd50560696f7fb0dadf20ab19e1d9aad852c1c5e7c1dd267e1cf7967826bfc17e90189afcff03562b3d611dd9e405d5351df10544c
|
7
|
+
data.tar.gz: bee07784b16ac19531147e2e554a9874e89bc0e0b73a8c07b28ffb13da8f70f88dfb00faa93f68876f6d94816f9ac55107a19b65fe7e2e3bb2c2422ca0d99af7
|
data/README.md
CHANGED
@@ -1,20 +1,15 @@
|
|
1
1
|
# Jekyll::Tailwindcss
|
2
2
|
|
3
|
-
Bring the
|
3
|
+
Bring the joy of building with TailwindCSS into your Jekyll project (without any JavaScript)
|
4
4
|
|
5
|
-
**TL;DR** This gem
|
5
|
+
**TL;DR** This gem uses [tailwindcss-ruby](https://github.com/rails/tailwindcss-ruby) to provide platform-specific tailwind executables and enables a smooth developer experience in Jekyll projects
|
6
6
|
|
7
|
-
> _"Because building a great
|
7
|
+
> _"Because building a great Jekyll site shouldn't require a `node_modules` folder"_
|
8
8
|
|
9
|
-
## Installation
|
10
|
-
|
11
|
-
Install the gem in your jekyll project's Gemfile by executing the following:
|
12
9
|
|
13
|
-
|
14
|
-
bundle add jekyll-tailwindcss --group jekyll_plugins
|
15
|
-
```
|
10
|
+
## Installation
|
16
11
|
|
17
|
-
|
12
|
+
Add the gem to your Jekyll project's Gemfile
|
18
13
|
|
19
14
|
```ruby
|
20
15
|
# Gemfile
|
@@ -25,10 +20,12 @@ group :jekyll_plugins do
|
|
25
20
|
end
|
26
21
|
```
|
27
22
|
|
28
|
-
|
29
|
-
|
23
|
+
Run `bundle install`
|
24
|
+
|
25
|
+
> [!TIP]
|
26
|
+
> By adding this gem to the `:jekyll_plugins` group, you don't need to explicitly configure it in `_config.yml`.
|
30
27
|
|
31
|
-
### Choosing a specific version of tailwindcss
|
28
|
+
### Optional: Choosing a specific version of tailwindcss
|
32
29
|
|
33
30
|
This gem uses the latest TailwindCSS by default. However since CLI versions are managed by the `tailwindcss-ruby` gem, it supports older versions as well.
|
34
31
|
|
@@ -56,7 +53,7 @@ tailwindcss:
|
|
56
53
|
config: "./tailwind.config.js"
|
57
54
|
```
|
58
55
|
|
59
|
-
Tailwind will generate CSS for the classes found in `content` directories. For most
|
56
|
+
Tailwind will generate CSS for the classes found in `content` directories. For most Jekyll sites, this would work well.
|
60
57
|
|
61
58
|
```js
|
62
59
|
// ./tailwind.config.js
|
@@ -83,7 +80,7 @@ Any CSS file with frontmatter and `@tailwind` directives will be converted.
|
|
83
80
|
```css
|
84
81
|
/* assets/css/styles.css */
|
85
82
|
---
|
86
|
-
# This yaml frontmatter is required for
|
83
|
+
# This yaml frontmatter is required for Jekyll to process the file
|
87
84
|
---
|
88
85
|
|
89
86
|
@tailwind base;
|
@@ -101,14 +98,21 @@ will be converted to
|
|
101
98
|
/* _site/assets/css/styles.css */
|
102
99
|
|
103
100
|
/*
|
104
|
-
* Tailwind generated CSS
|
101
|
+
* Tailwind generated CSS
|
105
102
|
* ...
|
106
103
|
*/
|
107
104
|
```
|
108
105
|
|
109
106
|
### PostCSS Support
|
110
107
|
|
111
|
-
|
108
|
+
> [!WARNING]
|
109
|
+
> PostCSS configuration is considered an advanced use case and is outside the scope of this gem.
|
110
|
+
> It is possible that support be removed in future versions of this gem. If needed, you should look to run your Tailwind builds with node.
|
111
|
+
|
112
|
+
That said... This gem includes basic PostCSS support. If a `postcss.config.js` file is included in your `_config.yml`, the Tailwind CLI will be invoked with the `--postcss` flag.
|
113
|
+
|
114
|
+
Users should verify their PostCSS setup outside this gem by running:
|
115
|
+
`bundle exec tailwindcss --postcss postcss.config.js`
|
112
116
|
|
113
117
|
```yaml
|
114
118
|
tailwindcss:
|
@@ -116,58 +120,61 @@ tailwindcss:
|
|
116
120
|
postcss: "./postcss.config.js" # OPTIONAL, only if you have a postcss config file
|
117
121
|
```
|
118
122
|
|
119
|
-
> [!NOTE]
|
120
|
-
> PostCSS configuration is considered an advanced use case and is outside the scope of this gem. Users should verify their PostCSS setup outside this gem by running:
|
121
|
-
> `bundle exec tailwindcss --postcss postcss.config.js`
|
122
123
|
|
123
124
|
</details>
|
124
125
|
|
125
126
|
## Usage
|
126
127
|
|
127
|
-
|
128
|
-
bundle exec jekyll serve # or build
|
129
|
-
```
|
128
|
+
> See an example repo at https://github.com/vormwald/jekyll-blahg
|
130
129
|
|
131
|
-
|
130
|
+
### Setup
|
131
|
+
You'll need 2 files to make this work:
|
132
132
|
|
133
|
-
|
133
|
+
**File 1: `./_tailwind.css`**
|
134
134
|
|
135
|
-
|
136
|
-
Any CSS file with frontmatter and `@import "tailwindcss";` will be converted.
|
137
|
-
|
138
|
-
Your CSS file
|
135
|
+
This file acts as your tailwind configuration file. Import "tailwindcss" and any custom CSS here.
|
139
136
|
|
140
137
|
```css
|
141
|
-
/* assets/css/styles.css */
|
142
|
-
---
|
143
|
-
# This yaml frontmatter is required for jekyll to process the file
|
144
|
-
---
|
145
|
-
|
146
138
|
@import "tailwindcss";
|
147
139
|
|
148
|
-
|
149
|
-
@apply rounded border border-gray-300;
|
150
|
-
}
|
140
|
+
/* ... any other imports or css classes */
|
151
141
|
```
|
152
142
|
|
153
|
-
will be converted to
|
154
143
|
|
155
|
-
|
156
|
-
/* _site/assets/css/styles.css */
|
144
|
+
**File 2: `./assets/css/styles.tailwindcss`**
|
157
145
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
* ...
|
168
|
-
*/
|
146
|
+
Place this file wherever you'd like your site's tailwind CLI generated content to go: `assets/css/your_css_file.tailwindcss` -> `__site/assets/css/your_css_file.css`
|
147
|
+
|
148
|
+
It must contain yaml frontmatter to be processed by Jekyll [^1]
|
149
|
+
|
150
|
+
```yaml
|
151
|
+
---
|
152
|
+
# This file will be converted to __site/assets/css/styles.css
|
153
|
+
---
|
154
|
+
This file is just a placeholder. It's content will be replaced by output from the tailwindcss CLI.
|
169
155
|
```
|
170
156
|
|
157
|
+
> [!NOTE]
|
158
|
+
> Why the 2 files?
|
159
|
+
>
|
160
|
+
> This is a compromise to allow the [TailwindCSS intellisense](https://tailwindcss.com/docs/editor-setup#intellisense-for-vs-code) plugin to work. (It cannot parse a CSS file with frontmatter, so we keep it seperate)
|
161
|
+
>
|
162
|
+
> The `_tailwind.css` file serves as the tailwindcss config file.
|
163
|
+
> If you'd rather set keep this file somewhere else, you can do so by setting the `tailwindcss.config_file` option in `_config.yml`:
|
164
|
+
>
|
165
|
+
> ```yaml
|
166
|
+
> tailwindcss:
|
167
|
+
> config_file: ./_data/tailwind.css
|
168
|
+
> ```
|
169
|
+
|
170
|
+
### Building the Jekyll site
|
171
|
+
|
172
|
+
```sh
|
173
|
+
bundle exec jekyll serve
|
174
|
+
```
|
175
|
+
[^1]: Jekyll will process any file that begins with yaml [frontmatter](https://jekyllrb.com/docs/front-matter/)
|
176
|
+
|
177
|
+
|
171
178
|
### Minification
|
172
179
|
|
173
180
|
The `--minify` flag is automatically added when the `JEKYLL_ENV` environment variable is present and set to anything other than `development`. [Jekyll Docs](https://jekyllrb.com/docs/configuration/environments/)
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "open3"
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Converters
|
5
|
+
class Css < Converter
|
6
|
+
safe true
|
7
|
+
priority :low
|
8
|
+
|
9
|
+
def matches(ext)
|
10
|
+
/^\.css$/i.match?(ext)
|
11
|
+
end
|
12
|
+
|
13
|
+
def output_ext(ext)
|
14
|
+
# At this point, we will have a CSS file
|
15
|
+
ext
|
16
|
+
end
|
17
|
+
|
18
|
+
def convert(content)
|
19
|
+
return content unless /@tailwind|@import ['"]tailwindcss/i.match?(content)
|
20
|
+
if config_path.nil? && tailwind_v3_syntax?(content)
|
21
|
+
Jekyll.logger.error "Jekyll Tailwind:", "to use tailwind v3 you need to include a config path in _config.yml"
|
22
|
+
return content
|
23
|
+
end
|
24
|
+
|
25
|
+
dev_mode = Jekyll.env == "development"
|
26
|
+
Jekyll.logger.info "Jekyll Tailwind:", "Generating #{dev_mode ? "" : "minified "}CSS"
|
27
|
+
|
28
|
+
compile_command = ::Tailwindcss::Commands
|
29
|
+
.compile_command(debug: dev_mode, config_path: config_path, postcss_path: postcss_path)
|
30
|
+
.join(" ")
|
31
|
+
|
32
|
+
output, error = nil
|
33
|
+
Open3.popen3(tailwindcss_env_options, compile_command) do |stdin, stdout, stderr, _wait_thread|
|
34
|
+
stdin.write content # write the content of *.tailwindcss to the tailwindcss CLI as input
|
35
|
+
stdin.close
|
36
|
+
output = stdout.read
|
37
|
+
error = stderr.read
|
38
|
+
end
|
39
|
+
Jekyll.logger.warn "Jekyll Tailwind:", error unless error.nil?
|
40
|
+
|
41
|
+
output
|
42
|
+
rescue => e
|
43
|
+
Jekyll.logger.error "Jekyll Tailwind:", e.message
|
44
|
+
content
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def tailwind_v3_syntax?(content)
|
50
|
+
return false if content.include?("@plugin")
|
51
|
+
|
52
|
+
content.include?("@tailwind")
|
53
|
+
end
|
54
|
+
|
55
|
+
def tailwindcss_env_options
|
56
|
+
# Without this ENV you'll get a warning about `Browserslist: caniuse-lite is outdated`
|
57
|
+
# Since we're using the CLI, we can't update the data, so we ignore it.
|
58
|
+
{"BROWSERSLIST_IGNORE_OLD_DATA" => "1"}
|
59
|
+
end
|
60
|
+
|
61
|
+
def config_path
|
62
|
+
@config.dig("tailwindcss", "config")
|
63
|
+
end
|
64
|
+
|
65
|
+
def postcss_path
|
66
|
+
@config.dig("tailwindcss", "postcss")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -5,33 +5,33 @@ module Jekyll
|
|
5
5
|
class Tailwindcss < Converter
|
6
6
|
safe true
|
7
7
|
priority :low
|
8
|
+
EXTENSION_PATTERN = %r{^\.tailwind(css)?$}i
|
8
9
|
|
9
10
|
def matches(ext)
|
10
|
-
|
11
|
+
EXTENSION_PATTERN.match? ext
|
11
12
|
end
|
12
13
|
|
13
14
|
def output_ext(ext)
|
14
|
-
|
15
|
-
ext
|
15
|
+
".css"
|
16
16
|
end
|
17
17
|
|
18
18
|
def convert(content)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
return
|
19
|
+
unless valid_tailwindcss_gem_version?
|
20
|
+
print_tailwind_v3_warning
|
21
|
+
|
22
|
+
return
|
23
23
|
end
|
24
24
|
|
25
25
|
dev_mode = Jekyll.env == "development"
|
26
26
|
Jekyll.logger.info "Jekyll Tailwind:", "Generating #{dev_mode ? "" : "minified "}CSS"
|
27
27
|
|
28
28
|
compile_command = ::Tailwindcss::Commands
|
29
|
-
.compile_command(debug: dev_mode
|
29
|
+
.compile_command(debug: dev_mode)
|
30
30
|
.join(" ")
|
31
31
|
|
32
32
|
output, error = nil
|
33
|
-
Open3.popen3(
|
34
|
-
stdin.write
|
33
|
+
Open3.popen3(compile_command) do |stdin, stdout, stderr, _wait_thread|
|
34
|
+
stdin.write tailwind_content
|
35
35
|
stdin.close
|
36
36
|
output = stdout.read
|
37
37
|
error = stderr.read
|
@@ -46,24 +46,30 @@ module Jekyll
|
|
46
46
|
|
47
47
|
private
|
48
48
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
content.include?("@tailwind")
|
49
|
+
def tailwind_content
|
50
|
+
"@import '#{tailwind_css_path}';"
|
53
51
|
end
|
54
52
|
|
55
|
-
def
|
56
|
-
|
57
|
-
# Since we're using the CLI, we can't update the data, so we ignore it.
|
58
|
-
{"BROWSERSLIST_IGNORE_OLD_DATA" => "1"}
|
53
|
+
def tailwind_css_path
|
54
|
+
@config.dig("tailwindcss", "css_path") || "./_tailwind.css"
|
59
55
|
end
|
60
56
|
|
61
|
-
def
|
62
|
-
|
57
|
+
def valid_tailwindcss_gem_version?
|
58
|
+
gem_spec = Gem.loaded_specs["tailwindcss-ruby"]
|
59
|
+
return false unless gem_spec
|
60
|
+
|
61
|
+
Gem::Version.new(gem_spec.version) >= Gem::Version.new("4.0.0")
|
62
|
+
rescue
|
63
|
+
# If anything goes wrong (gem not found, version format issues, etc.)
|
64
|
+
false
|
63
65
|
end
|
64
66
|
|
65
|
-
def
|
66
|
-
|
67
|
+
def print_tailwind_v3_warning
|
68
|
+
Jekyll.logger.warn "Jekyll Tailwind:", "You're using a .tailwindcss file extension, but your tailwindcss-ruby gem is below version 4.0."
|
69
|
+
Jekyll.logger.warn "Jekyll Tailwind:", "The .tailwindcss extension is only supported in v4.0.0 and above."
|
70
|
+
Jekyll.logger.warn "Jekyll Tailwind:", "Please either:"
|
71
|
+
Jekyll.logger.warn "Jekyll Tailwind:", " - Upgrade with: bundle update tailwindcss-ruby"
|
72
|
+
Jekyll.logger.warn "Jekyll Tailwind:", " - Rename your file to use .css extension with @import \"tailwindcss\" syntax"
|
67
73
|
end
|
68
74
|
end
|
69
75
|
end
|
data/lib/jekyll-tailwindcss.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-tailwindcss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Vormwald
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-04-12 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: tailwindcss-ruby
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- Rakefile
|
35
35
|
- lib/jekyll-tailwindcss.rb
|
36
36
|
- lib/jekyll-tailwindcss/version.rb
|
37
|
+
- lib/jekyll/converters/css.rb
|
37
38
|
- lib/jekyll/converters/tailwindcss.rb
|
38
39
|
- lib/tailwindcss/commands.rb
|
39
40
|
homepage: https://github.com/vormwald/jekyll-tailwindcss
|