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

Add Open Graph meta tags #438

merged 10 commits into from Feb 20, 2018


None yet
2 participants
Copy link

nealrichardson commented Oct 31, 2017

The Open Graph protocol and Twitter Card properties provide standards for website/page metadata. One important application of them is in providing previews when sharing links, whether on social media or on services like Slack.

This PR implements some of these meta tags, enough to give a preview of a pkgdown site link like this (on Slack):

screen shot 2017-10-30 at 7 21 04 pm

Specifically, it:

  • adds og:title, og:description, og:image, and twitter:card meta tags to the head.html template;
  • identifies suitable "description" metadata for the package index.html (the "Description" from DESCRIPTION), the reference pages (the function "description"), and the articles/vignettes (if specified in the YAML front matter), and makes it available to the template;
  • ensures that, if a logo.png is present in the package, it is included in the built site, and uses it as the preview image;
  • adds a single test that the template is rendered with the og:description

It's getting the job done for me on sites I've built with it, but it is not what I would consider a complete implementation. It needs documentation, more tests, and it's worth considering what an appropriate "description" should be for some of the other pages (reference index, news, etc.). But before I proceeded with that, I wanted to put this out there, gauge interest, and get design feedback.

Copy link

hadley left a comment

One small style problem, otherwise looks good!

@@ -31,6 +31,7 @@ build_home <- function(pkg = ".", path = "docs", depth = 0L, encoding = "UTF-8")
pkg <- as_pkgdown(pkg)
path <- rel_path(path, pkg$path)
data <- data_home(pkg)
data$opengraph <- list(description=pkg$desc$get("Description")[[1]])

This comment has been minimized.


hadley Oct 31, 2017


Can you please add spaces around =?


This comment has been minimized.

Copy link

nealrichardson commented Nov 6, 2017

Fixed a few =s and added some tests that the templates were being rendered with the right metadata. Incidentally, this increases the package's test (line) coverage from 63% to 78%.

@hadley hadley merged commit f8df34c into r-lib:master Feb 20, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed

This comment has been minimized.

Copy link

hadley commented Feb 20, 2018


@nealrichardson nealrichardson deleted the nealrichardson:open-graph branch Apr 5, 2018

@maelle maelle referenced this pull request Oct 11, 2018


Add OpenGraph metatags #104

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment