forked from AkkomaGang/akkoma
投稿ページとユーザーページのOGP対応
This commit is contained in:
parent
86f05e0683
commit
9a91b5e669
1 changed files with 47 additions and 9 deletions
|
@ -35,17 +35,55 @@ def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id}
|
||||||
def redirector_with_meta(conn, params) do
|
def redirector_with_meta(conn, params) do
|
||||||
{:ok, index_content} = File.read(index_file_path(conn))
|
{:ok, index_content} = File.read(index_file_path(conn))
|
||||||
|
|
||||||
tags = build_tags(conn, params)
|
if get_in(params, [:object]) do
|
||||||
preloads = preload_data(conn, params)
|
tags = build_tags(conn, params)
|
||||||
title = "<title>#{Pleroma.Config.get([:instance, :name])}</title>"
|
preloads = preload_data(conn, params)
|
||||||
|
title = "<title>#{Pleroma.Config.get([:instance, :name])}</title>"
|
||||||
|
title2 = "<meta property=\"og:title\" content=\"#{params.user.name} の投稿\">"
|
||||||
|
description = "<meta property=\"og:description\" content=\"#{params.object.data["content"]}\">"
|
||||||
|
type = "<meta property=\"og:type\" content=\"article\" />"
|
||||||
|
site_name = "<meta property=\"og:site_name\" content=\"flyerdonut\" />"
|
||||||
|
image =
|
||||||
|
case params.object.data["attachment"] do
|
||||||
|
[] ->
|
||||||
|
# attachmentが空のリストの場合の処理
|
||||||
|
"<meta property=\"og:image\" content=#{List.first(params.user.avatar["url"])["href"]} />"
|
||||||
|
_ ->
|
||||||
|
# attachmentが空のリストでない場合の処理
|
||||||
|
"<meta property=\"og:image\" content=#{List.first(List.first(params.object.data["attachment"])["url"])["href"]} /><meta name=\"note:card\" content=\"summary_large_image\">"
|
||||||
|
end
|
||||||
|
#datas = "<!-- datas #{inspect(params.object)} -->"
|
||||||
|
twitter = "<meta name=\"twitter:card\" content=\"summary\" />"
|
||||||
|
|
||||||
response =
|
response =
|
||||||
index_content
|
index_content
|
||||||
|> String.replace("<!--server-generated-meta-->", tags <> preloads <> title)
|
|> String.replace("<!--server-generated-meta-->", tags <> preloads <> title <> title2 <> description <> type <> site_name <> image <> twitter)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("text/html")
|
|> put_resp_content_type("text/html")
|
||||||
|> send_resp(200, response)
|
|> send_resp(200, response)
|
||||||
|
|
||||||
|
|
||||||
|
else
|
||||||
|
#Objectが存在しない場合(Userページ)
|
||||||
|
tags = build_tags(conn, params)
|
||||||
|
preloads = preload_data(conn, params)
|
||||||
|
title = "<title>#{Pleroma.Config.get([:instance, :name])}</title>"
|
||||||
|
title2 = "<meta property=\"og:title\" content=\"#{params.user.name} のページ\">"
|
||||||
|
description = "<meta property=\"og:description\" content=\"#{params.user.bio}\">"
|
||||||
|
type = "<meta property=\"og:type\" content=\"article\" />"
|
||||||
|
site_name = "<meta property=\"og:site_name\" content=\"flyerdonut\" />"
|
||||||
|
image = "<meta property=\"og:image\" content=#{List.first(params.user.avatar["url"])["href"]} />"
|
||||||
|
twitter = "<meta name=\"twitter:card\" content=\"summary\" />"
|
||||||
|
|
||||||
|
response =
|
||||||
|
index_content
|
||||||
|
|> String.replace("<!--server-generated-meta-->", tags <> preloads <> title <> title2 <> description <> type <> site_name <> image <> twitter)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_resp_content_type("text/html")
|
||||||
|
|> send_resp(200, response)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirector_with_preload(conn, %{"path" => ["pleroma", "admin"]}) do
|
def redirector_with_preload(conn, %{"path" => ["pleroma", "admin"]}) do
|
||||||
|
|
Loading…
Reference in a new issue