From 763d4cb8e0a8a226007aec276dc3009a031ce4b0 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Sun, 26 May 2024 09:05:30 -0500 Subject: [PATCH] Tidy up open graph metadata in head.html --- R/render.R | 14 ++++++++++---- inst/BS5/templates/head.html | 29 +++++++---------------------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/R/render.R b/R/render.R index d3c07ca69..6185576ff 100644 --- a/R/render.R +++ b/R/render.R @@ -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 = "/") @@ -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 } diff --git a/inst/BS5/templates/head.html b/inst/BS5/templates/head.html index 183609b52..49a070aaa 100644 --- a/inst/BS5/templates/head.html +++ b/inst/BS5/templates/head.html @@ -1,11 +1,6 @@ -{{#opengraph}} -{{#description}} - -{{/description}} -{{/opengraph}} {{{pagetitle}}} • {{#site}}{{title}}{{/site}} {{#has_favicons}} @@ -49,27 +44,17 @@ {{#opengraph}} {{#description}} - + + {{/description}} {{#image}} - -{{#alt}} - -{{/alt}} + + {{#alt}}{{/alt}} {{/image}} {{#twitter}} -{{#card}} - -{{/card}} -{{^card}} - -{{/card}} -{{#creator}} - -{{/creator}} -{{#site}} - -{{/site}} + {{#card}}{{/card}} + {{#creator}}{{/creator}} + {{#site}}{{/site}} {{/twitter}} {{/opengraph}}