Skip to content

Commit

Permalink
Allowing sharing on whatsapp (#1125)
Browse files Browse the repository at this point in the history
Co-authored-by: christophe dervieux <christophe.dervieux@gmail.com>
  • Loading branch information
prdm0 and cderv committed Apr 8, 2021
1 parent a5ac5f8 commit 6854e02
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
@@ -1,7 +1,7 @@
Package: bookdown
Type: Package
Title: Authoring Books and Technical Documents with R Markdown
Version: 0.21.9
Version: 0.21.10
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),
person("JJ", "Allaire", role = "ctb"),
Expand Down Expand Up @@ -40,6 +40,7 @@ Authors@R: c(
person("Nathan", "Werth", role = "ctb"),
person("Noam", "Ross", role = "ctb"),
person("Peter", "Hickey", role = "ctb"),
person("Pedro Rafael D.", "Marinho", role="ctb", comment = c(ORCID = "0000-0003-1591-8300")),
person("Romain", "Lesur", role = "ctb", comment = c(ORCID = "0000-0002-0721-5595")),
person("Sahir", "Bhatnagar", role = "ctb"),
person("Shir", "Dekel", role = "ctb", comment = c(ORCID = "0000-0003-1773-2446")),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -12,6 +12,8 @@

- Using the 'Knit' button now also works with a Rmd file in a sub-directory of the book project (when `rmd_subdir` is used in `_bookdown.yml`) (#1122)

- WhatsApp sharing feature has been added for `gitbook()` using `sharing` key in `config`. This enables sharing the bookdown URL in Whatsapp on Mobile and on Desktop (thanks, @prdm0, #1125).

## BUG FIXES

- Adapt CSS in `gitbook()` and `html_book()` for correct diplaying of `<details><summary>` content (thanks, @maelle, #971)
Expand Down
1 change: 1 addition & 0 deletions R/gitbook.R
Expand Up @@ -232,6 +232,7 @@ gitbook_config = function(config = list()) {
sharing = list(
github = FALSE, facebook = TRUE, twitter = TRUE,
linkedin = FALSE, weibo = FALSE, instapaper = FALSE, vk = FALSE,
whatsapp = FALSE,
all = c('facebook', 'twitter', 'linkedin', 'weibo', 'instapaper')
),
fontsettings = list(theme = 'white', family = 'sans', size = 2),
Expand Down
1 change: 1 addition & 0 deletions inst/examples/03-formats.Rmd
Expand Up @@ -109,6 +109,7 @@ bookdown::gitbook:
weibo: no
instapaper: no
vk: no
whatsapp: no
all: ['facebook', 'twitter', 'linkedin', 'weibo', 'instapaper']
info: yes
```
Expand Down
3 changes: 3 additions & 0 deletions inst/resources/gitbook/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions inst/resources/gitbook/js/plugin-sharing.js
Expand Up @@ -57,10 +57,21 @@ gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
e.preventDefault();
window.open("http://vkontakte.ru/share.php?url="+encodeURIComponent(location.href));
}
}
},
'whatsapp': {
'label': 'Whatsapp',
'icon': 'fa fa-whatsapp',
'onClick': function(e) {
e.preventDefault();
var url = encodeURIComponent(location.href);
window.open((isMobile() ? "whatsapp://send" : "https://web.whatsapp.com/send") + "?text=" + url);
}
},
};


function isMobile() {
return !!navigator.maxTouchPoints;
}

gitbook.events.bind("start", function(e, config) {
var opts = config.sharing;
Expand Down
1 change: 1 addition & 0 deletions man/bookdown-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6854e02

Please sign in to comment.