rstudio / pkgs.rstudio.com

https://pkgs.rstudio.com
1 stars 1 forks source link

Get the logo from OG meta in the head ? #5

Closed cderv closed 3 years ago

cderv commented 3 years ago

There is currently a logo not showing for blogdown because the logo is not in the package but in the blogdown book (see https://github.com/rstudio/blogdown/commit/00a7cdfb3af20af0f0213716216dead97b761007)

Should we assume that the logo is in the package and available through the pkgdown website ? Oddly, pkgdown makes it available in several places <destdir>/logo.png AND <destdir>/references/figures/logo.png when it is in the package man/figures/logo.png.

We would also set that for pkgs.rstudio.com, the logo informatio should be in the OG meta - all quillt related website should have

template:
  package: quillt
  opengraph:
    image:
      src: man/figures/logo.png
      alt: "bookdown package"
    twitter:
      creator: "@rstudio"
      card: summary

So we could query the OG meta to retrieve the URL of the logo to use in pkgs.rstudio.com homepage.

url <- "https://pkgs.rstudio.com"
packages <- c("bookdown", "blogdown")

get_logo_src <- function(package, url) {
  html <- xml2::read_html(file.path(url, package))
  img_node <- rvest::html_node(html, "meta[property='og:image']")
  rvest::html_attr(img_node, "content")
}

lapply(packages, get_logo_src, url = url)
#> [[1]]
#> [1] "https://pkgs.rstudio.com/bookdown/reference/figures/logo.png"
#> 
#> [[2]]
#> [1] "https://bookdown.org/yihui/blogdown/images/logo.png"

Created on 2021-03-02 by the reprex package (v1.0.0.9002)

The latter would allow flexibility for package maintainer that would just need to add the OG meta in their pkgdown website.

Happy to discuss the best way, and document it in quillt

cc @yihui

cderv commented 3 years ago

As we already did that for title, I decided to also did it for the logo. By default pkgdown will set the og meta image to the pkgdown logo location, so that will work even if opengraphis not customized in _pkgdown.yml