jekyll-github-code 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cf7c2830265d7dc0c56dd352412820a1cae0df5289030dc0825da1a9f9c9b5d8
4
+ data.tar.gz: a14cad52d57785d3b77ff1393dafe6b5ef790d7b48a6cbe01dab65d2a69f24cf
5
+ SHA512:
6
+ metadata.gz: 3803d1ad25166a79ddc769b4fc1f1b2f3d0a9bcdd851dfb5b7f4bab677a96214d2e98614ef0f1d95e2569e0da2b75030e18cfb6ba10e134ec81eefd1395eed7a
7
+ data.tar.gz: a99f5ca6f838459883c5ecc0bb96ef4ac98fb7885daf9b81981d128dfce9c635ceffe77c6c3b49d84d99ff9de6665887bb768b17f8e4f0551b141e7955afbcde
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_PATH: "vendor/bundle"
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] - 2025-12-12
9
+
10
+ ### Added
11
+
12
+ - Initial release
13
+ - `{% github_code %}` Liquid tag for embedding GitHub code
14
+ - Support for full file embedding
15
+ - Support for line range selection (`#L5-L15`)
16
+ - Support for single line selection (`#L10`)
17
+ - Automatic language detection based on file extension
18
+ - Copy-to-clipboard button
19
+ - Clickable filename linking to GitHub
20
+ - Dark and light theme support
21
+ - Compatible with Jekyll Chirpy theme
22
+ - Comprehensive test suite
23
+
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in jekyll-github-code.gemspec
6
+ gemspec
7
+
8
+ group :development do
9
+ gem 'rubocop', '~> 1.57', require: false
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Rodolfo Olivieri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,245 @@
1
+ # Jekyll GitHub Code
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/jekyll-github-code.svg)](https://badge.fury.io/rb/jekyll-github-code)
4
+ [![Ruby](https://github.com/r0x0d/jekyll-github-code/actions/workflows/ruby.yml/badge.svg)](https://github.com/r0x0d/jekyll-github-code/actions/workflows/ruby.yml)
5
+
6
+ A Jekyll plugin that lets you embed code from GitHub repositories directly in your blog posts. Perfect for technical blogs, especially those using the [Chirpy theme](https://github.com/cotes2020/jekyll-theme-chirpy).
7
+
8
+ ## Features
9
+
10
+ - **Embed full files** from any public GitHub repository
11
+ - **Line range support** - show only specific lines (`#L5-L15`)
12
+ - **Automatic syntax highlighting** based on file extension
13
+ - **Copy button** for easy code copying
14
+ - **Clickable filename** links directly to GitHub
15
+ - **Dark/light mode support** compatible with Chirpy theme
16
+ - **Graceful error handling** with informative messages
17
+
18
+ ## Installation
19
+
20
+ Add this line to your Jekyll site's `Gemfile`:
21
+
22
+ ```ruby
23
+ gem 'jekyll-github-code'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ ```bash
29
+ bundle install
30
+ ```
31
+
32
+ Or install it yourself as:
33
+
34
+ ```bash
35
+ gem install jekyll-github-code
36
+ ```
37
+
38
+ ### Configure Jekyll
39
+
40
+ Add the plugin to your `_config.yml`:
41
+
42
+ ```yaml
43
+ plugins:
44
+ - jekyll-github-code
45
+ ```
46
+
47
+ ### Add the Styles
48
+
49
+ Copy the SCSS file to your `_sass` directory or add these styles to your main stylesheet.
50
+
51
+ You can find the styles in `assets/css/github-code.scss` in this repository.
52
+
53
+ For Chirpy theme, add to `assets/css/jekyll-theme-chirpy.scss`:
54
+
55
+ ```scss
56
+ @import "github-code";
57
+ ```
58
+
59
+ ### Add the JavaScript (optional, for copy button)
60
+
61
+ Add the contents of `assets/js/github-code.js` to your site's JavaScript, or include it directly:
62
+
63
+ ```html
64
+ <script src="/assets/js/github-code.js"></script>
65
+ ```
66
+
67
+ ## Usage
68
+
69
+ ### Basic Usage - Full File
70
+
71
+ ```liquid
72
+ {% github_code owner/repo/blob/branch/path/to/file.py %}
73
+ ```
74
+
75
+ **Example:**
76
+
77
+ ```liquid
78
+ {% github_code r0x0d/toolbox-dev/blob/main/toolbox/environment/fedora-packaging.Containerfile %}
79
+ ```
80
+
81
+ ### With Line Range
82
+
83
+ Show only specific lines:
84
+
85
+ ```liquid
86
+ {% github_code owner/repo/blob/branch/path/to/file.py#L5-L15 %}
87
+ ```
88
+
89
+ **Example:**
90
+
91
+ ```liquid
92
+ {% github_code r0x0d/toolbox-dev/blob/main/toolbox/environment/fedora-packaging.Containerfile#L5-L15 %}
93
+ ```
94
+
95
+ ### Single Line
96
+
97
+ ```liquid
98
+ {% github_code owner/repo/blob/branch/path/to/file.py#L10 %}
99
+ ```
100
+
101
+ ### Full GitHub URL
102
+
103
+ You can also use the complete GitHub URL:
104
+
105
+ ```liquid
106
+ {% github_code https://github.com/owner/repo/blob/branch/path/to/file.py %}
107
+ ```
108
+
109
+ ## Supported Languages
110
+
111
+ The plugin automatically detects the language from the file extension:
112
+
113
+ | Extension | Language |
114
+ |-----------|----------|
115
+ | `.rb` | Ruby |
116
+ | `.py` | Python |
117
+ | `.js` | JavaScript |
118
+ | `.ts` | TypeScript |
119
+ | `.yml`, `.yaml` | YAML |
120
+ | `.md` | Markdown |
121
+ | `.sh` | Bash |
122
+ | `.Dockerfile`, `.Containerfile` | Dockerfile |
123
+ | Others | Uses extension as-is |
124
+
125
+ ## Theme Support
126
+
127
+ The plugin supports both light and dark themes out of the box, compatible with multiple theme systems:
128
+
129
+ ### Supported Theme Selectors
130
+
131
+ - `[data-mode="light"]` - Chirpy theme
132
+ - `[data-theme="light"]` - Common theme attribute
133
+ - `.light` - Class-based themes
134
+ - `@media (prefers-color-scheme: light)` - System preference
135
+
136
+ The default is dark theme. Light theme is automatically applied when any of the above selectors match.
137
+
138
+ ### CSS Variables
139
+
140
+ You can customize the appearance by overriding CSS variables:
141
+
142
+ ```css
143
+ .github-code-block {
144
+ --github-code-bg: #0d1117;
145
+ --github-code-header-bg: #161b22;
146
+ --github-code-border: #30363d;
147
+ --github-code-text: #e6edf3;
148
+ --github-code-text-secondary: #8b949e;
149
+ --github-code-link: #58a6ff;
150
+ --github-code-link-hover: #79c0ff;
151
+ --github-code-copy-hover: #238636;
152
+ }
153
+ ```
154
+
155
+ Light theme values are automatically applied, but you can also customize them:
156
+
157
+ ```css
158
+ [data-mode="light"] .github-code-block {
159
+ --github-code-bg: #ffffff;
160
+ --github-code-header-bg: #f6f8fa;
161
+ --github-code-border: #d0d7de;
162
+ --github-code-text: #1f2328;
163
+ --github-code-text-secondary: #656d76;
164
+ --github-code-link: #0969da;
165
+ --github-code-link-hover: #0550ae;
166
+ }
167
+ ```
168
+
169
+ ## Development
170
+
171
+ After checking out the repo, run `bundle install` to install dependencies.
172
+
173
+ ### Running Tests
174
+
175
+ ```bash
176
+ bundle exec rake test
177
+ ```
178
+
179
+ Or run tests directly:
180
+
181
+ ```bash
182
+ bundle exec ruby -Ilib -Itest test/github_code_test.rb
183
+ ```
184
+
185
+ ### Building the Gem
186
+
187
+ ```bash
188
+ bundle exec rake build
189
+ ```
190
+
191
+ ### Installing Locally
192
+
193
+ ```bash
194
+ bundle exec rake install
195
+ ```
196
+
197
+ ### Releasing
198
+
199
+ To release a new version:
200
+
201
+ 1. Update the version number in `lib/jekyll-github-code/version.rb`
202
+ 2. Update `CHANGELOG.md`
203
+ 3. Run `bundle exec rake release`
204
+
205
+ ## Demo
206
+
207
+ Open `demo.html` in your browser to see a preview of the rendered output with different examples.
208
+
209
+ ## How It Works
210
+
211
+ 1. The Liquid tag parses the GitHub reference (owner/repo/branch/path)
212
+ 2. Fetches the raw file content from `raw.githubusercontent.com`
213
+ 3. Extracts the specified line range (if provided)
214
+ 4. Escapes HTML entities in the code
215
+ 5. Renders a styled code block with:
216
+ - GitHub icon and clickable filename
217
+ - Copy button
218
+ - Syntax-highlighted code
219
+
220
+ ## Caching
221
+
222
+ The plugin fetches code at build time. For production, consider:
223
+
224
+ - Using Jekyll caching plugins
225
+ - Setting up GitHub Actions with caching
226
+ - Pre-generating static includes for frequently used snippets
227
+
228
+ ## Error Handling
229
+
230
+ If the code cannot be fetched (e.g., 404, network error), the plugin displays a styled error message instead of breaking the build.
231
+
232
+ ## Contributing
233
+
234
+ Bug reports and pull requests are welcome on GitHub at https://github.com/r0x0d/jekyll-github-code.
235
+
236
+ 1. Fork it
237
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
238
+ 3. Add tests for new functionality
239
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
240
+ 5. Push to the branch (`git push origin my-new-feature`)
241
+ 6. Create a new Pull Request
242
+
243
+ ## License
244
+
245
+ The gem is available as open source under the terms of the [MIT License](./LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = true
11
+ end
12
+
13
+ begin
14
+ require 'rubocop/rake_task'
15
+ RuboCop::RakeTask.new
16
+ rescue LoadError
17
+ # RuboCop not available
18
+ end
19
+
20
+ task default: :test