Add source response

This commit is contained in:
2023-02-03 11:16:31 +11:00
parent dd31388c2c
commit 19fe581c79
5 changed files with 54 additions and 4 deletions

View File

@@ -26,6 +26,7 @@ gem "builder"
gem "httparty"
gem "redcarpet"
gem "reverse_markdown"
gem "rexml"
gem "babosa"
gem "pinboard", github: "dnitza/pinboard", branch: "master"

View File

@@ -203,6 +203,10 @@ GEM
net-ssh (>= 2.6.5, < 8.0.0)
net-ssh (7.0.1)
nio4r (2.5.8)
nokogiri (1.14.1-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.14.1-x86_64-linux)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
@@ -215,6 +219,7 @@ GEM
method_source (~> 1.0)
puma (6.0.1)
nio4r (~> 2.0)
racc (1.6.2)
rack (2.2.5)
rack-test (2.0.2)
rack (>= 1.3)
@@ -225,6 +230,8 @@ GEM
ffi (~> 1.0)
redcarpet (3.5.1)
regexp_parser (2.6.1)
reverse_markdown (2.1.1)
nokogiri
rexml (3.2.5)
rom (5.3.0)
rom-changeset (~> 5.3, >= 5.3.0)
@@ -342,6 +349,7 @@ DEPENDENCIES
rack-test
rake
redcarpet
reverse_markdown
rexml
rom-factory
rom-sql

View File

@@ -2,7 +2,7 @@ module Adamantium
module Actions
module Site
class Config < Action
include Deps["settings", "views.site.home"]
include Deps["settings", "views.site.home", "queries.posts.microformat_post"]
before :authenticate!
def handle(req, res)
@@ -46,6 +46,10 @@ module Adamantium
}
]
}.to_json
elsif req.params[:q] == "source"
res.status = 200
res.content_type = "Application/JSON"
res.body = microformat_post.call(url: req.params[:url], properties: req.params[:properties]).to_json
else
res.render home
end

View File

@@ -2,10 +2,12 @@ module Adamantium
module Commands
module Posts
class Update < Command
def call(params)
slug = URI(params[:url]).path.split("/").last
include Deps["repos.post_repo"]
post_repo.update(slug, params)
def call(params:)
slug = URI(params[:url]).path.split("/").last
post = post_repo.fetch!(slug)
post_repo.update(post.id, params)
end
end
end

View File

@@ -0,0 +1,35 @@
require "reverse_markdown"
module Adamantium
module Queries
module Posts
class MicroformatPost
include Deps["repos.post_repo"]
def call(url:, properties:)
slug = URI(url).path.split("/").last
post = post_repo.fetch!(slug)
markdown_content = ReverseMarkdown.convert(post.content, unknown_tags: :raise, github_flavored: true).to_s
if properties.nil? || properties.empty?
return {
type: ["h-entry"],
properties: {
published: [post.published_at],
content: [markdown_content],
category: post.tags.map { |t| t.label.to_s }
}
}
end
result = {properties: {}}
result[:properties][:published] = [post.published_at] if properties.include? "published"
result[:properties][:content] = [markdown_content] if properties.include? "content"
result[:properties][:category] = post.tags.map { |t| t.label.to_s } if properties.include? "category"
result
end
end
end
end
end