Skip to content

Conversation

@maelle
Copy link
Contributor

@maelle maelle commented Dec 1, 2020

Fix #1080

same lines as in gitbook

@cderv cderv linked an issue Mar 31, 2021 that may be closed by this pull request
@apreshill apreshill added this to the v0.23 milestone May 29, 2021
@maelle
Copy link
Contributor Author

maelle commented Jun 10, 2021

bs4_book_page() knows html_cur and rmd_cur, so YAML could be used inside each Rmd 😸

@maelle
Copy link
Contributor Author

maelle commented Jun 10, 2021

not that helpful though

@maelle
Copy link
Contributor Author

maelle commented Jun 10, 2021

I am hoping is finding a way to add the current Rmd as a comment / special div, and then use that when tweaking to go read YAML in the original Rmd file...

@maelle
Copy link
Contributor Author

maelle commented Jun 10, 2021

each H1 would need some sort of Rmd info attached to them as data attribute 🤔

@maelle
Copy link
Contributor Author

maelle commented Jun 10, 2021

Compromise I'll implement next week (after discussion with @cderv) if ok with you @apreshill

  • cover-image used for all pages.
  • I'll check whether og:url is useless, otherwise build it from the main url & path.
  • title will be set to the first H1 + maybe with the book title.
  • description will be the truncated content.

So the idea would be to have no customization via YAML as it seemed complex. 🤔

@apreshill
Copy link
Contributor

apreshill commented Jun 10, 2021

Hi- this sounds very good to me, and I agree with not adding any per-chapter YAMLs since that it so ingrained into bookdown. I like the Description idea- reminds me of Hugo's auto summary variable (https://gohugo.io/content-management/summaries/#automatic-summary-splitting).

@maelle
Copy link
Contributor Author

maelle commented Jun 10, 2021

reminds me of Hugo's auto summary variable (gohugo.io/content-management/summaries/#automatic-summary-splitting).

guess where I got the idea from 😜

@maelle
Copy link
Contributor Author

maelle commented Jun 10, 2021

@cderv
Copy link
Collaborator

cderv commented Jun 10, 2021

Overall, I think we need to understand better how opengraph is really generated to be sure to set the correct value. Some comment on the above.

cover-image used for all pages.

👍

I'll check whether og:url is useless, otherwise build it from the main url & path.

I think it will be set to the url of the page by default in most case. Some OG simulator for twitter and facebook do for example. but it seems mandatory (better practice) in the resource I read. This could be possible to set / modify when splitting happen in bookdown.

title will be set to the first H1 + maybe with the book title.

<title> is already set. The same value is used already when splitting chapter (see prepend_chapter_title() used in split_chapter()

description will be the truncated content.

It may be important that description can be set globally too. Like in gitbook() in description yaml field in index.Rmd - it is possible that some user would prefer to have the same description for the book as a whole even if some chapter are shared with a specific url. Books are special website and I think it make sense to still have this possibility. If unset, then if we manage to get a content automatically from a page, then we can use that. But it may not be a good description content for some pages and worse than having no description (just image, title and link) sometimes.

With @maelle we also discussed the possibility of setting information for each html file in some way, but it is hard with the current design which merge then split, and not header in YAML file except index.Rmd. bs4_book() could be easier as 1 Rmd = 1 file but it is not the case for gitbook().

@maelle
Copy link
Contributor Author

maelle commented Jun 10, 2021

Maybe another parameter is needed (but in which file 🙃 ) to choose whether the general description should apply to all pages or just the index.html 🤔

@maelle
Copy link
Contributor Author

maelle commented Jun 14, 2021

Maybe another parameter is needed (but in which file upside_down_face ) to choose whether the general description should apply to all pages or just the index.html thinking

@cderv do you disagree with this? At the moment my PR doesn't let one use the same description for all pages.

Copy link
Collaborator

@cderv cderv left a comment

Choose a reason for hiding this comment

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

I think tweaking the og:url is great - bs4_book() allows this easily. We may need to it as the split stage though to tweak also gitbook() format.

For description, I am still wondering what to do. It feels weird to have a description per page that is just a few word of the page content. Is this something usual ? I guess it is done this way for web auto-generated content. Will it be clearer description than a single manual description for the whole book ? It could if it is clearly documented that the 197 first words will be used.

@apreshill what is your thoughts on that ?

BTW bs4_book() does not have description meta (for Google SEO: https://developers.google.com/search/docs/advanced/appearance/good-titles-snippets#meta-descriptions) :

<meta name="description" content="$if(description)$$description$$else$$title$$endif$" />
<meta name="generator" content="bookdown #bookdown:version# and GitBook 2.6.7" />

Maybe this should be added ? Related to #1080 probably

It seems highly optional though: https://github.com/joshbuchea/HEAD#meta
BTW this resource about <head> is great !

I have thought about the description per page feature. bookdown is not designed to have YAML field per page so I don't want to introduce that right now. Also we know we can easily add content to header from within a R chunk. metathis works this way but it needs to be 1 Rmd = 1 HTML without merging. Currently a meta set in a Rmd will be put inside all HTML files (as pandoc convert 1 md to 1 HTML before bookdown splits it).

So I don't have a great solution in mind for now about how a user could set a specific description per page.

@maelle
Copy link
Contributor Author

maelle commented Jun 25, 2021

Hi @maelle - if I'm following this right, the twitter description won't update per chapter, but the og will be per chapter? I've mainly seen those match - is there a reason to not have per chapter twitter descriptions?

@apreshill No, I had missed it! Thanks for catching this! Now I am wondering whether the Twitter and OG descriptions should have different lengths, maybe simpler to keep them the same for now?

Copy link
Collaborator

@cderv cderv left a comment

Choose a reason for hiding this comment

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

The logic is now quite clear

  • og:description, twitter:description and general description will be the same on each pages
  • If description YAML field is set, it will be used for index.html. If not, a simple default one will be added, with a message to user to add one.
  • For other pages, the content will be auto generated and replaced.

For other meta,

  • og:url will be adapted on each page
  • generator meta will be set to indicate bookdown
  • Other social meta will be set the same for the all pages

There are small fix left. And this is good to go !

cc @apreshill if you want to check this again.

maelle and others added 8 commits June 25, 2021 13:24
Copy link
Collaborator

@cderv cderv left a comment

Choose a reason for hiding this comment

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

Thanks for the changes. I think we are good now. We have found all the potential fix.

I just need to test on an example deployment, to see how it looks like on a social card simulator.

@apreshill is this good for you ? See previous comment for the current behavior #1034 (review)

Waiting for you final review before last comestic tweaks and merging.

@cderv cderv requested a review from apreshill June 25, 2021 12:24
@apreshill
Copy link
Contributor

Will do this afternoon. In the meantime, here was my testing repo in case it is helpful: https://github.com/apreshill/bs4booktesting

@cderv
Copy link
Collaborator

cderv commented Jun 30, 2021

Tested with https://github.com/cderv/bs4booktesting, a fork of yours as I don't have access. Published here: https://cderv.github.io/bs4booktesting/

This looks good now I believe

I also checked that Zotero connector is working now (fix #1080)

We are all set and ready to merge. ok for you @apreshill ?

Copy link
Contributor

@apreshill apreshill left a comment

Choose a reason for hiding this comment

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

This works excellent for me 🎉

@cderv cderv changed the title OG/twitter metadata in bs4_book bs4_book: add OG/twitter metadata Jun 30, 2021
@cderv cderv merged commit 3c4eca3 into rstudio:master Jun 30, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing metadata in published bs4_book Fix sharing images/meta tags generated by pandoc for bs4_book

4 participants