postwave 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/crystal/src/postwave/post.cr +77 -0
- data/crystal/src/postwave.cr +4 -0
- data/lib/postwave/blog_builder.rb +6 -2
- data/lib/postwave/blog_creator.rb +19 -1
- data/lib/postwave/blog_utilities.rb +9 -0
- data/lib/postwave/display_helper.rb +20 -0
- data/lib/postwave/post.rb +5 -2
- data/lib/postwave/rss_helper.rb +35 -0
- data/lib/postwave/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9ded40bea3eeb7f6f76e5de2f3df929f4ced4d3e8045af330747b5390b06e70
|
4
|
+
data.tar.gz: cc9f0bbe6554d86b510972d59eb979dd41911ad9b081a0a44c04ef974005ee38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1550146a4c3967f077312340d58e3b61691a0022e38c5bc225bae21da657be95b3340ac3a5ef04866f8d5a6861b996ec8161f0ecb57c6309a13d97c3e445d435
|
7
|
+
data.tar.gz: aaec0f9aa5ad0ae598e204e777cfb80eb0087ca59717d6a60a40d7e615407545a4a4d1d1d5190706889ecedfa34c427c00367801c1996a89e5a400330991330e
|
@@ -0,0 +1,77 @@
|
|
1
|
+
class Postwave::Post
|
2
|
+
KNOWN_FIELDS = %w(title date tags title_slug body draft)
|
3
|
+
REQUIRED_FIELDS = %w(title date)
|
4
|
+
MEATADATA_DELIMTER = "---"
|
5
|
+
|
6
|
+
def self.new_from_file_path(path : String)
|
7
|
+
metadata_delimter_count = 0
|
8
|
+
body_buffer_count = 0
|
9
|
+
field_content = { "body" => "" }
|
10
|
+
|
11
|
+
File.readlines(path).each do |line|
|
12
|
+
clean_line = line.strip
|
13
|
+
|
14
|
+
if clean_line == MEATADATA_DELIMTER
|
15
|
+
metadata_delimter_count += 1
|
16
|
+
next
|
17
|
+
end
|
18
|
+
|
19
|
+
if metadata_delimter_count == 0
|
20
|
+
next
|
21
|
+
elsif metadata_delimter_count == 1
|
22
|
+
field, value = clean_line.split(":", 2).map(&:strip)
|
23
|
+
field_content[field] = value
|
24
|
+
else
|
25
|
+
if body_buffer_count == 0
|
26
|
+
body_buffer_count += 1
|
27
|
+
next if clean_line.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
field_content["body"] += "#{line}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# turn "date" into a Time object
|
35
|
+
field_content["date"] = Time.parse(field_content["date"])
|
36
|
+
|
37
|
+
# turn "tags" into an array
|
38
|
+
if field_content["tags"]
|
39
|
+
field_content["tags"] = field_content["tags"].split(",").map do |tag|
|
40
|
+
tag.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, "")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# turn "draft" into boolean
|
45
|
+
if field_content["draft"]
|
46
|
+
field_content["draft"] = field_content["draft"].downcase == "true"
|
47
|
+
end
|
48
|
+
|
49
|
+
self.new(path, field_content)
|
50
|
+
end
|
51
|
+
|
52
|
+
def initialize(@file_name : String, field_content : Hash)
|
53
|
+
|
54
|
+
field_content.each do |field, value|
|
55
|
+
# instance_variable_set("@#{field}", value)
|
56
|
+
self.send("@#{field}".to_sym, value)
|
57
|
+
self.class.send(:attr_accessor, field)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def title_slug : String
|
62
|
+
@title_slug ||= @title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, "")
|
63
|
+
end
|
64
|
+
|
65
|
+
def slug : String
|
66
|
+
@slug ||= @title_slug
|
67
|
+
end
|
68
|
+
|
69
|
+
def slug=(new_slug)
|
70
|
+
@slug = new_slug
|
71
|
+
end
|
72
|
+
|
73
|
+
def generated_file_name
|
74
|
+
# YYYY-MM-DD-slug-from-title.md
|
75
|
+
"#{@date.to_s[..9]}-#{slug}.md"
|
76
|
+
end
|
77
|
+
end
|
@@ -5,6 +5,7 @@ require 'csv'
|
|
5
5
|
require 'time'
|
6
6
|
require_relative "blog_utilities"
|
7
7
|
require_relative "display_helper"
|
8
|
+
require_relative "rss_helper"
|
8
9
|
require_relative "post"
|
9
10
|
|
10
11
|
module Postwave
|
@@ -12,6 +13,7 @@ module Postwave
|
|
12
13
|
include Singleton
|
13
14
|
include BlogUtilities
|
14
15
|
include DisplayHelper
|
16
|
+
include RssHelper
|
15
17
|
|
16
18
|
INDEX_HEADERS = ["slug", "date", "title"]
|
17
19
|
|
@@ -53,6 +55,8 @@ module Postwave
|
|
53
55
|
build_tags_files(tags)
|
54
56
|
build_summary(published_posts, tags)
|
55
57
|
|
58
|
+
build_rss(published_posts)
|
59
|
+
|
56
60
|
build_time = Time.now - start
|
57
61
|
output_build_completed(build_time)
|
58
62
|
end
|
@@ -95,8 +99,8 @@ module Postwave
|
|
95
99
|
def build_summary(posts, tags)
|
96
100
|
summary = {
|
97
101
|
post_count: posts.count,
|
98
|
-
most_recent_file_name: posts.first
|
99
|
-
most_recent_date: posts.first
|
102
|
+
most_recent_file_name: posts.first&.file_name,
|
103
|
+
most_recent_date: posts.first&.date,
|
100
104
|
tags: tags.keys
|
101
105
|
}
|
102
106
|
File.write(File.join(Dir.pwd, POSTS_DIR, META_DIR, SUMMARY_FILE_NAME), summary.to_yaml)
|
@@ -22,6 +22,8 @@ module Postwave
|
|
22
22
|
build_files
|
23
23
|
write_initial_summary_contents
|
24
24
|
|
25
|
+
configure_blog
|
26
|
+
|
25
27
|
output_blog_created
|
26
28
|
end
|
27
29
|
|
@@ -43,7 +45,23 @@ module Postwave
|
|
43
45
|
tags: []
|
44
46
|
}
|
45
47
|
|
46
|
-
File.write(File.join(Dir.pwd, POSTS_DIR, META_DIR, SUMMARY_FILE_NAME), summary.to_yaml)
|
48
|
+
File.write(File.join(Dir.pwd, POSTS_DIR, META_DIR, SUMMARY_FILE_NAME), summary.transform_keys(&:to_s).to_yaml)
|
49
|
+
end
|
50
|
+
|
51
|
+
def configure_blog
|
52
|
+
config = {}
|
53
|
+
|
54
|
+
output_blog_name_prompt
|
55
|
+
config[:name] = gets.chomp
|
56
|
+
output_blog_url_prompt
|
57
|
+
config[:url] = gets.chomp
|
58
|
+
output_blog_posts_path_prompt
|
59
|
+
config[:posts_path] = gets.chomp
|
60
|
+
output_blog_description_prompt
|
61
|
+
config[:description] = gets.chomp
|
62
|
+
|
63
|
+
File.write(File.join(Dir.pwd, CONFIG_FILE_NAME), config.transform_keys(&:to_s).to_yaml)
|
64
|
+
output_config_message
|
47
65
|
end
|
48
66
|
end
|
49
67
|
end
|
@@ -3,6 +3,7 @@ module Postwave
|
|
3
3
|
CONFIG_FILE_NAME = "postwave.yaml"
|
4
4
|
INDEX_FILE_NAME = "index.csv"
|
5
5
|
SUMMARY_FILE_NAME = "summary.yaml"
|
6
|
+
RSS_FILE_NAME = "rss"
|
6
7
|
POSTS_DIR = "_posts"
|
7
8
|
META_DIR = "meta"
|
8
9
|
TAGS_DIR = "tags"
|
@@ -36,5 +37,13 @@ module Postwave
|
|
36
37
|
end
|
37
38
|
missing_paths
|
38
39
|
end
|
40
|
+
|
41
|
+
def config_values
|
42
|
+
@config_values ||= if yaml_load = YAML.load_file(File.join(Dir.pwd, CONFIG_FILE_NAME))
|
43
|
+
yaml_load.transform_keys(&:to_sym)
|
44
|
+
else
|
45
|
+
{}
|
46
|
+
end
|
47
|
+
end
|
39
48
|
end
|
40
49
|
end
|
@@ -7,6 +7,26 @@ module Postwave
|
|
7
7
|
puts "🌊 Creating new blog..."
|
8
8
|
end
|
9
9
|
|
10
|
+
def output_blog_name_prompt
|
11
|
+
puts "Enter the name of this blog (leave blank to skip): "
|
12
|
+
end
|
13
|
+
|
14
|
+
def output_blog_url_prompt
|
15
|
+
puts "Enter the url of this blog (leave blank to skip): "
|
16
|
+
end
|
17
|
+
|
18
|
+
def output_blog_posts_path_prompt
|
19
|
+
puts "Enter the directory for the blog posts (if a post will be at http://example.com/blog/posts/post-title put blog/posts):"
|
20
|
+
end
|
21
|
+
|
22
|
+
def output_blog_description_prompt
|
23
|
+
puts "Enter a short description of this blog (leave blank to skip): "
|
24
|
+
end
|
25
|
+
|
26
|
+
def output_config_message
|
27
|
+
puts "All configuration values can be changed at any time by editing the postwave.yaml file."
|
28
|
+
end
|
29
|
+
|
10
30
|
def output_blog_created
|
11
31
|
puts "New blog set up.".green
|
12
32
|
end
|
data/lib/postwave/post.rb
CHANGED
@@ -33,10 +33,13 @@ module Postwave
|
|
33
33
|
next if clean_line.empty?
|
34
34
|
end
|
35
35
|
|
36
|
-
field_content["body"] += "#{line}
|
36
|
+
field_content["body"] += "#{line}"
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
# turn "date" into a Time object
|
41
|
+
field_content["date"] = Time.parse(field_content["date"])
|
42
|
+
|
40
43
|
# turn "tags" into an array
|
41
44
|
if field_content["tags"]
|
42
45
|
field_content["tags"] = field_content["tags"].split(",").map do |tag|
|
@@ -75,7 +78,7 @@ module Postwave
|
|
75
78
|
|
76
79
|
def generated_file_name
|
77
80
|
# YYYY-MM-DD-slug-from-title.md
|
78
|
-
"#{@date[..9]}-#{slug}.md"
|
81
|
+
"#{@date.to_s[..9]}-#{slug}.md"
|
79
82
|
end
|
80
83
|
|
81
84
|
def update_file_name!
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative "blog_utilities"
|
2
|
+
require "rss"
|
3
|
+
|
4
|
+
module Postwave
|
5
|
+
module RssHelper
|
6
|
+
include BlogUtilities
|
7
|
+
|
8
|
+
def build_rss(posts)
|
9
|
+
File.open(File.join(Dir.pwd, POSTS_DIR, META_DIR, RSS_FILE_NAME), "w") do |rss|
|
10
|
+
rss << rss_content(posts)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def rss_content(posts)
|
15
|
+
RSS::Maker.make("2.0") do |maker|
|
16
|
+
maker.channel.title = config_values[:name]
|
17
|
+
maker.channel.description = config_values[:description]
|
18
|
+
maker.channel.link = config_values[:url]
|
19
|
+
maker.channel.generator = "Postwave"
|
20
|
+
maker.channel.updated = Time.now.to_s
|
21
|
+
|
22
|
+
posts.each do |post|
|
23
|
+
link = "#{config_values[:url]}/#{config_values[:posts_path]}/#{post.slug}"
|
24
|
+
|
25
|
+
maker.items.new_item do |item|
|
26
|
+
item.title = post.title
|
27
|
+
item.link = link
|
28
|
+
item.description = post.body
|
29
|
+
item.pubDate = post.date
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/postwave/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postwave
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Schwantes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -51,6 +51,8 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- bin/postwave
|
54
|
+
- crystal/src/postwave.cr
|
55
|
+
- crystal/src/postwave/post.cr
|
54
56
|
- lib/postwave.rb
|
55
57
|
- lib/postwave/blog_builder.rb
|
56
58
|
- lib/postwave/blog_creator.rb
|
@@ -58,6 +60,7 @@ files:
|
|
58
60
|
- lib/postwave/display_helper.rb
|
59
61
|
- lib/postwave/post.rb
|
60
62
|
- lib/postwave/post_creator.rb
|
63
|
+
- lib/postwave/rss_helper.rb
|
61
64
|
- lib/postwave/version.rb
|
62
65
|
- postwave.gemspec
|
63
66
|
homepage: https://github.com/dorkrawk/postwave
|