diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb new file mode 100644 index 00000000..8c2dba7e --- /dev/null +++ b/app/controllers/news_controller.rb @@ -0,0 +1,10 @@ +class NewsController < ApplicationController + def index + @title = '☯️ CoderDojo ニュース 📰' + @desc = 'CoderDojo に関するお知らせの一覧ページです。' + @url = request.url + + # データベースからニュースデータを取得(最新順) + @news_items = News.recent + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 47285052..44c9afa7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -107,7 +107,7 @@ def prefecture_name_in_english(prefecture_name) # 都道府県名の英語表記を返す簡易マッピング # 「都」「府」「県」を除去してから検索 name_without_suffix = prefecture_name.gsub(/[都府県]$/, '') - + prefecture_names = { '北海道' => 'Hokkaido', '青森' => 'Aomori', @@ -157,7 +157,7 @@ def prefecture_name_in_english(prefecture_name) '鹿児島' => 'Kagoshima', '沖縄' => 'Okinawa' } - + prefecture_names[name_without_suffix] || prefecture_name end @@ -208,32 +208,8 @@ def translate_dojo_tag(tag_name) 'HTML' => 'HTML', 'CSS' => 'CSS' } - - tag_translations[tag_name] || tag_name - end - def format_news_title(news) - has_custom_emoji = news.title[0]&.match?(/[\p{Emoji}&&[^0-9#*]]/) - return news.title if has_custom_emoji - - # Add preset Emoji to its prefix if news.title does not have Emoji. - emoji = case news.url - when %r{/podcasts/\d+} - '📻' - when %r{prtimes\.jp} - '📢' - else - '📰' - end - "#{emoji} #{news.title}" + tag_translations[tag_name] || tag_name end - def news_link_url(news) - # Convert absolute podcast URLs to relative paths for local development - if news.url.match?(%r{^https://coderdojo\.jp/podcasts/\d+$}) - news.url.sub('https://coderdojo.jp', '') - else - news.url - end - end end diff --git a/app/models/news.rb b/app/models/news.rb index 0dd08cbc..0bd5fa84 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -6,4 +6,29 @@ class News < ApplicationRecord uniqueness: true, format: { with: /\Ahttps?:\/\/.*\z/i } validates :published_at, presence: true + + def formatted_title + has_custom_emoji = title[0]&.match?(/[\p{Emoji}&&[^0-9#*]]/) + return title if has_custom_emoji + + # Add preset Emoji to its prefix if title does not have Emoji. + emoji = case url + when %r{/podcasts/\d+} + '📻' + when %r{prtimes\.jp} + '📢' + else + '📰' + end + "#{emoji} #{title}" + end + + def link_url + # Convert absolute podcast URLs to relative paths for local development + if url.match?(%r{^https://coderdojo\.jp/podcasts/\d+$}) + url.sub('https://coderdojo.jp', '') + else + url + end + end end diff --git a/app/views/home/show.html.erb b/app/views/home/show.html.erb index 5b4626c1..38e5a0e8 100644 --- a/app/views/home/show.html.erb +++ b/app/views/home/show.html.erb @@ -194,30 +194,15 @@ -

- 最新情報はメールで受け取れます。 -
- (毎月配信) -

- -
-
-
- - - -
-
-
+ + <%= render 'shared/dojo_letter_signup' %>
- + 過去の記事を読む diff --git a/app/views/news/index.html.erb b/app/views/news/index.html.erb new file mode 100644 index 00000000..5e95242e --- /dev/null +++ b/app/views/news/index.html.erb @@ -0,0 +1,44 @@ +<% provide :title, strip_tags(@title) %> +<% provide :desc, strip_tags(@desc) %> +<% provide :url, @url %> +<% provide :meta_image, "/img/ogp-news.jpeg" %> + +
+
+

<%= @title.html_safe %>

+ +

+ <%= @desc.html_safe %> +

+
+ +
+ <%= render 'shared/dojo_letter_signup' %> + <%= render 'shared/social_buttons' %> +
+ +
+ <% if @news_items.any? %> +
+ <% @news_items.each do |news| %> +
+

+ <%= link_to news.formatted_title, news.link_url, target: '_blank', rel: 'noopener' %> +

+

+ + <%= l(news.published_at.to_date, format: :long) if news.published_at %> +

+
+ <% end %> +
+ <% else %> +

現在、ニュース記事はありません。

+ <% end %> +
+ +
+ <%= render 'shared/dojo_letter_signup' %> + <%= render 'shared/social_buttons' %> +
+
diff --git a/app/views/shared/_dojo_letter_signup.html.erb b/app/views/shared/_dojo_letter_signup.html.erb new file mode 100644 index 00000000..4d8c2920 --- /dev/null +++ b/app/views/shared/_dojo_letter_signup.html.erb @@ -0,0 +1,17 @@ +

+ 最新情報はメールで受け取れます。 +
+ (毎月配信) +

+ +
+
+
+ + + +
+
+
\ No newline at end of file diff --git a/app/views/shared/_footer.html.erb b/app/views/shared/_footer.html.erb index 5b304963..fea784bb 100644 --- a/app/views/shared/_footer.html.erb +++ b/app/views/shared/_footer.html.erb @@ -2,7 +2,7 @@

Top | Kata - | News + | News | 資料 | 憲章 | 統計 @@ -16,7 +16,7 @@

- <%= link_to news_url do %> + <%= link_to news_index_path do %> <% end %> <%= link_to facebook_page_url do %> diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb index 96868778..e06800a0 100644 --- a/app/views/shared/_header.html.erb +++ b/app/views/shared/_header.html.erb @@ -21,7 +21,7 @@ <%= link_to '最近の活動', '/#news' %>