foresite 1.2.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 +4 -4
- data/README.md +14 -4
- data/lib/foresite/cli.rb +40 -3
- data/lib/foresite/renderer.rb +2 -1
- data/lib/foresite/version.rb +1 -1
- data/lib/foresite.rb +15 -2
- data/lib/skeleton/feed.xml.erb +23 -0
- data/lib/skeleton/wrapper.html.erb +1 -0
- metadata +29 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d09961b909cc4ea9534a3110ad0dd8466c2155ba43485d4b8be8169f8089f0c
|
4
|
+
data.tar.gz: fb0b3d20ce4aa5d43f9c8cd120d4e4297a6af7c7ba218b57572183e7b77366df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
73
|
-
* Current date in YYYY-MM-DD format is the first markdown paragraph
|
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
|
-
*
|
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
|
|
@@ -107,6 +113,10 @@ In this example, the `index.html` will contain:
|
|
107
113
|
</ul>
|
108
114
|
```
|
109
115
|
|
116
|
+
### 5. Watch files and build automatically
|
117
|
+
|
118
|
+
Run `foresite watch` to detect changes to markdown or ERB files, build will run automatically. Useful for previewing content locally.
|
119
|
+
|
110
120
|
## Development
|
111
121
|
|
112
122
|
1. Clone
|
data/lib/foresite/cli.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "date"
|
2
|
+
|
1
3
|
module Foresite
|
2
4
|
##
|
3
5
|
# Cli class.
|
@@ -12,6 +14,11 @@ module Foresite
|
|
12
14
|
true
|
13
15
|
end
|
14
16
|
|
17
|
+
desc "version", "Displays version"
|
18
|
+
def version
|
19
|
+
$stdout.puts(Foresite::VERSION)
|
20
|
+
end
|
21
|
+
|
15
22
|
desc "init", "Initializes foresite in current directory"
|
16
23
|
long_desc <<-LONGDESC
|
17
24
|
Initializes foresite in the current directory.
|
@@ -83,6 +90,7 @@ module Foresite
|
|
83
90
|
# Wipe all output files.
|
84
91
|
Dir.glob(File.join(Foresite.get_path_to_out, "*.html")).each { File.delete(_1) }
|
85
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)
|
86
94
|
|
87
95
|
markdown_paths = Dir.glob(File.join(Foresite.get_path_to_md, "*.md"))
|
88
96
|
|
@@ -101,11 +109,14 @@ module Foresite
|
|
101
109
|
File.write(html_path, Foresite.render_wrapped(title, markdown_content))
|
102
110
|
$stdout.puts("Created #{Foresite.relative_path(html_path)}")
|
103
111
|
|
104
|
-
# Extract date
|
112
|
+
# Extract date.
|
105
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")
|
106
116
|
|
107
117
|
{
|
108
|
-
date_ymd:
|
118
|
+
date_ymd: date_ymd,
|
119
|
+
date_822: date_822,
|
109
120
|
href: Foresite.relative_path(html_path),
|
110
121
|
title: title
|
111
122
|
}
|
@@ -114,8 +125,34 @@ module Foresite
|
|
114
125
|
# Generate index file.
|
115
126
|
index_html_path = Foresite.get_path_to_index_file
|
116
127
|
File.write(index_html_path, Foresite.render_wrapped_index(links))
|
117
|
-
|
118
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)}")
|
133
|
+
end
|
134
|
+
|
135
|
+
desc "watch", "Watches markdown and templates files and runs `build` when they change"
|
136
|
+
long_desc <<-LONGDESC
|
137
|
+
See `build` help for more information
|
138
|
+
LONGDESC
|
139
|
+
|
140
|
+
# @todo How might we test this?
|
141
|
+
def watch
|
142
|
+
dirs_to_watch = [
|
143
|
+
Foresite::DIRNAME_MARKDOWN,
|
144
|
+
Foresite::DIRNAME_ERB
|
145
|
+
]
|
146
|
+
|
147
|
+
$stdout.puts("Watching #{dirs_to_watch.map { "./#{_1}" }.join(", ")} for changes... (Ctrl+C to exit)")
|
148
|
+
|
149
|
+
Filewatcher.new(dirs_to_watch).watch do |changes|
|
150
|
+
changes.each do |filename, event|
|
151
|
+
$stdout.puts("#{File.basename(filename)} #{event}")
|
152
|
+
end
|
153
|
+
|
154
|
+
build
|
155
|
+
end
|
119
156
|
end
|
120
157
|
end
|
121
158
|
end
|
data/lib/foresite/renderer.rb
CHANGED
@@ -12,9 +12,10 @@ 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
|
-
instance_variable_set("@#{k}"
|
18
|
+
instance_variable_set(:"@#{k}", v)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
data/lib/foresite/version.rb
CHANGED
data/lib/foresite.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "erb"
|
4
|
-
require "
|
4
|
+
require "filewatcher"
|
5
5
|
require "kramdown"
|
6
|
+
require "thor"
|
6
7
|
require "zeitwerk"
|
7
8
|
|
8
9
|
loader = Zeitwerk::Loader.for_gem
|
@@ -16,6 +17,7 @@ module Foresite
|
|
16
17
|
FILENAME_POST_MD = "post.md.erb"
|
17
18
|
FILENAME_WRAPPER_HTML = "wrapper.html.erb"
|
18
19
|
FILENAME_LIST_HTML = "_list.html.erb"
|
20
|
+
FILENAME_FEED_XML = "feed.xml.erb"
|
19
21
|
|
20
22
|
ENV_ROOT = "FORESITE_ROOT"
|
21
23
|
|
@@ -67,6 +69,10 @@ module Foresite
|
|
67
69
|
File.join(get_path_to_root, "index.html")
|
68
70
|
end
|
69
71
|
|
72
|
+
def self.get_path_to_feed_file
|
73
|
+
File.join(get_path_to_root, "feed.xml")
|
74
|
+
end
|
75
|
+
|
70
76
|
def self.relative_path(full_path)
|
71
77
|
full_path.gsub(get_path_to_root, "").gsub(Regexp.new("^#{File::SEPARATOR}"), "")
|
72
78
|
end
|
@@ -97,6 +103,13 @@ module Foresite
|
|
97
103
|
})
|
98
104
|
end
|
99
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
|
+
|
100
113
|
def self.touch_directories
|
101
114
|
[get_path_to_md, get_path_to_out, get_path_to_erb].map do |path|
|
102
115
|
if Dir.exist?(path)
|
@@ -109,7 +122,7 @@ module Foresite
|
|
109
122
|
end
|
110
123
|
|
111
124
|
def self.copy_templates
|
112
|
-
[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|
|
113
126
|
full_file_path = File.join(get_path_to_erb, filename)
|
114
127
|
if File.exist?(full_file_path)
|
115
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>
|
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.
|
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:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: kramdown
|
@@ -16,70 +15,84 @@ dependencies:
|
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
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.
|
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.
|
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.
|
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.
|
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.
|
53
|
+
version: '2.7'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: filewatcher
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.1'
|
61
|
+
type: :runtime
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.1'
|
55
68
|
- !ruby/object:Gem::Dependency
|
56
69
|
name: rspec
|
57
70
|
requirement: !ruby/object:Gem::Requirement
|
58
71
|
requirements:
|
59
72
|
- - "~>"
|
60
73
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
74
|
+
version: '3.13'
|
62
75
|
type: :development
|
63
76
|
prerelease: false
|
64
77
|
version_requirements: !ruby/object:Gem::Requirement
|
65
78
|
requirements:
|
66
79
|
- - "~>"
|
67
80
|
- !ruby/object:Gem::Version
|
68
|
-
version: '3.
|
81
|
+
version: '3.13'
|
69
82
|
- !ruby/object:Gem::Dependency
|
70
83
|
name: standard
|
71
84
|
requirement: !ruby/object:Gem::Requirement
|
72
85
|
requirements:
|
73
86
|
- - "~>"
|
74
87
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1.
|
88
|
+
version: '1.50'
|
76
89
|
type: :development
|
77
90
|
prerelease: false
|
78
91
|
version_requirements: !ruby/object:Gem::Requirement
|
79
92
|
requirements:
|
80
93
|
- - "~>"
|
81
94
|
- !ruby/object:Gem::Version
|
82
|
-
version: '1.
|
95
|
+
version: '1.50'
|
83
96
|
- !ruby/object:Gem::Dependency
|
84
97
|
name: rake
|
85
98
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,7 +107,6 @@ dependencies:
|
|
94
107
|
- - "~>"
|
95
108
|
- !ruby/object:Gem::Version
|
96
109
|
version: '13'
|
97
|
-
description:
|
98
110
|
email:
|
99
111
|
- carl.wiedemann@gmail.com
|
100
112
|
executables:
|
@@ -111,6 +123,7 @@ files:
|
|
111
123
|
- lib/foresite/renderer.rb
|
112
124
|
- lib/foresite/version.rb
|
113
125
|
- lib/skeleton/_list.html.erb
|
126
|
+
- lib/skeleton/feed.xml.erb
|
114
127
|
- lib/skeleton/post.md.erb
|
115
128
|
- lib/skeleton/wrapper.html.erb
|
116
129
|
homepage: https://github.com/carlwiedemann/foresite
|
@@ -120,7 +133,6 @@ metadata:
|
|
120
133
|
homepage_uri: https://github.com/carlwiedemann/foresite
|
121
134
|
source_code_uri: https://github.com/carlwiedemann/foresite
|
122
135
|
changelog_uri: https://github.com/carlwiedemann/foresite/blob/main/CHANGELOG.md
|
123
|
-
post_install_message:
|
124
136
|
rdoc_options: []
|
125
137
|
require_paths:
|
126
138
|
- lib
|
@@ -128,15 +140,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
140
|
requirements:
|
129
141
|
- - ">="
|
130
142
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
143
|
+
version: 3.3.0
|
132
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
145
|
requirements:
|
134
146
|
- - ">="
|
135
147
|
- !ruby/object:Gem::Version
|
136
148
|
version: '0'
|
137
149
|
requirements: []
|
138
|
-
rubygems_version: 3.
|
139
|
-
signing_key:
|
150
|
+
rubygems_version: 3.6.7
|
140
151
|
specification_version: 4
|
141
152
|
summary: An extremely minimal static site generator.
|
142
153
|
test_files: []
|