Social media card

I've been trying to add a twitter card to some plain rmarkdown documents that get converted to html files.
On the latest rmarkdow I tried for instance:

title: "My super website"
      src: path/to/my/image.png
      alt: "My super website"

But this didn't work, am I missing something?

I think that this is solved for blogdown via the configuration files (twitterImg: "myimage.png" and similar) as I found several blogs from some years ago mentioning it, but these solutions didn't work for plain rmarkdown websites.
There are also several solutions to add meta tags on files:
headR and metathis.
Perhaps it would be useful if this could be handled at the rmarkdown level.

Which output format are you using ? You yaml does not show.

Here are some general thoughts as I do not have the specific info about the format you are using.

I believe it works for blogdown if the hugo theme used supports it. For HTML document, it would need to be customized per document depending on the template and theme used.

Best solution is to use metathis :package: that works well for several format for this cross format feature that is social media cart. Does it work for you ? It seems a simple solution to add a chunk at the beginning of the document with this informations don't you think ? IMO as simple as providing in the yaml header, and easier to maintain technically to be usable easily across several format.

Note that if you are using this with the same output (don't know which) and you do that often, you could create your own template to pass to the format function and knowing where to insert the variable you are passing in the YAML header.

Hope it helps

As mentioned this is not for a blogdown site, I am using html_document output with the default theme.

The problem with both metathis and using include: in_header: my_header.htmlis that both are static and don't use the information I write on the YAML header for each website, so I need to write that again. I would like to avoid, because it doesn't extend well when multiple webpages are created.

I am not sure to follow this

Are you not including in each file the yaml header content ? How are you using a common yaml header for multiple Rmd ? Are you talking about Rmarkdown website ?

About sharing some piece of content :
Note that with Rmd file, you can easily reuse content in several document by using Child document:

For R code only, you could also store the code in a file and use it in several document either by sourcing it in a chunk or by using the code chunk option:

This are two tricks to think about when you need to reuse some content exactly the same in several documents to avoid copy paste.

Thanks Christophe. To be clear, I'm talking about this repository.

Setting the yaml header on the _site.yml is correctly used by multiple Rmd. I've been talking about Rmarkdown website all the time.
This solution (setting a fixed header on _site.yml) doesn't use the information of each webpage (it cannot use the title and description I set for each webpage, just the general one provided). Precisely what I want to avoid is reusing the same content. I want the header/twitter card to be tailored for each individual web page, but following the same template as it does on blogdown.

For comparison if I set the title and description on post on blogdown like this one or that one, when I check the card validation I get different content. I didn't need to supply any other code than setting that on the yaml information of those post. I wanted to know if this can be done with Rmarkdown websites.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.