我需要将一些 JSON-LD 内容放在脚本标签中。今天,我把内容是这样的:
page_live.ex
defmodule ProjectWeb.PageLive do
use ProjectWeb, :live_view
@data_structure %{
"@context": "http://www.schema.org",
"@type": "WebSite",
name: "Project",
url: "https://project.com/"
}
@impl true
def mount(_params, _session, socket) do
socket = assign(socket, data_structure: @data_structure)
{:ok, socket}
end
end
根.html.leex
<!DOCTYPE html>
<html lang="pt-BR">
<head>
...
<%= if @data_structure do %>
<script type='application/ld+json'>
<%= Poison.encode!(@data_structure) %>
</script>
<% end %>
...
</head>
<body>
<%= @inner_content %>
</body>
<html>
Poison 库总是转换为字符串。我需要一个 JSON。
如何将 JSON 内容放入脚本标签中?