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

Add Open Graph meta tags #438

Merged
merged 10 commits into from Feb 20, 2018
Merged

Add Open Graph meta tags #438

merged 10 commits into from Feb 20, 2018

Conversation

nealrichardson
Copy link

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
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small style problem, otherwise looks good!

R/build-home.R Outdated
@@ -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]])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add spaces around =?

@nealrichardson
Copy link
Author

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
@hadley
Copy link
Member

hadley commented Feb 20, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants