mitodl / ocw-hugo-themes

A Hugo theme for building OCW websites
BSD 3-Clause "New" or "Revised" License
5 stars 4 forks source link

Update og:image tag to use fully-qualified URL #1177

Closed pt2302 closed 1 year ago

pt2302 commented 1 year ago

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/1616.

Description (What does it do?)

This makes a small change to the way that the .env environment configuration file is validated: the variable RESOURCE_BASE_URL can now be an empty string, which is required for testing this PR.

The primary change in this PR is that it updates the og:image tag to use a fully-qualified URL.

How can this be tested?

To test this locally, ensure that RESOURCE_BASE_URL= is set to any empty string in the .env file. Replace the content of the partial located at /base-theme/layouts/partials/extra_metadata.html with the content currently on the main branch, namely:

{{ $context := .context }}
{{ $imageData := partial "course-image-url.html" $context }}
{{ $courseImageUrl := index $imageData 0 }}

<meta property="og:image" content="{{- $courseImageUrl -}}" />

Run yarn start <course-id> for any course. Inspect the page source, and verify that the <meta property="og:image" content=/some_relative_url> tag has only a relative URL in it.

Now, revert this update to /base-theme/layouts/partials/extra_metadata.html, and run yarn start <course-id> again. Verify that the <meta property="og:image" content=some_url> tag now has a fully-qualified URL.

github-actions[bot] commented 1 year ago

Netlify Deployments:
www: https://ocw-hugo-themes-www-pr-1177--ocw-next.netlify.app/
Course v2: https://ocw-hugo-themes-course-v2-pr-1177--ocw-next.netlify.app/