Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
Use Yaml to generate markdown header
Browse files Browse the repository at this point in the history
  • Loading branch information
miry committed Jul 22, 2022
1 parent 11c5618 commit d785d1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions spec/medium/post_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe Medium::Post do
it "render full page" do
subject = Medium::Post.from_json(post_fixture)
content, assets = subject.to_md
content.size.should eq(3322)
content.size.should eq(3324)
assets.size.should eq(1)
assets.keys.should eq([
"ab24f0b378f797307fddc32f10a99685.html",
Expand All @@ -51,7 +51,7 @@ describe Medium::Post do
subject.ctx = ::Medup::Context.new(settings)

content, assets = subject.to_md
content.size.should eq(3048)
content.size.should eq(3050)
assets.keys.should eq([
"0*FbFs8aNmqNLKw4BM.png",
"ab24f0b378f797307fddc32f10a99685.html",
Expand Down
32 changes: 17 additions & 15 deletions src/medium/post.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "json_mapping"
require "yaml"

require "./post/*"

Expand Down Expand Up @@ -30,23 +31,24 @@ module Medium
end

def to_md
result = "---\n\
url: #{mediumUrl}\n\
canonical_url: #{canonicalUrl}\n\
title: #{@title}\n\
subtitle: #{subtitle}\n\
slug: #{@slug}\n\
description: #{seo_description}\n\
tags: #{tags}\n"
assets = Hash(String, String).new

unless @user.nil?
user = @user.not_nil!
result += "author: #{user.name}\n\
username: #{user.username}\n"
header = {
"url" => mediumUrl,
"canonical_url" => canonicalUrl,
"title" => @title,
"subtitle" => subtitle,
"slug" => @slug,
"description" => seo_description,
"tags" => tags,
}
user = @user
if !user.nil?
header["author"] = user.name
header["username"] = user.username
end

result += "---\n\n"
result = header.to_yaml + "---\n\n"

assets = Hash(String, String).new
footer = "\n"

@content.bodyModel.paragraphs.map do |paragraph|
Expand Down

0 comments on commit d785d1c

Please sign in to comment.