m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-08-12 21:06:13 -0700
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-08-12 21:16:35 -0700
commit59447261a889b1b65f32e325894ef6fc2b9288c6 (patch)
tree548614e0ee9cdd7000562f87a4be0c46d6a78e60
parentd24ac544f910da9d4d4f9dd7db0e24248257f9a7 (diff)
Change post ids in pather
-rw-r--r--lib/blog.rb13
-rwxr-xr-xscripts/build.rb2
-rw-r--r--src/blog.html.erb2
-rw-r--r--src/index.html.erb2
4 files changed, 15 insertions, 4 deletions
diff --git a/lib/blog.rb b/lib/blog.rb
index 96e79dd..fe552e5 100644
--- a/lib/blog.rb
+++ b/lib/blog.rb
@@ -3,12 +3,22 @@ require 'date'
def parse_post filename
file_raw = File.read(src filename).force_encoding('UTF-8').split('---')
post = YAML.load file_raw[0]
+
post['date'] = DateTime.parse(post['date'])
- post['content'] = file_raw[1].strip
+ post['raw_content'] = file_raw[1].strip
post['filename'] = filename
+ post['id'] = "blog_#{basename_no_extension filename}"
post
end
+def basename_no_extension filename
+ File.basename filename.sub(/\.[\w.]*$/, '')
+end
+
+def compile_post post
+ post['content'] = ERB.new(post['raw_content']).result binding
+end
+
def generate_blog_post post
ERB.new(File.read(src 'post-template.html.erb')).result binding
end
@@ -27,6 +37,7 @@ end
def write_blog_files
posts.each do |post|
+ compile_post post
content = ERB.new(File.read(src 'post-template.html.erb')).result binding
write_templated content, post['filename'], head_title: post['title'], h1_title: 'Blog.'
end
diff --git a/scripts/build.rb b/scripts/build.rb
index aad1c00..fd78c7b 100755
--- a/scripts/build.rb
+++ b/scripts/build.rb
@@ -45,7 +45,7 @@ if !Dir.exists? 'public/blog'
end
posts.each do |post|
- P.add post['title'], post['filename']
+ P.add post['id'], post['filename']
end
write_statics statics
diff --git a/src/blog.html.erb b/src/blog.html.erb
index bd7b8aa..3709ca9 100644
--- a/src/blog.html.erb
+++ b/src/blog.html.erb
@@ -1,7 +1,7 @@
<ul>
<% posts.each do |post| %>
<li>
- <a href=<%= path_to post['title'] %>><%= post['title'] %></a> <%= format_date post['date'] %>
+ <a href=<%= path_to post['id'] %>><%= post['title'] %></a> <%= format_date post['date'] %>
</li>
<% end %>
</ul>
diff --git a/src/index.html.erb b/src/index.html.erb
index eb9728f..7d4f7d0 100644
--- a/src/index.html.erb
+++ b/src/index.html.erb
@@ -9,7 +9,7 @@
<ul>
<% posts.take(5).each do |post| %>
<li>
- <a href='<%= path_to post['title'] %>'><%= post['title'] %></a> <%= format_date post['date'] %>
+ <a href='<%= path_to post['id'] %>'><%= post['title'] %></a> <%= format_date post['date'] %>
</li>
<% end %>
</ul>