Add metatags to the Address page

pull/858/head
Felipe Renan 6 years ago
parent 3085edf6bd
commit de9290c672
  1. 15
      apps/block_scout_web/lib/block_scout_web/templates/address/_metatags.html.eex
  2. 2
      apps/block_scout_web/lib/block_scout_web/templates/address/overview.html.eex
  3. 1
      apps/block_scout_web/lib/block_scout_web/templates/address_contract/_metatags.html.eex
  4. 1
      apps/block_scout_web/lib/block_scout_web/templates/address_internal_transaction/_metatags.html.eex
  5. 1
      apps/block_scout_web/lib/block_scout_web/templates/address_read_contract/_metatags.html.eex
  6. 1
      apps/block_scout_web/lib/block_scout_web/templates/address_token/_metatags.html.eex
  7. 1
      apps/block_scout_web/lib/block_scout_web/templates/address_token_transfer/_metatags.html.eex
  8. 1
      apps/block_scout_web/lib/block_scout_web/templates/address_transaction/_metatags.html.eex
  9. 1
      apps/block_scout_web/lib/block_scout_web/templates/address_validation/_metatags.html.eex
  10. 9
      apps/block_scout_web/lib/block_scout_web/views/address_view.ex
  11. 21
      apps/block_scout_web/test/block_scout_web/views/address_view_test.exs

@ -0,0 +1,15 @@
<%= if assigns[:address] do %>
<title>
<%= gettext(
"%{address} - %{subnetwork} Explorer",
address: BlockScoutWeb.AddressView.address_page_title(@address),
subnetwork: LayoutView.subnetwork_title()
) %>
</title>
<meta name="description" content="<%= gettext "View the account balance, transactions, and other data for %{address} on the %{network}", address: to_string(@address), network: LayoutView.network_title() %>">
<meta name="keywords" content="<%= BlockScoutWeb.AddressView.address_page_title(@address) <> ", " <> Explorer.coin() <> ", "<> LayoutView.network_title() %>">
<% else %>
<title>
<%= gettext "Top Accounts - %{subnetwork} Explorer", subnetwork: LayoutView.subnetwork_title() %>
</title>
<% end %>

@ -23,7 +23,7 @@
<% end %>
<span class="mr-4 mb-2">
<span data-selector="transaction-count">
<%= Cldr.Number.to_string!(@transaction_count, format: "#,###") %>
<%= Cldr.Number.to_string!(@transaction_count, format: "#,###") %>
</span> <%= gettext("Transactions") %>
<%= if validator?(@validation_count) do %>
<span data-selector="validation-count">

@ -0,0 +1 @@
<%= render BlockScoutWeb.AddressView, "_metatags.html", conn: @conn, address: @address %>

@ -0,0 +1 @@
<%= render BlockScoutWeb.AddressView, "_metatags.html", conn: @conn, address: @address %>

@ -0,0 +1 @@
<%= render BlockScoutWeb.AddressView, "_metatags.html", conn: @conn, address: @address %>

@ -0,0 +1 @@
<%= render BlockScoutWeb.AddressView, "_metatags.html", conn: @conn, address: @address %>

@ -0,0 +1 @@
<%= render BlockScoutWeb.AddressView, "_metatags.html", conn: @conn, address: @address %>

@ -0,0 +1 @@
<%= render BlockScoutWeb.AddressView, "_metatags.html", conn: @conn, address: @address %>

@ -0,0 +1 @@
<%= render BlockScoutWeb.AddressView, "_metatags.html", conn: @conn, address: @address %>

@ -3,6 +3,7 @@ defmodule BlockScoutWeb.AddressView do
alias Explorer.Chain
alias Explorer.Chain.{Address, Hash, InternalTransaction, SmartContract, Token, TokenTransfer, Transaction, Wei}
alias BlockScoutWeb.LayoutView
@dialyzer :no_match
@ -231,4 +232,12 @@ defmodule BlockScoutWeb.AddressView do
"0x" <> short_address
end
def address_page_title(address) do
cond do
smart_contract_verified?(address) -> "#{address.smart_contract.name} (#{to_string(address)})"
contract?(address) -> "Contract #{to_string(address)}"
true -> "#{to_string(address)}"
end
end
end

@ -316,4 +316,25 @@ defmodule BlockScoutWeb.AddressViewTest do
assert String.length(short_hash) == 6
end
end
describe "address_page_title/1" do
test "uses the Smart Contract name when the contract is verified" do
smart_contract = build(:smart_contract, name: "POA")
address = build(:address, smart_contract: smart_contract)
assert AddressView.address_page_title(address) == "POA (#{address.hash})"
end
test "uses the string 'Contract' when it's a contract" do
address = build(:contract_address, smart_contract: nil)
assert AddressView.address_page_title(address) == "Contract #{address.hash}"
end
test "uses the address hash when it is not a contract" do
address = build(:address, smart_contract: nil)
assert AddressView.address_page_title(address) == "#{address.hash}"
end
end
end

Loading…
Cancel
Save