LoginSignup
6
0

More than 1 year has passed since last update.

piyopiyo.exポータルチュートリアル 5章~faviconとページタイトルを設定する~

Last updated at Posted at 2022-10-23

本記事はpiyopiyo.exポータルチュートリアルの5章となります。

本章の目的

ブラウザのタブに表示される、faviconとサイト名を変更します。

image.png

faviconを設定する

faviconの設定についてはプロジェクト生成時に下記に設定されているので、該当箇所に画像を配置するだけで置き換えることができます。

lib/phoenix_app_web/endpoint.ex
~中略~
  plug Plug.Static,
    at: "/",
    from: :phoenix_app,
    gzip: false,
    only: ~w(assets fonts images favicon.ico robots.txt) # <-- favicon setting here
~中略~

デフォルトでは空のファイルが配置されています。
image.png
上書きすることで画像ファイルを置き換えます。
image.png
置き換え後の画像
image.png

サイトのタイトルを変更する

サイトタイトルについては、すでに3章でroot.htmlを修正したタイミングで変更済です。

lib/phoenix_app_web/templates/layout/root.html.heex
~中略~
    <meta name="og:type" content="website">
    <meta name="og:title" content="piyopiyo.exポータル"> <!-- Web Site Title here --> 
    <meta name="twitter:card" content="summary">
~中略~

ただし、現在トップページとなっているmessages一覧画面のハンドラで上書きされているため、「Listing Messages」が表示されています。
該当箇所を削除します。

lib/phoenix_app_web/live/message_live/index.ex
  defp apply_action(socket, :index, _params) do
    socket
#    |> assign(:page_title, "Listing Messages") # <-- delete here
    |> assign(:message, nil)
  end

結果の確認

faviconとページタイトルが反映されました。

image.png

関連情報

  • この演習完了時点のリポジトリ断面

  • 使用したpiyopiyo.exポータル公式のfavicon画像

6
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
0