Skip to content

Commit

Permalink
z_url_metadata: Add 'site_name' property
Browse files Browse the repository at this point in the history
  • Loading branch information
mworrell committed Nov 25, 2024
1 parent 7dd5737 commit 4694f97
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/z_url_metadata.erl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ p(url, MD) ->
undefined -> MD#url_metadata.final_url;
PrefUrl -> z_url:abs_link(PrefUrl, MD#url_metadata.final_url)
end;
p(site_name, MD) ->
case p1([<<"og:site_name">>, <<"twitter:site">>], MD) of
undefined ->
Url = case p1([canonical_url], MD) of
undefined -> MD#url_metadata.final_url;
Canonical -> Canonical
end,
case uri_string:parse(Url) of
#{ host := Host } ->
case unicode:characters_to_binary(Host) of
<<"www.", H/binary>> -> H;
H -> H
end;
{error, _, _} ->
undefined
end;
Sitename ->
Sitename
end;
p(content_length, MD) ->
MD#url_metadata.content_length;
p(headers, MD) ->
Expand Down

0 comments on commit 4694f97

Please sign in to comment.