Add source response
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
35
app/queries/posts/microformat_post.rb
Normal file
35
app/queries/posts/microformat_post.rb
Normal 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
|
Reference in New Issue
Block a user