Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow og:image meta tag to be customisable #847

Merged
merged 2 commits into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
You can now provide a divider item (e.g "or") to separate items
([PR #849](https://github.com/alphagov/govuk-frontend/pull/849))

- Allow og:image meta tag url to be set independantly
Image url for the opengraph image needs to be absolute and
can now be overwritten by setting the `assetUrl` variable.
([PR #847](https://github.com/alphagov/govuk-frontend/pull/847))

🔧 Fixes:

- Replace conflicting `js-hidden` class used within the tabs component with a new modifier class.
Expand Down Expand Up @@ -75,7 +80,7 @@
`headingLevel: <number>` parameter. Default is `2`.
([PR #853](https://github.com/alphagov/govuk-frontend/pull/853))

- Update date input component
- Update date input component

Allow the `name` and `id` attributes to be passed individually for each input item.

Expand Down
6 changes: 4 additions & 2 deletions src/template.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% from "./components/skip-link/macro.njk" import govukSkipLink %}
{% from "./components/header/macro.njk" import govukHeader %}
{% from "./components/footer/macro.njk" import govukFooter %}
{# specify absolute url for the static assets folder e.g. http://wwww.domain.com/assets #}
{% set assetUrl = assetUrl | default(assetPath) %}
<!DOCTYPE html>
<html lang="{{ htmlLang | default('en') }}" class="govuk-template {{ htmlClasses }}">
<head>
Expand All @@ -19,9 +21,9 @@
{% endblock %}

{% block head %}{% endblock %}

{# The default og:image is added below head so that scrapers see any custom metatags first, and this is just a fallback #}
<meta property="og:image" content="{{ assetPath | default('/assets') }}/images/govuk-opengraph-image.png">
{# image url needs to be absolute e.g. http://wwww.domain.com/.../govuk-opengraph-image.png #}
<meta property="og:image" content="{{ assetUrl | default('/assets') }}/images/govuk-opengraph-image.png">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the default needs to be 'assetPath' otherwise this is a breaking change still?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe {{ openGraphImagePath | assertPath | default('/assets') }}

not sure

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't work with assetPath anyway, so not sure it's a breaking change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, but consider if someone set their 'assetPath' to a absolute path, it would be working for those users?

Copy link
Author

@kr8n3r kr8n3r Jul 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah.
we can set
{% set assetUrl = assetUrl or (assetPath | default('/assets')) %}

so if they do have it set to absolute atm, OG image will still work.

for anyone new, they can assign a new value to assetUrl ?

Copy link
Author

@kr8n3r kr8n3r Jul 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified so that the default value for assetUrl is assetPath, insuring it is not a breaking change if anyone specified an absolute url for the assets

</head>
<body class="govuk-template__body {{ bodyClasses }}">
<script>document.body.className = ((document.body.className) ? document.body.className + ' js-enabled' : 'js-enabled');</script>
Expand Down