From 12fd372c7383455b8464c3c7513dcbc97bfd4c25 Mon Sep 17 00:00:00 2001 From: AshGDS <8880610+AshGDS@users.noreply.github.com> Date: Mon, 14 Oct 2024 16:07:22 +0100 Subject: [PATCH] Add share links variant to landing page - We need to do a bit of remapping because the share_links components wants symbols rather than strings in its hashmaps. Co-authored-by: Ashley Burnett --- Gemfile.lock | 2 +- app/models/block/share_links.rb | 11 +++++++++++ .../landing_page/blocks/_share_links.html.erb | 12 ++++++++++++ .../landing_page.yaml | 17 +++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 app/models/block/share_links.rb create mode 100644 app/views/landing_page/blocks/_share_links.html.erb diff --git a/Gemfile.lock b/Gemfile.lock index 655abeacf3..d3c2000446 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -160,7 +160,7 @@ GEM govuk_personalisation (1.0.0) plek (>= 1.9.0) rails (>= 6, < 8) - govuk_publishing_components (44.2.0) + govuk_publishing_components (44.3.0) govuk_app_config govuk_personalisation (>= 0.7.0) kramdown diff --git a/app/models/block/share_links.rb b/app/models/block/share_links.rb new file mode 100644 index 0000000000..082babea8a --- /dev/null +++ b/app/models/block/share_links.rb @@ -0,0 +1,11 @@ +module Block + class ShareLinks < Block::Base + attr_reader :links + + def initialize(block_hash) + super(block_hash) + + @links = data.fetch("links").map { |l| { href: l["href"], text: l["text"], icon: l["icon"] } } + end + end +end diff --git a/app/views/landing_page/blocks/_share_links.html.erb b/app/views/landing_page/blocks/_share_links.html.erb new file mode 100644 index 0000000000..c9a65ca3a1 --- /dev/null +++ b/app/views/landing_page/blocks/_share_links.html.erb @@ -0,0 +1,12 @@ +<% if block.links.any? %> + <%= render "govuk_publishing_components/components/heading", { + text: "Share links heading", + padding: true + } %> + + <%= render "govuk_publishing_components/components/share_links", { + square_icons: true, + columns: true, + links: block.links + } %> +<% end %> diff --git a/lib/data/landing_page_content_items/landing_page.yaml b/lib/data/landing_page_content_items/landing_page.yaml index d33f038316..f08f9780a3 100644 --- a/lib/data/landing_page_content_items/landing_page.yaml +++ b/lib/data/landing_page_content_items/landing_page.yaml @@ -141,3 +141,20 @@ blocks: blocks: - type: govspeak content:

Title 2 govspeak title goes here

+- type: share_links + links: + - href: "/twitter-share-link" + text: "Twitter" + icon: "twitter" + - href: "/instagram-share-link" + text: "Instagram" + icon: "instagram" + - href: "/flickr-share-link" + text: "Flickr" + icon: "flickr" + - href: "/facebook-share-link" + text: "Facebook" + icon: "facebook" + - href: "/youtube-share-link" + text: "YouTube" + icon: "youtube"