foresite 1.1.3 → 1.3.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 +8 -2
- data/lib/foresite/cli.rb +31 -2
- data/lib/foresite/renderer.rb +1 -1
- data/lib/foresite/version.rb +1 -1
- data/lib/foresite.rb +4 -2
- data/lib/skeleton/wrapper.html.erb +4 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31f026a8d80bce2b57fbe4b909cb3c6490ca50debf834de0636c7b713749fe83
|
4
|
+
data.tar.gz: 0b450e5e2639cb57ece5ae26810c8b467a6d91bc269ffcb1f96bb4e2f18fd716
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ab2348a5bb8eb90c0707a4ace0921e586a15d7d2838d72f4841fe39165a3912c129593ca4b5075dde9b62ad94a114cf4170865fb89781d2c3ec8f40d24b4c16
|
7
|
+
data.tar.gz: 543c72aad677e681b17b12eae7c43a927fbe1417b98c1cf0838fc9f9b343e55ae3730308ce679cf522cf698bedc8c3cddbb56a67f713355af1768b55d54566f0
|
data/README.md
CHANGED
@@ -77,7 +77,7 @@ Some facts:
|
|
77
77
|
|
78
78
|
`post.md.erb` is used to when running `foresite touch` for the default markdown content. It has two variables, `@title` for the post title and `@date_ymd` for the created date in ISO 8601 `YYYY-MM-DD` format. Modify to have different defaults when running `foresite touch`.
|
79
79
|
|
80
|
-
`wrapper.html.erb` wraps all of your markdown.
|
80
|
+
`wrapper.html.erb` wraps all of your markdown. It has two variables, `@title` for the post title that will populate the `<title>` tag, and `@content` for a given post's HTML (converted from markdown). For the `index.html` file, `@title` will be `nil`, and `@content` will be an list of links to all posts in reverse-chronological order. Modify to have different overall page structure, or to add `<style>` etc.
|
81
81
|
|
82
82
|
`_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
83
|
|
@@ -103,10 +103,14 @@ In this example, the `index.html` will contain:
|
|
103
103
|
|
104
104
|
```html
|
105
105
|
<ul>
|
106
|
-
<li>2023-01-15 <a href="2023-01-15-welcome-to-my-site.html">Welcome to my site</a></li>
|
106
|
+
<li>2023-01-15 <a href="post/2023-01-15-welcome-to-my-site.html">Welcome to my site</a></li>
|
107
107
|
</ul>
|
108
108
|
```
|
109
109
|
|
110
|
+
### 5. Watch files and build automatically
|
111
|
+
|
112
|
+
Run `foresite watch` to detect changes to markdown or ERB files, build will run automatically. Useful for previewing content locally.
|
113
|
+
|
110
114
|
## Development
|
111
115
|
|
112
116
|
1. Clone
|
@@ -123,6 +127,8 @@ Bug reports and pull requests are welcome. The goals of Foresite are:
|
|
123
127
|
* Simple to use & understand
|
124
128
|
* Minimal features
|
125
129
|
|
130
|
+
Read more in the [blog post introducing Foresite](https://carlwiedemann.github.io/post/2023-01-17-introducing-foresite.html)
|
131
|
+
|
126
132
|
## License
|
127
133
|
|
128
134
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/foresite/cli.rb
CHANGED
@@ -12,6 +12,11 @@ module Foresite
|
|
12
12
|
true
|
13
13
|
end
|
14
14
|
|
15
|
+
desc "version", "Displays version"
|
16
|
+
def version
|
17
|
+
$stdout.puts(Foresite::VERSION)
|
18
|
+
end
|
19
|
+
|
15
20
|
desc "init", "Initializes foresite in current directory"
|
16
21
|
long_desc <<-LONGDESC
|
17
22
|
Initializes foresite in the current directory.
|
@@ -93,11 +98,12 @@ module Foresite
|
|
93
98
|
|
94
99
|
links = markdown_paths.map do |markdown_path|
|
95
100
|
markdown_content = File.read(markdown_path)
|
101
|
+
title = markdown_content.split("\n").first { |line| /^# [a-z]/i =~ line }.gsub(/^#/, "").strip
|
96
102
|
|
97
103
|
filename_markdown = File.basename(markdown_path)
|
98
104
|
html_path = Foresite.get_path_to_out_file(filename_markdown.gsub(/\.md$/, ".html"))
|
99
105
|
|
100
|
-
File.write(html_path, Foresite.render_wrapped(markdown_content))
|
106
|
+
File.write(html_path, Foresite.render_wrapped(title, markdown_content))
|
101
107
|
$stdout.puts("Created #{Foresite.relative_path(html_path)}")
|
102
108
|
|
103
109
|
# Extract date if it exists.
|
@@ -106,7 +112,7 @@ module Foresite
|
|
106
112
|
{
|
107
113
|
date_ymd: match_data.nil? ? "" : match_data[0],
|
108
114
|
href: Foresite.relative_path(html_path),
|
109
|
-
title:
|
115
|
+
title: title
|
110
116
|
}
|
111
117
|
end
|
112
118
|
|
@@ -116,5 +122,28 @@ module Foresite
|
|
116
122
|
|
117
123
|
$stdout.puts("Created #{Foresite.relative_path(index_html_path)}")
|
118
124
|
end
|
125
|
+
|
126
|
+
desc "watch", "Watches markdown and templates files and runs `build` when they change"
|
127
|
+
long_desc <<-LONGDESC
|
128
|
+
See `build` help for more information
|
129
|
+
LONGDESC
|
130
|
+
|
131
|
+
# @todo How might we test this?
|
132
|
+
def watch
|
133
|
+
dirs_to_watch = [
|
134
|
+
Foresite::DIRNAME_MARKDOWN,
|
135
|
+
Foresite::DIRNAME_ERB
|
136
|
+
]
|
137
|
+
|
138
|
+
$stdout.puts("Watching #{dirs_to_watch.map { "./#{_1}" }.join(", ")} for changes... (Ctrl+C to exit)")
|
139
|
+
|
140
|
+
Filewatcher.new(dirs_to_watch).watch do |changes|
|
141
|
+
changes.each do |filename, event|
|
142
|
+
$stdout.puts("#{File.basename(filename)} #{event}")
|
143
|
+
end
|
144
|
+
|
145
|
+
build
|
146
|
+
end
|
147
|
+
end
|
119
148
|
end
|
120
149
|
end
|
data/lib/foresite/renderer.rb
CHANGED
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
|
@@ -82,8 +83,9 @@ module Foresite
|
|
82
83
|
})
|
83
84
|
end
|
84
85
|
|
85
|
-
def self.render_wrapped(markdown_content)
|
86
|
+
def self.render_wrapped(title, markdown_content)
|
86
87
|
render_erb_file(FILENAME_WRAPPER_HTML, {
|
88
|
+
title: title,
|
87
89
|
content: ::Kramdown::Document.new(markdown_content).to_html
|
88
90
|
})
|
89
91
|
end
|
@@ -1,8 +1,11 @@
|
|
1
|
+
<%
|
2
|
+
index_title = 'Another Foresite Blog'
|
3
|
+
-%>
|
1
4
|
<!DOCTYPE html>
|
2
5
|
<html lang="en">
|
3
6
|
<head>
|
4
7
|
<meta charset="utf-8">
|
5
|
-
<title
|
8
|
+
<title><%= @title ? "#{@title} - #{index_title}" : index_title %></title>
|
6
9
|
<style></style>
|
7
10
|
</head>
|
8
11
|
<body>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foresite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Wiedemann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: filewatcher
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.1'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|