Add emoji to statuses
This commit is contained in:
18
slices/main/actions/feeds/statuses_json.rb
Normal file
18
slices/main/actions/feeds/statuses_json.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
module Main
|
||||
module Actions
|
||||
module Feeds
|
||||
class StatusesJSON < Action
|
||||
include Deps["views.feeds.statuses_json", "repos.post_repo"]
|
||||
|
||||
def handle(req, res)
|
||||
posts = post_repo.statuses_for_rss.map do |post|
|
||||
Decorators::Posts::Decorator.new(post).to_h
|
||||
end
|
||||
|
||||
res.content_type = "application/json; charset=utf-8"
|
||||
res.body = JSON.generate(posts, quirks_mode: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -24,6 +24,8 @@ module Main
|
||||
get "/feeds/rss", to: "feeds.rss"
|
||||
get "/feeds/statuses_rss", to: "feeds.statuses_rss"
|
||||
|
||||
get "/feeds/statuses_json", to: "feeds.statuses_json"
|
||||
|
||||
get "/more", to: "more.index"
|
||||
|
||||
get "/hikes", to: "workouts.index"
|
||||
|
@@ -53,11 +53,23 @@ module Main
|
||||
doc.at("//img")
|
||||
end
|
||||
|
||||
def inline_image_sources
|
||||
inline_images
|
||||
&.select {|attr, _value| attr == "src"}
|
||||
&.map {|img| img[1] } || []
|
||||
end
|
||||
|
||||
def photo_sources
|
||||
photos.map{|photo| photo["value"]}
|
||||
end
|
||||
|
||||
def prefix_emoji
|
||||
if name
|
||||
nil
|
||||
elsif photos? && content == ""
|
||||
"📷"
|
||||
elsif __getobj__.emoji
|
||||
__getobj__.emoji
|
||||
else
|
||||
@prefix_emoji ||= if (match = content.match(Unicode::Emoji::REGEX))
|
||||
match
|
||||
@@ -133,6 +145,15 @@ module Main
|
||||
__getobj__.trips
|
||||
end
|
||||
|
||||
def to_h
|
||||
{
|
||||
id: slug,
|
||||
emoji: prefix_emoji,
|
||||
content: raw_content,
|
||||
images: (inline_image_sources + photo_sources).compact
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# e.g. geo:-37.75188,144.90417;u=35
|
||||
|
21
slices/main/views/feeds/statuses_json.rb
Normal file
21
slices/main/views/feeds/statuses_json.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
require "builder"
|
||||
|
||||
module Main
|
||||
module Views
|
||||
module Feeds
|
||||
class StatusesJSON < Main::View
|
||||
include Deps["repos.post_repo"]
|
||||
|
||||
expose :posts do
|
||||
post_repo.statuses_for_rss.map do |post|
|
||||
Decorators::Posts::Decorator.new post
|
||||
end
|
||||
end
|
||||
|
||||
expose :json, decorate: false, layout: true do |posts|
|
||||
posts.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user