static-site-builder 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfa2d9ecc9c90e973fd3cecd6c04e2aad09a80fa29ba0bd78a95b524206986c4
4
- data.tar.gz: 2394ef787382dec487390d4b05a1add37a27e3e9154f032f82d9972fae25924e
3
+ metadata.gz: 4ec7765f3cc618a791a6d655fed75fe39f43a09d9c697cc71135d17160dbd27f
4
+ data.tar.gz: 74ace48bd713ba712607509baf63a80095cd610395be622b59c3e552336f10df
5
5
  SHA512:
6
- metadata.gz: 89d7320b08a5e90d12f7c155a8f2e2b0a7f907b9ff18c53c81632dcc5f49cd90e34d41b1533baf760bd4866a07aa06ad95a6f84ac4d34600ed8a86296a24b25e
7
- data.tar.gz: 7db49008d74e0aa849e084edb8a8ccc515c1764c3d97e3fb820e952697d3187dd3723e4f4edb4dc284b1dff5ccf5549de7de282413c4616d619d7a8addb693da
6
+ metadata.gz: 358643b7c2cb4bd56693c18fa4f57114da85b519a1423e319a55d1b4d7ee0d3190768985225539e6c65f9eed044d96fced689d5464d39fb0db85238dbcb4e6d4
7
+ data.tar.gz: a8ab43edfdac947a34e0222c181037213120eb1f9dea91c924f218e974908c51491135ce475aadde6552bedd65698cf05a54e18af60b73669b6c6fe7134cb84a
data/CHANGELOG.md CHANGED
@@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.1.4] - 2025-11-22
9
+
10
+ ### Added
11
+ - Generator now automatically creates `lib/page_helpers.rb` with `PageHelpers::PAGES` structure for page metadata
12
+ - Generator now automatically creates `config/sitemap.rb` for sitemap generation
13
+ - `sitemap_generator` gem is now automatically included in generated Gemfiles
14
+ - `build:sitemap` task is automatically added to generated Rakefiles
15
+ - Sitemap generation is integrated into `build:all` task
16
+
17
+ ### Changed
18
+ - Page metadata is now managed via `PageHelpers::PAGES` hash instead of frontmatter
19
+ - README updated to reflect `PageHelpers::PAGES` approach (frontmatter example removed)
20
+ - ActionView requirement changed from `>= 8.0` to `~> 7.1` for Ruby 3.1 compatibility
21
+ - Generated layouts now use `@title` and `@js_modules` instance variables instead of frontmatter
22
+
23
+ ### Fixed
24
+ - Fixed `js_modules` variable reference in generated layouts (now uses `@js_modules`)
25
+ - Fixed PageHelpers metadata loading to occur before page content rendering, allowing partials to access `@title`, `@description`, etc.
26
+ - Removed all frontmatter parsing code and references
27
+ - Updated all specs to use `PageHelpers::PAGES` instead of frontmatter
28
+
8
29
  ## [0.1.3] - 2025-11-22
9
30
 
10
31
  ### Added
@@ -17,7 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
17
38
  ### Changed
18
39
  - Replaced raw ERB implementation with ActionView::Base for template rendering
19
40
  - Render method now uses ActionView's rendering system, matching Rails behaviour exactly
20
- - Partials automatically receive page variables (frontmatter, js_modules, importmap_json, current_page)
41
+ - Partials automatically receive page variables (@js_modules, importmap_json, current_page)
21
42
  - Improved error messages for missing partials (converted from ActionView format for backwards compatibility)
22
43
  - Template annotations now preserve both page and layout annotations correctly
23
44
 
@@ -39,7 +60,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
39
60
  - `render` helper method for ERB templates to include partials
40
61
  - Support for rendering partials from `app/views/shared/` directory
41
62
  - Partial files should be named with `_` prefix (e.g., `_header.html.erb`)
42
- - Partials have access to page variables (frontmatter, js_modules, etc.)
63
+ - Partials have access to page variables (@js_modules, etc.)
43
64
 
44
65
  ### Changed
45
66
  - Improved ERB compilation to support partial rendering
@@ -54,7 +75,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
54
75
  - Support for multiple JavaScript bundlers (Importmap, ESBuild, Webpack, Vite, None)
55
76
  - Support for multiple CSS frameworks (TailwindCSS, shadcn/ui, Plain CSS)
56
77
  - Support for multiple JavaScript frameworks (Stimulus, React, Vue, Alpine.js, Vanilla)
57
- - Frontmatter parsing for ERB pages
78
+ - Page metadata via `PageHelpers::PAGES` hash
58
79
  - Layout support with nested layouts
59
80
  - Importmap JSON generation
60
81
  - Asset copying (JavaScript, CSS, vendor files, static files)
data/README.md CHANGED
@@ -48,11 +48,12 @@ A clean project structure that depends on gems:
48
48
 
49
49
  ```
50
50
  my-site/
51
- ├── Gemfile # Dependencies (static-site-builder, importmap-rails, etc.)
51
+ ├── Gemfile # Dependencies (static-site-builder, sitemap_generator, etc.)
52
52
  ├── package.json # JS dependencies (if needed)
53
- ├── Rakefile # Build tasks
53
+ ├── Rakefile # Build tasks (includes sitemap generation)
54
54
  ├── config/
55
- └── importmap.rb # Importmap config (if using importmap)
55
+ ├── importmap.rb # Importmap config (if using importmap)
56
+ │ └── sitemap.rb # Sitemap generation config
56
57
  ├── app/
57
58
  │ ├── views/
58
59
  │ │ ├── layouts/
@@ -61,7 +62,8 @@ my-site/
61
62
  │ ├── javascript/
62
63
  │ └── assets/
63
64
  └── lib/
64
- └── site_builder.rb # Compiles your site
65
+ ├── site_builder.rb # Compiles your site
66
+ └── page_helpers.rb # Page metadata (title, description, etc.)
65
67
  ```
66
68
 
67
69
  ## How It Works
@@ -109,18 +111,32 @@ my-site/
109
111
 
110
112
  ### Using ERB Templates
111
113
 
112
- Create pages in `app/views/pages/` with frontmatter:
114
+ Create pages in `app/views/pages/`:
113
115
 
114
116
  ```erb
115
- ---
116
- title: My Page
117
- description: A great page
118
- ---
119
-
120
117
  <h1><%= @title %></h1>
121
118
  <p><%= @description %></p>
122
119
  ```
123
120
 
121
+ Page metadata is automatically configured in `lib/page_helpers.rb` (generated automatically):
122
+
123
+ ```ruby
124
+ module PageHelpers
125
+ PAGES = {
126
+ '/' => {
127
+ title: 'My Page',
128
+ description: 'A great page',
129
+ url: 'https://example.com',
130
+ image: 'https://example.com/image.jpg',
131
+ priority: 1.0,
132
+ changefreq: 'weekly'
133
+ }
134
+ }.freeze
135
+ end
136
+ ```
137
+
138
+ The builder automatically loads metadata from `PageHelpers::PAGES` and sets `@title`, `@description`, `@url`, and `@image` instance variables for use in your templates. This metadata is also used by the `sitemap_generator` gem for generating sitemaps.
139
+
124
140
  Use layouts in `app/views/layouts/application.html.erb`:
125
141
 
126
142
  ```erb
@@ -214,6 +230,18 @@ Install components and use them in your templates:
214
230
  npx shadcn-ui@latest add button
215
231
  ```
216
232
 
233
+ ### Generating Sitemaps
234
+
235
+ Sitemap generation is automatically configured when you generate a new site. The `sitemap_generator` gem is included in the Gemfile, and `config/sitemap.rb` is automatically created.
236
+
237
+ The sitemap is generated from your `PageHelpers::PAGES` metadata during `rake build:all`. Update `config/sitemap.rb` to set your domain:
238
+
239
+ ```ruby
240
+ SitemapGenerator::Sitemap.default_host = 'https://yourdomain.com'
241
+ ```
242
+
243
+ The sitemap will be generated in `dist/sitemaps/sitemap.xml.gz` during the build process.
244
+
217
245
  ## Examples
218
246
 
219
247
  ### ERB + Importmap + Stimulus + TailwindCSS
data/lib/generator.rb CHANGED
@@ -68,6 +68,8 @@ module StaticSiteBuilder
68
68
  create_config_files
69
69
  create_app_structure
70
70
  create_build_files
71
+ create_page_helpers
72
+ create_sitemap_config
71
73
  create_example_pages
72
74
  create_readme
73
75
  create_gitignore
@@ -104,7 +106,8 @@ module StaticSiteBuilder
104
106
  gems = [
105
107
  "rake",
106
108
  "static-site-builder",
107
- "webrick" # Required for dev server (removed from stdlib in Ruby 3.0+)
109
+ "webrick", # Required for dev server (removed from stdlib in Ruby 3.0+)
110
+ "sitemap_generator" # For generating sitemaps from PageHelpers::PAGES
108
111
  ]
109
112
  gems << "importmap-rails" if @options[:js_bundler] == "importmap"
110
113
  gems << "phlex-rails" if @options[:template_engine] == "phlex"
@@ -186,6 +189,78 @@ module StaticSiteBuilder
186
189
  create_rails_config if @options[:edit_rails]
187
190
  end
188
191
 
192
+ def create_page_helpers
193
+ content = <<~RUBY
194
+ # frozen_string_literal: true
195
+
196
+ module PageHelpers
197
+ # Page metadata configuration
198
+ # The builder automatically loads this and sets @title, @description, @url, and @image
199
+ # instance variables for use in your templates.
200
+ # This metadata is also used by sitemap_generator for generating sitemaps.
201
+ PAGES = {
202
+ '/' => {
203
+ title: 'Home',
204
+ description: 'Welcome to my site',
205
+ url: 'https://example.com',
206
+ image: 'https://example.com/image.jpg',
207
+ priority: 1.0,
208
+ changefreq: 'weekly'
209
+ }
210
+ }.freeze
211
+
212
+ def page_title(path = nil)
213
+ path ||= @current_page
214
+ PAGES[path]&.fetch(:title) || 'Site'
215
+ end
216
+
217
+ def page_description(path = nil)
218
+ path ||= @current_page
219
+ PAGES[path]&.fetch(:description) || 'A static site'
220
+ end
221
+
222
+ def page_url(path = nil)
223
+ path ||= @current_page
224
+ PAGES[path]&.fetch(:url) || 'https://example.com'
225
+ end
226
+
227
+ def page_image(path = nil)
228
+ path ||= @current_page
229
+ PAGES[path]&.fetch(:image) || 'https://example.com/image.jpg'
230
+ end
231
+ end
232
+ RUBY
233
+
234
+ write_file("lib/page_helpers.rb", content)
235
+ end
236
+
237
+ def create_sitemap_config
238
+ content = <<~RUBY
239
+ # frozen_string_literal: true
240
+
241
+ require 'sitemap_generator'
242
+ require_relative '../lib/page_helpers'
243
+
244
+ # Configure sitemap generator
245
+ # Update default_host to your actual domain
246
+ SitemapGenerator::Sitemap.default_host = 'https://example.com'
247
+ SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps'
248
+ SitemapGenerator::Sitemap.public_path = 'dist'
249
+
250
+ # Generate sitemap from PageHelpers::PAGES
251
+ SitemapGenerator::Sitemap.create do
252
+ PageHelpers::PAGES.each do |path, metadata|
253
+ add path,
254
+ lastmod: Time.now,
255
+ priority: metadata[:priority] || 0.5,
256
+ changefreq: metadata[:changefreq] || 'weekly'
257
+ end
258
+ end
259
+ RUBY
260
+
261
+ write_file("config/sitemap.rb", content)
262
+ end
263
+
189
264
  def create_importmap_config
190
265
  content = <<~RUBY
191
266
  # frozen_string_literal: true
@@ -410,7 +485,7 @@ module StaticSiteBuilder
410
485
  <head>
411
486
  <meta charset="UTF-8">
412
487
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
413
- <title><%= frontmatter['title'] || 'Site' %></title>
488
+ <title><%= @title || 'Site' %></title>
414
489
  <link rel="stylesheet" href="/assets/stylesheets/application.css">
415
490
  </head>
416
491
  <body>
@@ -470,8 +545,8 @@ module StaticSiteBuilder
470
545
  case @options[:js_bundler]
471
546
  when "importmap"
472
547
  <<~ERB
473
- <% if js_modules && !js_modules.empty? %>
474
- <% js_modules.each do |module_name| %>
548
+ <% if @js_modules.present? %>
549
+ <% @js_modules.each do |module_name| %>
475
550
  <script type="module">import "<%= module_name %>";</script>
476
551
  <% end %>
477
552
  <% else %>
@@ -728,8 +803,8 @@ module StaticSiteBuilder
728
803
  require "pathname"
729
804
 
730
805
  namespace :build do
731
- desc "Build everything (HTML + CSS)"
732
- task :all => [:html, :css] do
806
+ desc "Build everything (HTML + CSS + Sitemap)"
807
+ task :all => [:html, :css, :sitemap] do
733
808
  puts "\\n✓ Build complete!"
734
809
  end
735
810
 
@@ -778,6 +853,11 @@ module StaticSiteBuilder
778
853
  ENV["PRODUCTION"] = "true"
779
854
  Rake::Task["build:all"].invoke
780
855
  end
856
+
857
+ desc "Generate sitemap from PageHelpers::PAGES"
858
+ task :sitemap do
859
+ require './config/sitemap'
860
+ end
781
861
  end
782
862
 
783
863
  namespace :dev do
@@ -798,8 +878,8 @@ module StaticSiteBuilder
798
878
  require "pathname"
799
879
 
800
880
  namespace :build do
801
- desc "Build everything (HTML)"
802
- task :all => [:html] do
881
+ desc "Build everything (HTML + Sitemap)"
882
+ task :all => [:html, :sitemap] do
803
883
  puts "\\n✓ Build complete!"
804
884
  end
805
885
 
@@ -820,6 +900,11 @@ module StaticSiteBuilder
820
900
  ENV["PRODUCTION"] = "true"
821
901
  Rake::Task["build:all"].invoke
822
902
  end
903
+
904
+ desc "Generate sitemap from PageHelpers::PAGES"
905
+ task :sitemap do
906
+ require './config/sitemap'
907
+ end
823
908
  end
824
909
 
825
910
  namespace :dev do
@@ -337,6 +337,24 @@ module StaticSiteBuilder
337
337
  view.instance_variable_set(:@current_page, current_page_path)
338
338
  view.instance_variable_set(:@page_content, nil)
339
339
 
340
+ # Set title and metadata from PageHelpers BEFORE rendering page content
341
+ # This ensures partials rendered within the page have access to metadata
342
+ page_helpers_path = @root.join('lib', 'page_helpers.rb')
343
+ begin
344
+ if page_helpers_path.exist?
345
+ require page_helpers_path.to_s
346
+ pages = ::PageHelpers::PAGES rescue nil
347
+ if pages && pages.is_a?(Hash) && pages.key?(current_page_path)
348
+ metadata = pages[current_page_path]
349
+ view.instance_variable_set(:@title, metadata[:title])
350
+ view.instance_variable_set(:@description, metadata[:description])
351
+ view.instance_variable_set(:@url, metadata[:url])
352
+ view.instance_variable_set(:@image, metadata[:image])
353
+ end
354
+ end
355
+ rescue => e
356
+ # Silently continue if PageHelpers can't be loaded
357
+ end
340
358
 
341
359
  # Override render to handle 'footer' -> 'shared/footer' conversion
342
360
  # and ensure locals are passed to partials
@@ -413,31 +431,6 @@ module StaticSiteBuilder
413
431
  page_content = annotate_template(page_content, relative_template_path.to_s)
414
432
  end
415
433
 
416
- # Set title and metadata from PageHelpers before rendering layout
417
- puts " DEBUG: About to set metadata for #{current_page_path}"
418
- page_helpers_path = @root.join('lib', 'page_helpers.rb')
419
- puts " DEBUG: Checking PageHelpers at: #{page_helpers_path} (exists: #{page_helpers_path.exist?})"
420
- begin
421
- if page_helpers_path.exist?
422
- require page_helpers_path.to_s
423
- pages = ::PageHelpers::PAGES rescue nil
424
- puts " Pages loaded: #{pages ? 'yes' : 'no'}, keys: #{pages&.keys&.inspect}"
425
- if pages && pages.is_a?(Hash) && pages.key?(current_page_path)
426
- metadata = pages[current_page_path]
427
- view.instance_variable_set(:@title, metadata[:title])
428
- view.instance_variable_set(:@description, metadata[:description])
429
- view.instance_variable_set(:@url, metadata[:url])
430
- view.instance_variable_set(:@image, metadata[:image])
431
- puts " ✓ Set metadata for #{current_page_path}: #{metadata[:title]}"
432
- else
433
- puts " ⚠ No metadata found for #{current_page_path}"
434
- end
435
- end
436
- rescue => e
437
- puts " ⚠ Error loading PageHelpers: #{e.class} - #{e.message}"
438
- puts e.backtrace.first(3)
439
- end
440
-
441
434
  # Render layout using ActionView
442
435
  # Instance variables set in the page template are available in the layout
443
436
  layout_template = ActionView::Template.new(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StaticSiteBuilder
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: static-site-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukasz Czapiewski
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '8.0'
18
+ version: '7.1'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '8.0'
25
+ version: '7.1'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: base64
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -128,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: '3.0'
131
+ version: '3.1'
132
132
  required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - ">="