foresite 1.3.0 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31f026a8d80bce2b57fbe4b909cb3c6490ca50debf834de0636c7b713749fe83
4
- data.tar.gz: 0b450e5e2639cb57ece5ae26810c8b467a6d91bc269ffcb1f96bb4e2f18fd716
3
+ metadata.gz: 3d09961b909cc4ea9534a3110ad0dd8466c2155ba43485d4b8be8169f8089f0c
4
+ data.tar.gz: fb0b3d20ce4aa5d43f9c8cd120d4e4297a6af7c7ba218b57572183e7b77366df
5
5
  SHA512:
6
- metadata.gz: 5ab2348a5bb8eb90c0707a4ace0921e586a15d7d2838d72f4841fe39165a3912c129593ca4b5075dde9b62ad94a114cf4170865fb89781d2c3ec8f40d24b4c16
7
- data.tar.gz: 543c72aad677e681b17b12eae7c43a927fbe1417b98c1cf0838fc9f9b343e55ae3730308ce679cf522cf698bedc8c3cddbb56a67f713355af1768b55d54566f0
6
+ metadata.gz: 0a15d6e41db517b1c78e5bd114fbc0b82ecb36b96455e52e3a327d6e6a4239f9a3ca8bfc29fc804bec753a09405609e528dfa3ab0ca4215664163a9a6465147a
7
+ data.tar.gz: a8d7974d9b99e3818d4c7597ebe80e2fe1241ae8e13c27cea06c420adba44fa06646a44a6da823ef854c43b3ac492c2e8eadf32c8f8a9835440f23d3db9a3e2d
data/README.md CHANGED
@@ -41,6 +41,7 @@ Create a project directory for your site and run `foresite init` from within it:
41
41
  Created erb/post.md.erb
42
42
  Created erb/wrapper.html.erb
43
43
  Created erb/_list.html.erb
44
+ Created erb/feed.xml.erb
44
45
 
45
46
  Three subdirectories are created, along with three [ERB](https://docs.ruby-lang.org/en/3.2/ERB.html) template files.
46
47
 
@@ -52,6 +53,7 @@ Some facts:
52
53
  * `post.md.erb` is the default markdown file for every post.
53
54
  * `wrapper.html.erb` is a HTML wrapper template for every generated HTML file.
54
55
  * `_list.html.erb` is a HTML template partial for the list of posts on the `index.html` page.
56
+ * `feed.xml.erb` is a XML template for an RSS feed.
55
57
 
56
58
  ### 2. Write your first post
57
59
 
@@ -69,8 +71,8 @@ A single markdown file is created in the `md` subdirectory. **This file is meant
69
71
 
70
72
  Some facts:
71
73
 
72
- * The title is the first line formatted as H1 (mandatory).
73
- * Current date in YYYY-MM-DD format is the first markdown paragraph (optional).
74
+ * The title is the first line formatted as H1.
75
+ * Current date in YYYY-MM-DD format is the first markdown paragraph.
74
76
  * Current date and title are "slugified" for filename.
75
77
 
76
78
  ### 3. Modify templates as desired
@@ -81,6 +83,8 @@ Some facts:
81
83
 
82
84
  `_list.html.erb` is used to generate the `<ul>` list of posts on the `index.html` file. Modify to show posts in a different way.
83
85
 
86
+ `feed.xml.erb` is an RSS feed, it will require a `title` as well as a `base_url` for where you host your site.
87
+
84
88
  ### 4. Generate HTML from markdown
85
89
 
86
90
  Run `foresite build` to create HTML in the `post` subdirectory and the `index.html` file:
@@ -88,8 +92,9 @@ Run `foresite build` to create HTML in the `post` subdirectory and the `index.ht
88
92
  $ foresite build
89
93
  Created post/2023-01-15-welcome-to-my-site.html
90
94
  Created index.html
95
+ Created feed.xml
91
96
 
92
- In this example, two HTML files are created.
97
+ In this example, two HTML files and an XML file are created.
93
98
 
94
99
  Some facts:
95
100
 
@@ -97,7 +102,8 @@ Some facts:
97
102
  * A single `index.html` file shows a list of links to all posts in reverse-chronological order, prefixed with post date.
98
103
  * Post titles are parsed from the first H1 tag in each post markdown file.
99
104
  * Post dates are parsed from the post markdown filename.
100
- * Re-running `foresite build` removes and recreates all HTML files in the `post` subdirectory as well as the `index.html` file.
105
+ * The `feed.xml` file reflects the list posts in RSS 2.0 format.
106
+ * Re-running `foresite build` removes and recreates all HTML files in the `post` subdirectory as well as the `index.html` file and `feed.xml` file.
101
107
 
102
108
  In this example, the `index.html` will contain:
103
109
 
data/lib/foresite/cli.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "date"
2
+
1
3
  module Foresite
2
4
  ##
3
5
  # Cli class.
@@ -88,6 +90,7 @@ module Foresite
88
90
  # Wipe all output files.
89
91
  Dir.glob(File.join(Foresite.get_path_to_out, "*.html")).each { File.delete(_1) }
90
92
  File.delete(Foresite.get_path_to_index_file) if File.exist?(Foresite.get_path_to_index_file)
93
+ File.delete(Foresite.get_path_to_feed_file) if File.exist?(Foresite.get_path_to_feed_file)
91
94
 
92
95
  markdown_paths = Dir.glob(File.join(Foresite.get_path_to_md, "*.md"))
93
96
 
@@ -106,11 +109,14 @@ module Foresite
106
109
  File.write(html_path, Foresite.render_wrapped(title, markdown_content))
107
110
  $stdout.puts("Created #{Foresite.relative_path(html_path)}")
108
111
 
109
- # Extract date if it exists.
112
+ # Extract date.
110
113
  match_data = /\d{4}-\d{2}-\d{2}/.match(filename_markdown)
114
+ date_ymd = match_data[0]
115
+ date_822 = DateTime.strptime(date_ymd, "%F").strftime("%a, %d %b %Y %H:%M:%S %z")
111
116
 
112
117
  {
113
- date_ymd: match_data.nil? ? "" : match_data[0],
118
+ date_ymd: date_ymd,
119
+ date_822: date_822,
114
120
  href: Foresite.relative_path(html_path),
115
121
  title: title
116
122
  }
@@ -119,8 +125,11 @@ module Foresite
119
125
  # Generate index file.
120
126
  index_html_path = Foresite.get_path_to_index_file
121
127
  File.write(index_html_path, Foresite.render_wrapped_index(links))
122
-
123
128
  $stdout.puts("Created #{Foresite.relative_path(index_html_path)}")
129
+
130
+ feed_xml_path = Foresite.get_path_to_feed_file
131
+ File.write(feed_xml_path, Foresite.render_feed(links, links.last[:date_822]))
132
+ $stdout.puts("Created #{Foresite.relative_path(feed_xml_path)}")
124
133
  end
125
134
 
126
135
  desc "watch", "Watches markdown and templates files and runs `build` when they change"
@@ -12,6 +12,7 @@ module Foresite
12
12
  # @param [Hash] vars Variables for template.
13
13
  def initialize(path, vars)
14
14
  @path = path
15
+ @vars_original = @vars
15
16
  vars.each do |k, v|
16
17
  if k.is_a?(Symbol)
17
18
  instance_variable_set(:"@#{k}", v)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Foresite
4
- VERSION = "1.3.0"
4
+ VERSION = "1.4.0"
5
5
  end
data/lib/foresite.rb CHANGED
@@ -17,6 +17,7 @@ module Foresite
17
17
  FILENAME_POST_MD = "post.md.erb"
18
18
  FILENAME_WRAPPER_HTML = "wrapper.html.erb"
19
19
  FILENAME_LIST_HTML = "_list.html.erb"
20
+ FILENAME_FEED_XML = "feed.xml.erb"
20
21
 
21
22
  ENV_ROOT = "FORESITE_ROOT"
22
23
 
@@ -68,6 +69,10 @@ module Foresite
68
69
  File.join(get_path_to_root, "index.html")
69
70
  end
70
71
 
72
+ def self.get_path_to_feed_file
73
+ File.join(get_path_to_root, "feed.xml")
74
+ end
75
+
71
76
  def self.relative_path(full_path)
72
77
  full_path.gsub(get_path_to_root, "").gsub(Regexp.new("^#{File::SEPARATOR}"), "")
73
78
  end
@@ -98,6 +103,13 @@ module Foresite
98
103
  })
99
104
  end
100
105
 
106
+ def self.render_feed(items, date_build_822)
107
+ render_erb_file(FILENAME_FEED_XML, {
108
+ items: items.reverse,
109
+ date_build_822: date_build_822
110
+ })
111
+ end
112
+
101
113
  def self.touch_directories
102
114
  [get_path_to_md, get_path_to_out, get_path_to_erb].map do |path|
103
115
  if Dir.exist?(path)
@@ -110,7 +122,7 @@ module Foresite
110
122
  end
111
123
 
112
124
  def self.copy_templates
113
- [FILENAME_POST_MD, FILENAME_WRAPPER_HTML, FILENAME_LIST_HTML].map do |filename|
125
+ [FILENAME_POST_MD, FILENAME_WRAPPER_HTML, FILENAME_LIST_HTML, FILENAME_FEED_XML].map do |filename|
114
126
  full_file_path = File.join(get_path_to_erb, filename)
115
127
  if File.exist?(full_file_path)
116
128
  "#{relative_path(full_file_path)} already exists"
@@ -0,0 +1,23 @@
1
+ <%
2
+ title = 'Another Foresite Blog'
3
+ base_url = 'https://example.com'
4
+ -%>
5
+ <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
6
+ <channel>
7
+ <title><%= title %></title>
8
+ <link><%= base_url %>/feed.xml</link>
9
+ <language>en-us</language>
10
+ <pubDate><%= @date_build_822 %></pubDate>
11
+ <lastBuildDate><%= @date_build_822 %></lastBuildDate>
12
+ <generator>Foresite</generator>
13
+ <atom:link href="<%= base_url %>/feed.xml" rel="self" type="application/rss+xml"/>
14
+ <% @items.each do |item| -%>
15
+ <item>
16
+ <title><%= item[:title] %></title>
17
+ <link><%= "#{base_url}/#{item[:href]}" %></link>
18
+ <guid><%= "#{base_url}/#{item[:href]}" %></guid>
19
+ <pubDate><%= item[:date_822] %></pubDate>
20
+ </item>
21
+ <%- end %>
22
+ </channel>
23
+ </rss>
@@ -6,6 +6,7 @@
6
6
  <head>
7
7
  <meta charset="utf-8">
8
8
  <title><%= @title ? "#{@title} - #{index_title}" : index_title %></title>
9
+ <link rel="alternate" type="application/rss+xml" title="<%= index_title %>" href="/feed.xml">
9
10
  <style></style>
10
11
  </head>
11
12
  <body>
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foresite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Wiedemann
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-01-05 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: kramdown
@@ -16,42 +15,42 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '2.4'
18
+ version: '2.5'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '2.4'
25
+ version: '2.5'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: thor
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '1.2'
32
+ version: '1.4'
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '1.2'
39
+ version: '1.4'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: zeitwerk
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: '2.6'
46
+ version: '2.7'
48
47
  type: :runtime
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: '2.6'
53
+ version: '2.7'
55
54
  - !ruby/object:Gem::Dependency
56
55
  name: filewatcher
57
56
  requirement: !ruby/object:Gem::Requirement
@@ -72,28 +71,28 @@ dependencies:
72
71
  requirements:
73
72
  - - "~>"
74
73
  - !ruby/object:Gem::Version
75
- version: '3.2'
74
+ version: '3.13'
76
75
  type: :development
77
76
  prerelease: false
78
77
  version_requirements: !ruby/object:Gem::Requirement
79
78
  requirements:
80
79
  - - "~>"
81
80
  - !ruby/object:Gem::Version
82
- version: '3.2'
81
+ version: '3.13'
83
82
  - !ruby/object:Gem::Dependency
84
83
  name: standard
85
84
  requirement: !ruby/object:Gem::Requirement
86
85
  requirements:
87
86
  - - "~>"
88
87
  - !ruby/object:Gem::Version
89
- version: '1.3'
88
+ version: '1.50'
90
89
  type: :development
91
90
  prerelease: false
92
91
  version_requirements: !ruby/object:Gem::Requirement
93
92
  requirements:
94
93
  - - "~>"
95
94
  - !ruby/object:Gem::Version
96
- version: '1.3'
95
+ version: '1.50'
97
96
  - !ruby/object:Gem::Dependency
98
97
  name: rake
99
98
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +107,6 @@ dependencies:
108
107
  - - "~>"
109
108
  - !ruby/object:Gem::Version
110
109
  version: '13'
111
- description:
112
110
  email:
113
111
  - carl.wiedemann@gmail.com
114
112
  executables:
@@ -125,6 +123,7 @@ files:
125
123
  - lib/foresite/renderer.rb
126
124
  - lib/foresite/version.rb
127
125
  - lib/skeleton/_list.html.erb
126
+ - lib/skeleton/feed.xml.erb
128
127
  - lib/skeleton/post.md.erb
129
128
  - lib/skeleton/wrapper.html.erb
130
129
  homepage: https://github.com/carlwiedemann/foresite
@@ -134,7 +133,6 @@ metadata:
134
133
  homepage_uri: https://github.com/carlwiedemann/foresite
135
134
  source_code_uri: https://github.com/carlwiedemann/foresite
136
135
  changelog_uri: https://github.com/carlwiedemann/foresite/blob/main/CHANGELOG.md
137
- post_install_message:
138
136
  rdoc_options: []
139
137
  require_paths:
140
138
  - lib
@@ -142,15 +140,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
140
  requirements:
143
141
  - - ">="
144
142
  - !ruby/object:Gem::Version
145
- version: 2.7.0
143
+ version: 3.3.0
146
144
  required_rubygems_version: !ruby/object:Gem::Requirement
147
145
  requirements:
148
146
  - - ">="
149
147
  - !ruby/object:Gem::Version
150
148
  version: '0'
151
149
  requirements: []
152
- rubygems_version: 3.4.3
153
- signing_key:
150
+ rubygems_version: 3.6.7
154
151
  specification_version: 4
155
152
  summary: An extremely minimal static site generator.
156
153
  test_files: []