aardi 0.9.2 → 2.0.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/lib/aardi/abstract_blog.rb +9 -4
- data/lib/aardi/abstract_feed.rb +15 -3
- data/lib/aardi/abstract_page_support.rb +10 -4
- data/lib/aardi/archive.rb +24 -19
- data/lib/aardi/atom_feed.rb +11 -11
- data/lib/aardi/blog.rb +18 -12
- data/lib/aardi/config.rb +16 -12
- data/lib/aardi/content_hashes.rb +13 -6
- data/lib/aardi/custom_renderer.rb +2 -4
- data/lib/aardi/day.rb +6 -5
- data/lib/aardi/errors.rb +6 -0
- data/lib/aardi/file_target.rb +7 -8
- data/lib/aardi/folder.rb +7 -12
- data/lib/aardi/home.rb +14 -15
- data/lib/aardi/home_footer_links.rb +21 -0
- data/lib/aardi/init_files/config.yml +1 -0
- data/lib/aardi/json_feed.rb +6 -7
- data/lib/aardi/metadata.rb +36 -0
- data/lib/aardi/month.rb +12 -12
- data/lib/aardi/orphanage.rb +3 -3
- data/lib/aardi/page.rb +1 -1
- data/lib/aardi/page_content.rb +2 -2
- data/lib/aardi/page_target.rb +4 -6
- data/lib/aardi/path_servlet.rb +2 -2
- data/lib/aardi/post.rb +12 -21
- data/lib/aardi/post_bookmark_line.rb +26 -0
- data/lib/aardi/renderer.rb +42 -0
- data/lib/aardi/site.rb +11 -44
- data/lib/aardi/sitemap.rb +14 -8
- data/lib/aardi/tag_blog.rb +42 -0
- data/lib/aardi/tags.rb +61 -0
- data/lib/aardi/tasks/fixtimes.rake +2 -2
- data/lib/aardi/tasks/homepage.rake +2 -2
- data/lib/aardi/tasks/init.rake +24 -22
- data/lib/aardi/tasks/load_config.rake +1 -1
- data/lib/aardi/tasks/new.rake +2 -2
- data/lib/aardi/tasks/now.rake +1 -1
- data/lib/aardi/tasks/recent.rake +1 -1
- data/lib/aardi/tasks/render.rake +3 -1
- data/lib/aardi/tasks/server.rake +6 -6
- data/lib/aardi/tasks.rb +2 -2
- data/lib/aardi/template.rb +33 -19
- data/lib/aardi/timekeeper.rb +6 -13
- data/lib/aardi/version.rb +1 -1
- data/lib/aardi/year.rb +7 -6
- data/lib/aardi.rb +51 -41
- metadata +14 -144
- data/lib/aardi/ledger.rb +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0f5fd17e9f26a95d4822008bf0d1c359e2f887219296c35a6576eb88e87131f5
|
|
4
|
+
data.tar.gz: 59244e3456a33e30b26ca690a8cfe130cf9f42fd2f3165b00856da1405ab3972
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 024e92b44b23e64e7b4f4d13ab59d081ad7f8accbbab321a021a61e7516efd27f9d29e5a25bb653b5df3b2c32bbaaa99144ba132d00724ce143519647c0cb04b
|
|
7
|
+
data.tar.gz: 5a41b64b3262b2f7f969a93b9b9f06e0e1bc0601e48a14541574f151d8bfb7b95a919e40ac759c50ccdcbb7ff37edbc85e85743cc128a52a82b242e4909f583f
|
data/lib/aardi/abstract_blog.rb
CHANGED
|
@@ -4,13 +4,18 @@ module Aardi
|
|
|
4
4
|
class AbstractBlog
|
|
5
5
|
attr_reader :key
|
|
6
6
|
|
|
7
|
-
def metadata = (@metadata ||=
|
|
7
|
+
def metadata = (@metadata ||= Metadata.new)
|
|
8
8
|
|
|
9
9
|
def mtime = children.max_by(&:mtime)&.mtime
|
|
10
10
|
|
|
11
11
|
def render
|
|
12
|
-
children.
|
|
13
|
-
|
|
12
|
+
children.each_with_object({}) { |child, acc| acc.merge!(child.render) }.merge!(write_target)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def title
|
|
16
|
+
return "#{base_title} - #{@tag}" if @tag
|
|
17
|
+
|
|
18
|
+
base_title
|
|
14
19
|
end
|
|
15
20
|
|
|
16
21
|
private
|
|
@@ -20,7 +25,7 @@ module Aardi
|
|
|
20
25
|
end
|
|
21
26
|
|
|
22
27
|
def write_target
|
|
23
|
-
source = PageContent.new
|
|
28
|
+
source = PageContent.new(content, title, metadata)
|
|
24
29
|
PageTarget.new(source, target_path).write
|
|
25
30
|
end
|
|
26
31
|
end
|
data/lib/aardi/abstract_feed.rb
CHANGED
|
@@ -2,25 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
module Aardi
|
|
4
4
|
class AbstractFeed < AbstractBlog
|
|
5
|
-
def initialize(posts)
|
|
5
|
+
def initialize(posts, archive_path = nil, tag = nil)
|
|
6
|
+
@archive_path = archive_path
|
|
6
7
|
@posts = posts
|
|
8
|
+
@tag = tag
|
|
7
9
|
end
|
|
8
10
|
|
|
9
11
|
def render
|
|
10
12
|
write_target
|
|
11
13
|
end
|
|
12
14
|
|
|
13
|
-
def target_path
|
|
15
|
+
def target_path
|
|
16
|
+
return "./#{@archive_path}/#{feed_file}" if @archive_path
|
|
17
|
+
|
|
18
|
+
"./#{feed_file}"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Keep #title private so Nokogiri `:title` in ATOMFeed#feed_details
|
|
22
|
+
# as an element name rather than a delegated call.
|
|
23
|
+
private :title
|
|
14
24
|
|
|
15
25
|
private
|
|
16
26
|
|
|
27
|
+
def base_title = Config[:site_title]
|
|
28
|
+
|
|
17
29
|
def children
|
|
18
30
|
@posts
|
|
19
31
|
end
|
|
20
32
|
|
|
21
33
|
def creation = children.max_by(&:creation)&.creation
|
|
22
34
|
|
|
23
|
-
def feed_url = "#{
|
|
35
|
+
def feed_url = "#{Config[:site_url]}#{target_path[1..]}"
|
|
24
36
|
|
|
25
37
|
def updated = children.max_by(&:updated)&.updated
|
|
26
38
|
|
|
@@ -2,19 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
module Aardi
|
|
4
4
|
module AbstractPageSupport
|
|
5
|
-
|
|
5
|
+
def metadata
|
|
6
|
+
@metadata
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def mtime
|
|
10
|
+
@mtime
|
|
11
|
+
end
|
|
6
12
|
|
|
7
13
|
def parse_source(path)
|
|
8
|
-
File.open(path, encoding:
|
|
14
|
+
File.open(path, encoding: 'utf-8') do |file|
|
|
9
15
|
parts = file.read.rpartition("\n----\n")
|
|
10
|
-
@metadata =
|
|
16
|
+
@metadata = Metadata.new(parts.first, path)
|
|
11
17
|
@src_content = parts.last
|
|
12
18
|
@mtime = file.mtime.utc
|
|
13
19
|
end
|
|
14
20
|
end
|
|
15
21
|
|
|
16
22
|
def title
|
|
17
|
-
metadata
|
|
23
|
+
metadata.title || @src_content[/\A(?:#+ +)?([^\n]+)/, 1]
|
|
18
24
|
end
|
|
19
25
|
end
|
|
20
26
|
end
|
data/lib/aardi/archive.rb
CHANGED
|
@@ -2,47 +2,52 @@
|
|
|
2
2
|
|
|
3
3
|
module Aardi
|
|
4
4
|
class Archive < AbstractBlog
|
|
5
|
-
def initialize(
|
|
6
|
-
@posts = posts
|
|
5
|
+
def initialize(archive_path, tag = nil, tags = nil)
|
|
7
6
|
@archive_path = archive_path
|
|
7
|
+
@tag = tag
|
|
8
|
+
@tags = tags
|
|
9
|
+
@index = Hash.new { |hash, year| hash[year] = Year.new(year, @archive_path, @tag) }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def <<(post)
|
|
13
|
+
@index[post.creation.year] << post
|
|
8
14
|
end
|
|
9
15
|
|
|
10
16
|
def content
|
|
11
17
|
year_fmt = "| %<year>s | %<months>s \n"
|
|
12
|
-
month_fmt = "[ %<count>s ](#{
|
|
18
|
+
month_fmt = "[ %<count>s ](#{Config[:site_url]}/%<archive_path>s/%<year>s/%<month>s/)"
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
rows = years.map { |year| year.archive_row(year_fmt, month_fmt) }.join
|
|
21
|
+
"#{title_heading}#{tag_list}**When**:\n\n#{table_header}#{rows}"
|
|
15
22
|
end
|
|
16
23
|
|
|
17
24
|
def target_path = "./#{@archive_path}/index.html"
|
|
18
25
|
|
|
19
|
-
def title = Aardi.config[:blog_archive_title]
|
|
20
|
-
|
|
21
26
|
private
|
|
22
27
|
|
|
23
|
-
def
|
|
24
|
-
index = Hash.new { |hash, year| hash[year] = Year.new(year, @archive_path) }
|
|
25
|
-
@posts.each do |post|
|
|
26
|
-
index[post.year] << post
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
index
|
|
30
|
-
end
|
|
28
|
+
def base_title = Config[:blog_archive_title]
|
|
31
29
|
|
|
32
30
|
def children
|
|
33
31
|
years
|
|
34
32
|
end
|
|
35
33
|
|
|
36
|
-
def
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
||Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|
|
|
34
|
+
def table_header
|
|
35
|
+
"||Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|
|
|
40
36
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
41
37
|
"
|
|
42
38
|
end
|
|
43
39
|
|
|
40
|
+
def tag_list
|
|
41
|
+
return '' unless @tags
|
|
42
|
+
return '' if @tags.empty?
|
|
43
|
+
|
|
44
|
+
"**What**: #{@tags.inline_links}\n\n"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def title_heading = "# #{title}\n\n"
|
|
48
|
+
|
|
44
49
|
def years
|
|
45
|
-
@years ||=
|
|
50
|
+
@years ||= @index.values.sort_by { |date| -date.key }
|
|
46
51
|
end
|
|
47
52
|
end
|
|
48
53
|
end
|
data/lib/aardi/atom_feed.rb
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
module Aardi
|
|
4
4
|
class ATOMFeed < AbstractFeed
|
|
5
5
|
def content
|
|
6
|
-
atom_feed = Nokogiri::XML::Builder.new(encoding:
|
|
7
|
-
feed(
|
|
6
|
+
atom_feed = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do
|
|
7
|
+
feed('xmlns' => 'http://www.w3.org/2005/Atom') do |feed|
|
|
8
8
|
feed_details(feed)
|
|
9
9
|
end
|
|
10
10
|
end
|
|
@@ -13,15 +13,14 @@ module Aardi
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
# :reek:TooManyStatements
|
|
16
|
+
# rubocop:disable Metrics/MethodLength
|
|
16
17
|
def feed_details(feed)
|
|
17
|
-
aardi_config = Aardi.config
|
|
18
|
-
|
|
19
18
|
feed.author do
|
|
20
|
-
name(
|
|
19
|
+
name(Config[:site_author])
|
|
21
20
|
end
|
|
22
21
|
|
|
23
|
-
subnodes = {id: feed_url, link: {href: feed_url, rel:
|
|
24
|
-
|
|
22
|
+
subnodes = { id: feed_url, link: { href: feed_url, rel: 'self' },
|
|
23
|
+
title:, updated: updated.iso8601 }
|
|
25
24
|
|
|
26
25
|
subnodes.each do |node, value|
|
|
27
26
|
feed.public_send node, value
|
|
@@ -31,11 +30,12 @@ module Aardi
|
|
|
31
30
|
post_details(post, feed)
|
|
32
31
|
end
|
|
33
32
|
end
|
|
33
|
+
# rubocop:enable Metrics/MethodLength
|
|
34
34
|
|
|
35
35
|
private
|
|
36
36
|
|
|
37
37
|
def feed_file
|
|
38
|
-
|
|
38
|
+
'index.xml'
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
# :reek:FeatureEnvy
|
|
@@ -45,10 +45,10 @@ module Aardi
|
|
|
45
45
|
post_url = post.url
|
|
46
46
|
|
|
47
47
|
# For safety, must use content_ and not content:
|
|
48
|
-
content_(post.feed_snippet).type =
|
|
48
|
+
content_(post.feed_snippet).type = 'html'
|
|
49
49
|
|
|
50
|
-
subnodes = {id: post_url, link: {href: post_url}, title: post.title,
|
|
51
|
-
|
|
50
|
+
subnodes = { id: post_url, link: { href: post_url }, title: post.title,
|
|
51
|
+
published: post.creation.iso8601, updated: post.updated.iso8601 }
|
|
52
52
|
subnodes.each do |node, value|
|
|
53
53
|
feed.public_send node, value
|
|
54
54
|
end
|
data/lib/aardi/blog.rb
CHANGED
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
module Aardi
|
|
4
4
|
class Blog < AbstractBlog
|
|
5
|
-
def initialize
|
|
6
|
-
@
|
|
7
|
-
@
|
|
5
|
+
def initialize
|
|
6
|
+
@posts = []
|
|
7
|
+
@blog_path = nil
|
|
8
|
+
@archive_path = Config[:blog_archive_path]
|
|
9
|
+
@tags = Tags.new
|
|
8
10
|
end
|
|
9
11
|
|
|
10
|
-
def
|
|
11
|
-
@posts
|
|
12
|
+
def <<(post)
|
|
13
|
+
@posts << post
|
|
14
|
+
archive << post
|
|
15
|
+
@tags << post
|
|
12
16
|
end
|
|
13
17
|
|
|
14
18
|
def report_recent
|
|
@@ -18,15 +22,15 @@ module Aardi
|
|
|
18
22
|
private
|
|
19
23
|
|
|
20
24
|
def archive
|
|
21
|
-
Archive.new(
|
|
25
|
+
@archive ||= Archive.new(@archive_path, tag, @tags)
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
def atom_feed
|
|
25
|
-
ATOMFeed.new(feed_posts)
|
|
29
|
+
ATOMFeed.new(feed_posts, @blog_path, tag)
|
|
26
30
|
end
|
|
27
31
|
|
|
28
32
|
def children
|
|
29
|
-
[archive, home, atom_feed, json_feed]
|
|
33
|
+
[archive, home, atom_feed, json_feed, *@tags]
|
|
30
34
|
end
|
|
31
35
|
|
|
32
36
|
def feed_posts
|
|
@@ -34,17 +38,19 @@ module Aardi
|
|
|
34
38
|
end
|
|
35
39
|
|
|
36
40
|
def home
|
|
37
|
-
Home.new(recent_posts(:blog_home_posts), @archive_path)
|
|
41
|
+
Home.new(recent_posts(:blog_home_posts), @archive_path, @blog_path, tag)
|
|
38
42
|
end
|
|
39
43
|
|
|
40
44
|
def json_feed
|
|
41
|
-
JSONFeed.new(feed_posts)
|
|
45
|
+
JSONFeed.new(feed_posts, @blog_path, tag)
|
|
42
46
|
end
|
|
43
47
|
|
|
44
48
|
def recent_posts(conf_key)
|
|
45
|
-
posts.
|
|
49
|
+
@posts.max_by(Config[conf_key], &:creation)
|
|
46
50
|
end
|
|
47
51
|
|
|
48
|
-
def
|
|
52
|
+
def tag = nil
|
|
53
|
+
|
|
54
|
+
def write_target = {}
|
|
49
55
|
end
|
|
50
56
|
end
|
data/lib/aardi/config.rb
CHANGED
|
@@ -2,20 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
module Aardi
|
|
4
4
|
class Config
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
RAISE_ON_MISS = ->(_, key) { raise KeyError, "Key not found: #{key.inspect}" }
|
|
6
|
+
|
|
7
|
+
@data = Hash.new(&RAISE_ON_MISS)
|
|
8
|
+
|
|
9
|
+
class << self
|
|
10
|
+
def [](key) = @data[key]
|
|
11
|
+
def fetch(key, default = nil) = @data.fetch(key, default)
|
|
12
|
+
def load(path) = prepare(File.read(path))
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
def prepare(config_yaml)
|
|
15
|
+
@data.merge!(YAML.safe_load(config_yaml).transform_keys(&:to_sym))
|
|
16
|
+
@data.freeze
|
|
17
|
+
self
|
|
18
|
+
end
|
|
10
19
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
config_hash.transform_keys!(&:to_sym)
|
|
15
|
-
config_hash[:markup_options]&.transform_keys!(&:to_sym)
|
|
16
|
-
@data.merge!(config_hash)
|
|
17
|
-
@data.freeze
|
|
18
|
-
self
|
|
20
|
+
def reset
|
|
21
|
+
@data = Hash.new(&RAISE_ON_MISS)
|
|
22
|
+
end
|
|
19
23
|
end
|
|
20
24
|
end
|
|
21
25
|
end
|
data/lib/aardi/content_hashes.rb
CHANGED
|
@@ -15,6 +15,16 @@ module Aardi
|
|
|
15
15
|
@hashes[path] = hash
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
def replace(new_hashes)
|
|
19
|
+
@hashes = new_hashes
|
|
20
|
+
@new_hashes = nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def save(new_hashes)
|
|
24
|
+
replace(new_hashes)
|
|
25
|
+
write
|
|
26
|
+
end
|
|
27
|
+
|
|
18
28
|
def write
|
|
19
29
|
return if new_hashes == @original_hashes
|
|
20
30
|
|
|
@@ -25,15 +35,12 @@ module Aardi
|
|
|
25
35
|
private
|
|
26
36
|
|
|
27
37
|
def new_hashes
|
|
28
|
-
@new_hashes ||= @hashes.sort.map
|
|
38
|
+
@new_hashes ||= @hashes.sort.map { |path, hash| "#{path}: #{hash}\n" }.join
|
|
29
39
|
end
|
|
30
40
|
|
|
31
41
|
def read_hashes
|
|
32
|
-
@original_hashes = File.exist?(@path) ? File.read(@path) :
|
|
33
|
-
@hashes = @original_hashes.
|
|
34
|
-
path, hash = line.split(":", 2)
|
|
35
|
-
[path.strip, hash.to_i]
|
|
36
|
-
end
|
|
42
|
+
@original_hashes = File.exist?(@path) ? File.read(@path) : ''
|
|
43
|
+
@hashes = @original_hashes.scan(/^(.+): (\d+)$/).to_h { |path, hash| [path, hash.to_i] }
|
|
37
44
|
end
|
|
38
45
|
end
|
|
39
46
|
end
|
|
@@ -7,9 +7,7 @@ module Aardi
|
|
|
7
7
|
HEADER_SQUEEZE = /&#.*?;|"|[^a-z0-9\-_]/
|
|
8
8
|
|
|
9
9
|
def header(text, header_level)
|
|
10
|
-
|
|
11
|
-
id = header_id(text)
|
|
12
|
-
"<h#{header_level} id=\"#{id}\">#{squeezed_text}</h#{header_level}>"
|
|
10
|
+
"<h#{header_level} id=\"#{header_id(text)}\">#{text.squeeze(' ')}</h#{header_level}>"
|
|
13
11
|
end
|
|
14
12
|
|
|
15
13
|
def link(link, title, content)
|
|
@@ -33,7 +31,7 @@ module Aardi
|
|
|
33
31
|
end
|
|
34
32
|
|
|
35
33
|
def header_stub_id(text)
|
|
36
|
-
text.downcase.strip.tr(
|
|
34
|
+
text.downcase.strip.tr(' ', '-').gsub(HEADER_SQUEEZE, '').squeeze('-')
|
|
37
35
|
end
|
|
38
36
|
|
|
39
37
|
def ids
|
data/lib/aardi/day.rb
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module Aardi
|
|
4
4
|
# :reek:TooManyInstanceVariables
|
|
5
5
|
class Day < AbstractBlog
|
|
6
|
-
def initialize(year, month, key, archive_path)
|
|
6
|
+
def initialize(year, month, key, archive_path, tag = nil)
|
|
7
7
|
@year = year
|
|
8
8
|
@month = month
|
|
9
9
|
@key = key
|
|
10
10
|
@archive_path = archive_path
|
|
11
|
+
@tag = tag
|
|
11
12
|
@posts = []
|
|
12
13
|
end
|
|
13
14
|
|
|
@@ -18,7 +19,7 @@ module Aardi
|
|
|
18
19
|
def content
|
|
19
20
|
@content ||= begin
|
|
20
21
|
sorted_posts = @posts.sort_by(&:creation)
|
|
21
|
-
posts_content = sorted_posts.reverse
|
|
22
|
+
posts_content = sorted_posts.reverse.map(&:content)
|
|
22
23
|
"# #{title}\n#{posts_content.join}"
|
|
23
24
|
end
|
|
24
25
|
end
|
|
@@ -29,16 +30,16 @@ module Aardi
|
|
|
29
30
|
"./#{@archive_path}/#{@year}/#{@month}/#{self}/index.html"
|
|
30
31
|
end
|
|
31
32
|
|
|
32
|
-
def title = date.strftime("%A, %-e %B %Y")
|
|
33
|
-
|
|
34
33
|
private
|
|
35
34
|
|
|
35
|
+
def base_title = date.strftime('%A, %-e %B %Y')
|
|
36
|
+
|
|
36
37
|
def children
|
|
37
38
|
@posts
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
def date = Date.new(@year.key, @month.key, @key)
|
|
41
42
|
|
|
42
|
-
def to_s = @key.to_s.rjust(2,
|
|
43
|
+
def to_s = @key.to_s.rjust(2, '0')
|
|
43
44
|
end
|
|
44
45
|
end
|
data/lib/aardi/errors.rb
ADDED
data/lib/aardi/file_target.rb
CHANGED
|
@@ -3,20 +3,22 @@
|
|
|
3
3
|
module Aardi
|
|
4
4
|
class FileTarget
|
|
5
5
|
def initialize(src, target_path)
|
|
6
|
+
renderer = Aardi.renderer
|
|
6
7
|
@src = src
|
|
7
8
|
@path = target_path
|
|
8
|
-
@content_hashes =
|
|
9
|
+
@content_hashes = renderer.content_hashes
|
|
10
|
+
@html_files = renderer.html_files
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
# :reek:TooManyStatements
|
|
12
14
|
def write
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return unless do_write
|
|
15
|
+
hash = @src.output_hash
|
|
16
|
+
return { @path => hash } unless should_write?
|
|
16
17
|
|
|
17
18
|
FileUtils.mkdir_p(File.dirname(@path))
|
|
18
19
|
File.write(@path, "#{@src.output}\n")
|
|
19
20
|
puts("Wrote #{@path}")
|
|
21
|
+
{ @path => hash }
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
private
|
|
@@ -33,11 +35,8 @@ module Aardi
|
|
|
33
35
|
return true unless file_exists?
|
|
34
36
|
return false unless output_hash_changed?
|
|
35
37
|
|
|
38
|
+
# in case cache missing (or corrupt) yet file good.
|
|
36
39
|
@src.output != File.read(@path).strip
|
|
37
40
|
end
|
|
38
|
-
|
|
39
|
-
def update_hash
|
|
40
|
-
@content_hashes[@path] = @src.output_hash
|
|
41
|
-
end
|
|
42
41
|
end
|
|
43
42
|
end
|
data/lib/aardi/folder.rb
CHANGED
|
@@ -4,15 +4,15 @@ module Aardi
|
|
|
4
4
|
class Folder
|
|
5
5
|
def initialize(path)
|
|
6
6
|
@path = path
|
|
7
|
-
@normalized_path = "#{path.sub(/^\./,
|
|
7
|
+
@normalized_path = "#{path.sub(/^\./, '')}/"
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
def mtime = children.
|
|
10
|
+
def mtime = children.filter_map(&:mtime).max
|
|
11
11
|
|
|
12
12
|
def render
|
|
13
|
-
children.
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
result = children.each_with_object({}) { |child, acc| acc.merge!(child.render) }
|
|
14
|
+
Aardi.renderer.sitemap.record_mtime(@normalized_path, mtime) unless @path == '.'
|
|
15
|
+
result
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
private
|
|
@@ -26,16 +26,11 @@ module Aardi
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def paths
|
|
29
|
-
@paths ||= FileList["#{@path}/*"].exclude(
|
|
29
|
+
@paths ||= FileList["#{@path}/*"].exclude(Config[:files_to_exclude])
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def sources
|
|
33
|
-
@sources ||= paths.filter_map { |path| Page.new(path) if path.end_with?(
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def update_sitemap
|
|
37
|
-
# '.' is the top level so skip it since the homepage will register itself
|
|
38
|
-
Aardi.ledger[:sitemap].update_mtime(@normalized_path, mtime) unless @path == "."
|
|
33
|
+
@sources ||= paths.filter_map { |path| Page.new(path) if path.end_with?('.md') }
|
|
39
34
|
end
|
|
40
35
|
end
|
|
41
36
|
end
|
data/lib/aardi/home.rb
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module Aardi
|
|
4
4
|
class Home < AbstractBlog
|
|
5
|
-
def initialize(posts, archive_path)
|
|
5
|
+
def initialize(posts, archive_path, blog_path = nil, tag = nil)
|
|
6
6
|
@posts = posts
|
|
7
7
|
@archive_path = archive_path
|
|
8
|
+
@blog_path = blog_path
|
|
9
|
+
@tag = tag
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
def content
|
|
@@ -12,36 +14,33 @@ module Aardi
|
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
def render
|
|
15
|
-
Aardi.
|
|
17
|
+
Aardi.renderer.sitemap.update_mtime('/', mtime) unless @blog_path
|
|
16
18
|
write_target
|
|
17
19
|
end
|
|
18
20
|
|
|
19
|
-
def target_path
|
|
21
|
+
def target_path
|
|
22
|
+
return "./#{@blog_path}/index.html" if @blog_path
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
'./index.html'
|
|
25
|
+
end
|
|
22
26
|
|
|
23
27
|
private
|
|
24
28
|
|
|
29
|
+
def base_title = Config[:blog_home_title]
|
|
30
|
+
|
|
25
31
|
def children
|
|
26
32
|
@posts
|
|
27
33
|
end
|
|
28
34
|
|
|
29
|
-
def content_footer
|
|
30
|
-
site_url = Aardi.config[:site_url]
|
|
31
|
-
more_archive = "[Archive](#{site_url}/#{@archive_path}/)"
|
|
32
|
-
more_rss = "[RSS](#{site_url}/index.xml)"
|
|
33
|
-
more_json = "[JSON](#{site_url}/index.json)"
|
|
34
|
-
"**More:** #{more_archive}, #{more_rss}, #{more_json}"
|
|
35
|
-
end
|
|
35
|
+
def content_footer = HomeFooterLinks.new(@blog_path).to_s
|
|
36
36
|
|
|
37
37
|
def days_hash
|
|
38
|
-
@days_hash ||= @posts.group_by { |post| post.creation.strftime(
|
|
38
|
+
@days_hash ||= @posts.group_by { |post| post.creation.strftime('%Y-%m-%d') }
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def post_day_content(post_day)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"## #{date_header}\n#{posts_content}"
|
|
42
|
+
first_post = post_day.first
|
|
43
|
+
"## #{first_post.creation.strftime('%A, %e %B %Y')}\n#{post_day.map(&:content).join}"
|
|
45
44
|
end
|
|
46
45
|
|
|
47
46
|
def post_days_content
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aardi
|
|
4
|
+
class HomeFooterLinks
|
|
5
|
+
def initialize(blog_path)
|
|
6
|
+
@blog_path = blog_path
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def to_s
|
|
10
|
+
"**More:** [Archive](#{archive_url}), [RSS](#{rss_url}), [JSON](#{json_url})"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def archive_url = "#{base_url}/#{Config[:blog_archive_path]}/"
|
|
16
|
+
def base_url = "#{Config[:site_url]}#{feed_base}"
|
|
17
|
+
def feed_base = @blog_path ? "/#{@blog_path}" : ''
|
|
18
|
+
def json_url = "#{base_url}/index.json"
|
|
19
|
+
def rss_url = "#{base_url}/index.xml"
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/aardi/json_feed.rb
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
module Aardi
|
|
4
4
|
class JSONFeed < AbstractFeed
|
|
5
5
|
def content
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
home_page_url: aardi_config[:site_url], feed_url:}
|
|
6
|
+
feed_content = { version: 'https://jsonfeed.org/version/1.1', title:,
|
|
7
|
+
home_page_url: Config[:site_url], feed_url: }
|
|
9
8
|
feed_content[:items] = @posts.map { |post| post_details(post) }
|
|
10
9
|
|
|
11
10
|
JSON.pretty_generate(feed_content)
|
|
@@ -14,19 +13,19 @@ module Aardi
|
|
|
14
13
|
private
|
|
15
14
|
|
|
16
15
|
def feed_file
|
|
17
|
-
|
|
16
|
+
'index.json'
|
|
18
17
|
end
|
|
19
18
|
|
|
20
19
|
def post_details(post)
|
|
21
20
|
post_updated = post.updated
|
|
22
21
|
post_creation = post.creation
|
|
23
22
|
|
|
24
|
-
details = {id: post.name, url: post.url, title: post.title,
|
|
25
|
-
|
|
23
|
+
details = { id: post.name, url: post.url, title: post.title,
|
|
24
|
+
date_published: post_creation.iso8601, content_html: post.feed_snippet }
|
|
26
25
|
|
|
27
26
|
details[:date_modified] = post_updated.iso8601 unless post_creation == post_updated
|
|
28
27
|
|
|
29
|
-
details
|
|
28
|
+
details
|
|
30
29
|
end
|
|
31
30
|
end
|
|
32
31
|
end
|