1
0
mirror of https://github.com/danbee/micropub.git synced 2025-03-04 08:59:13 +00:00

Add optional title to front matter

This commit is contained in:
Daniel Barber 2019-11-17 17:07:54 -05:00
parent 37fe32f291
commit 2d83f2eb0d
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
2 changed files with 34 additions and 5 deletions

View File

@ -1,4 +1,5 @@
require "date"
require "yaml"
require "kramdown"
module Micropub
@ -67,13 +68,18 @@ module Micropub
end
end
def post_frontmatter
{
"title" => title,
"date" => published.rfc3339,
"layout" => "micropost",
"categories" => categories,
}.compact.to_yaml
end
def post_content
<<~POST
---
date: '#{published.rfc3339}'
layout: micropost
categories:
#{categories.map { |category| "- #{category}\n" }.join.strip}
#{post_frontmatter.strip}
---
#{content}

View File

@ -205,5 +205,28 @@ describe Micropub::Post do
Hallo, Earth!
POST
end
it "returns a post formatted for hugo with a title" do
post = Micropub::Post.new(
"title" => "Welcome!",
"content" => "Hallo, Earth!",
"published" => "2019-11-12",
"category" => ["one", "two", "three"],
)
_(post.post_content).must_equal <<~POST
---
title: Welcome!
date: '2019-11-12T00:00:00+00:00'
layout: micropost
categories:
- one
- two
- three
---
Hallo, Earth!
POST
end
end
end