Skip to content

Commit

Permalink
Set media page title.
Browse files Browse the repository at this point in the history
  • Loading branch information
yamat47 committed Aug 14, 2024
1 parent 8e5d0ed commit abe16ac
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/app/controllers/media/game_schedules_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class GameSchedulesController < ApplicationController
before_action :ensure_season_param

def index
season = Season.find_by!(short_name: params[:season])
@season = Season.find_by!(short_name: params[:season])

game_schedules = GameSchedule.start_at_ordered
.game_field_ordered
.where(season:)
.where(season: @season)
.preload(:home_team, :visitor_team, :game_field, :tournament)

# group by date.
Expand Down
11 changes: 11 additions & 0 deletions app/app/helpers/media/seo_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Media
module SeoHelper
BASE_PAGE_TITLE = '関東学生フットボールクラブ連盟 公式サイト'

def media_page_title(title)
[title, BASE_PAGE_TITLE].filter_map(&:presence).join('|')
end
end
end
3 changes: 2 additions & 1 deletion app/app/views/layouts/media/application.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
!!!
%html
%head
%title KcffMatchHub
%title
= media_page_title(content_for(:title))
%meta{ content: 'width=device-width,initial-scale=1', name: 'viewport' }
= csrf_meta_tags
= csp_meta_tag
Expand Down
1 change: 1 addition & 0 deletions app/app/views/media/game_fields/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
:ruby
add_breadcrumb t('view.media.breadcrumbs.root'), root_path
add_breadcrumb t('view.media.breadcrumbs.game_fields.index')
content_for(:title, t('view.media.page_title.game_fields.index'))

.media-list
.media-list__title
Expand Down
1 change: 1 addition & 0 deletions app/app/views/media/game_schedules/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
:ruby
add_breadcrumb t('view.media.breadcrumbs.root'), root_path
add_breadcrumb t('view.media.breadcrumbs.game_schedules.index')
content_for(:title, t('view.media.page_title.game_schedules.index', season: @season.full_name))

.media-list
.media-list__title
Expand Down
1 change: 1 addition & 0 deletions app/app/views/media/notices/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
add_breadcrumb t('view.media.breadcrumbs.root'), root_path
add_breadcrumb t('view.media.breadcrumbs.notices.index'), notices_path
add_breadcrumb @notice.title
content_for(:title, @notice.title)

.media-list
.media-list__content
Expand Down
1 change: 1 addition & 0 deletions app/app/views/media/teams/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
:ruby
add_breadcrumb t('view.media.breadcrumbs.root'), root_path
add_breadcrumb t('view.media.breadcrumbs.teams.index')
content_for(:title, t('view.media.page_title.teams.index'))

.media-list
.media-list__title
Expand Down
9 changes: 9 additions & 0 deletions app/config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,15 @@ ja:
start_at: K.O.
tournament: 大会
teams: 対戦チーム
page_title:
game_fields:
index: 試合会場
teams:
index: 所属チーム
game_schedules:
index: 日程・結果(%{season})
notices:
index: お知らせ
breadcrumbs:
root: トップページ
game_fields:
Expand Down
25 changes: 25 additions & 0 deletions app/spec/helpers/media/seo_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Media::SeoHelper do
describe '#media_page_title' do
context 'when title is nil' do
subject { helper.media_page_title(nil) }

it { is_expected.to eq '関東学生フットボールクラブ連盟 公式サイト' }
end

context 'when title is empty string' do
subject { helper.media_page_title('') }

it { is_expected.to eq '関東学生フットボールクラブ連盟 公式サイト' }
end

context 'when title is present' do
subject { helper.media_page_title('タイトル') }

it { is_expected.to eq 'タイトル|関東学生フットボールクラブ連盟 公式サイト' }
end
end
end

0 comments on commit abe16ac

Please sign in to comment.