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

Tidy up open graph metadata in head.html #2586

Merged
merged 1 commit into from
May 30, 2024
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
14 changes: 10 additions & 4 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ data_open_graph <- function(pkg = ".", call = caller_env()) {
pkg <- as_pkgdown(pkg)
og <- config_pluck_list(pkg, "template.opengraph", default = list())
og <- check_open_graph(og, pkgdown_config_path(pkg) %||% "_pkgdown.yml", call = call)
if (is.null(og$image) && !is.null(find_logo(pkg$src_path))) {
og$image <- list(src = path_file(find_logo(pkg$src_path)))

logo <- find_logo(pkg$src_path)
if (is.null(og$image) && !is.null(logo)) {
og$image <- list(src = path_file(logo))
}
if (!is.null(og$image) && !grepl("^http", og$image$src)) {
site_url <- config_pluck(pkg, "url", default = "/")
Expand All @@ -148,8 +150,12 @@ data_open_graph <- function(pkg = ".", call = caller_env()) {
og$image$src <- paste0(site_url, og$image$src)
}

og$twitter$creator <- og$twitter$creator %||% og$twitter$site
og$twitter$site <- og$twitter$site %||% og$twitter$creator
if (!is.null(og$twitter)) {
og$twitter$card <- og$twitter$card %||% "summary"
og$twitter$creator <- og$twitter$creator %||% og$twitter$site
og$twitter$site <- og$twitter$site %||% og$twitter$creator
}

og
}

Expand Down
29 changes: 7 additions & 22 deletions inst/BS5/templates/head.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
{{#opengraph}}
{{#description}}
<meta name="description" content="{{.}}" />
{{/description}}
{{/opengraph}}
<title>{{{pagetitle}}} • {{#site}}{{title}}{{/site}}</title>

{{#has_favicons}}
Expand Down Expand Up @@ -49,27 +44,17 @@
<meta property="og:title" content="{{{pagetitle}}}" />
{{#opengraph}}
{{#description}}
<meta property="og:description" content="{{.}}" />
<meta name="description" content="{{.}}" />
<meta property="og:description" content="{{.}}" />
{{/description}}
{{#image}}
<meta property="og:image" content="{{{src}}}" />
{{#alt}}
<meta property="og:image:alt" content="{{{.}}}" />
{{/alt}}
<meta property="og:image" content="{{{src}}}" />
{{#alt}}<meta property="og:image:alt" content="{{{.}}}" />{{/alt}}
{{/image}}
{{#twitter}}
{{#card}}
<meta name="twitter:card" content="{{{.}}}" />
{{/card}}
{{^card}}
<meta name="twitter:card" content="summary" />
{{/card}}
{{#creator}}
<meta name="twitter:creator" content="{{{.}}}" />
{{/creator}}
{{#site}}
<meta name="twitter:site" content="{{{.}}}" />
{{/site}}
{{#card}}<meta name="twitter:card" content="{{{.}}}" />{{/card}}
{{#creator}}<meta name="twitter:creator" content="{{{.}}}" />{{/creator}}
{{#site}}<meta name="twitter:site" content="{{{.}}}" />{{/site}}
{{/twitter}}
{{/opengraph}}

Expand Down
Loading