Skip to content

Commit

Permalink
Update og:image tag to use fully-qualified URL (#1177)
Browse files Browse the repository at this point in the history
* Update og:image tag to use fully-qualified URL

* Allow RESOURCE_BASE_URL to be an empty string

* Adding comment about .env validation change
  • Loading branch information
pt2302 committed Jun 27, 2023
1 parent 3cde05d commit 575baa6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
7 changes: 4 additions & 3 deletions base-theme/layouts/partials/extra_metadata.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{ $context := .context }}
{{ $imageData := partial "course-image-url.html" $context }}
{{ $courseImageUrl := index $imageData 0 }}

<meta property="og:image" content="{{- $courseImageUrl -}}" />
{{ $courseImageMetadata := index $imageData 1 }}
{{- $sitemapDomain := partial "sitemap_domain.html" -}}
{{- $absCourseImage := printf "https://%s%s" $sitemapDomain $courseImageMetadata.Params.file -}}
<meta property="og:image" content="{{- $absCourseImage -}}" />
5 changes: 3 additions & 2 deletions env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ const envSchema = {
OCW_TEST_COURSE: envalid.str({
devDefault: "9.40-spring-2018"
}),
RESOURCE_BASE_URL: envalid.url({
desc: "Base URL with which to prefix resource paths in hugo's output.",
RESOURCE_BASE_URL: envalid.str({
// str, not url, to allow for ""
desc: "Base URL with which to prefix resource paths in Hugo's output.",
devDefault: "https://live-qa.ocw.mit.edu/"
}),
SEARCH_API_URL: envalid.url({
Expand Down
10 changes: 10 additions & 0 deletions tests-e2e/ocw-ci-test-course/homepage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,13 @@ test.describe("Course info", () => {
})
})
})

test("og:image tag has fully-qualified URL", async ({ page }) => {
const course = new CoursePage(page, "course")
await course.goto()
const metaShareImage = page.locator('meta[property="og:image"]')
await expect(metaShareImage).toHaveAttribute(
"content",
"https://live-qa.ocw.mit.edu/courses/123-ocw-ci-test-course-fall-2022/example_jpg.jpg"
)
})

0 comments on commit 575baa6

Please sign in to comment.