From dccca3b6aba1f8bc63ff32f0a9e52c07d57159eb Mon Sep 17 00:00:00 2001 From: Yohei Yasukawa Date: Mon, 28 Oct 2024 20:47:53 +0900 Subject: [PATCH] Pick the first image in a doc if exists and set it as OGP image --- app/controllers/docs_controller.rb | 5 +++-- app/views/docs/show.html.erb | 1 + db/docs/tobitate-japan.md | 10 ++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/docs_controller.rb b/app/controllers/docs_controller.rb index 3ba97285a..d86397952 100644 --- a/app/controllers/docs_controller.rb +++ b/app/controllers/docs_controller.rb @@ -26,8 +26,9 @@ def show @doc.content.gsub! "{{ NUM_OF_PARTNERSHIPS }}", Dojo::NUM_OF_PARTNERSHIPS end - @content = Kramdown::Document.new(@doc.content, input: 'GFM').to_html - @url = request.url + @content = Kramdown::Document.new(@doc.content, input: 'GFM').to_html + @url = request.url + @meta_image = Nokogiri::HTML.parse(@content).at("//img")&.attribute('data-src')&.value || "/img/ogp-docs.jpeg" # Add here if you want to optimize meta description. case @doc.filename diff --git a/app/views/docs/show.html.erb b/app/views/docs/show.html.erb index 711e25adb..f3f01be1b 100644 --- a/app/views/docs/show.html.erb +++ b/app/views/docs/show.html.erb @@ -5,6 +5,7 @@ <% provide :desc, @doc.description %> <% provide :url, @url %> <% provide :lang, @lang %> +<% provide :meta_image, @meta_image %>
diff --git a/db/docs/tobitate-japan.md b/db/docs/tobitate-japan.md index 442d377cc..95044b16b 100644 --- a/db/docs/tobitate-japan.md +++ b/db/docs/tobitate-japan.md @@ -1,14 +1,16 @@ # ✈️ トビタテ!留学JAPAN / CoderDojo 留学 - - CoderDojo 留学 - Supported by トビタテ!留学 JAPAN - +
トビタテ!留学JAPAN「日本代表プログラム」は、返済不要の奨学金や研修等を通して学生の留学を支援する奨学金制度です。 高校生・高専生・大学生を対象とした文科省主催の取り組みで、返済不要の奨学金や研修など通して **好きなこと** で留学ができるプログラムです。 + + CoderDojo 留学 - Supported by トビタテ!留学 JAPAN + +
## [✅](#agenda) 特長 {#agenda}