Skip to content

Commit

Permalink
Allow non-GOV.UK favicon and opengraph assets
Browse files Browse the repository at this point in the history
Fixes: #347

We already provide a way to non display the crown next to the service name by setting `show_govuk_logo: false` in config/tech-docs.yml. This is used by external users such as [MOJ](https://user-guide.modernisation-platform.service.justice.gov.uk).

This work extends the usage of that setting enabled custom favicon and opengraph image insted of the default Crown.
It's limited to just the `favicon.ico`, `favicon.svg` and `opengraph-image.png`, but this should suffice.

Users need to create those assets and place them in their `source/images` folder.
  • Loading branch information
kr8n3r committed Jan 21, 2025
1 parent d41b0d5 commit 6801fa3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 5 additions & 1 deletion lib/govuk_tech_docs/meta_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ def canonical_url
attr_reader :config, :current_page

def page_image
"#{host}/assets/govuk/assets/images/govuk-opengraph-image.png"
if config[:tech_docs][:show_govuk_logo]
"#{host}/assets/govuk/assets/images/govuk-opengraph-image.png"
else
"#{host}/images/opengraph-image.png"
end
end

def site_name
Expand Down
15 changes: 10 additions & 5 deletions lib/source/layouts/core.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
<%= stylesheet_link_tag :manifest %>

<link rel="canonical" href="<%= meta_tags.canonical_url %>">
<link rel="icon" sizes="48x48" href="/assets/govuk/assets/images/favicon.ico">
<link rel="icon" sizes="any" href="/assets/govuk/assets/images/favicon.svg" type="image/svg+xml">
<link rel="mask-icon" href="/assets/govuk/assets/images/govuk-icon-mask.svg" color="#0b0c0c">
<link rel="apple-touch-icon" href="/assets/govuk/assets/images/govuk-icon-180.png">
<link rel="manifest" href="/assets/govuk/assets/manifest.json">
<% if config[:tech_docs][:show_govuk_logo] %>
<link rel="icon" sizes="48x48" href="/assets/govuk/assets/images/favicon.ico">
<link rel="icon" sizes="any" href="/assets/govuk/assets/images/favicon.svg" type="image/svg+xml">
<link rel="mask-icon" href="/assets/govuk/assets/images/govuk-icon-mask.svg" color="#0b0c0c">
<link rel="apple-touch-icon" href="/assets/govuk/assets/images/govuk-icon-180.png">
<link rel="manifest" href="/assets/govuk/assets/manifest.json">
<% else %>
<link rel="icon" sizes="48x48" href="/mages/favicon.ico">
<link rel="icon" sizes="any" href="/images/favicon.svg" type="image/svg+xml">
<% end %>

<% meta_tags.tags.each do |name, content| %>
<%= tag :meta, name: name, content: content %>
Expand Down

0 comments on commit 6801fa3

Please sign in to comment.