Skip to content

Commit d484500

Browse files
authored
feat: prep for pkgdown new version (#110)
* feat: prep for pkgdown light switch * fix dark background * refactor: use pkgdown's math rendering option instead of custom head.html * ci: use dev pkgdown @jeroen
1 parent fdbec4d commit d484500

File tree

8 files changed

+45
-125
lines changed

8 files changed

+45
-125
lines changed

DESCRIPTION

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ Imports:
3434
curl,
3535
jsonlite,
3636
memoise,
37-
pkgdown (>= 2.0.1),
37+
pkgdown (>= 2.0.9.9000),
3838
purrr,
3939
servr,
4040
yaml,
4141
xml2,
4242
commonmark
4343
Roxygen: list(markdown = TRUE)
4444
Config/testthat/edition: 3
45+
Remotes:
46+
r-lib/pkgdown

R/build-site.R

+29-12
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ build_ropensci_docs <- function(path = ".", destination = NULL, install = FALSE,
5151

5252
#NB: pkgdown uses utils::modifyList() to merge _pkgdown.yml values with overrides.
5353
#This will recursively merge lists, and delete values that are 'NULL' in overrides.
54+
55+
5456
override <- list(
5557
template = list(
5658
package = "rotemplate",
5759
bootstrap = 5,
58-
params = list(mathjax = need_mathjax(path), bootswatch = NULL),
60+
params = list(bootswatch = NULL),
5961
path = NULL,
6062
bootswatch = NULL
6163
),
@@ -66,6 +68,11 @@ build_ropensci_docs <- function(path = ".", destination = NULL, install = FALSE,
6668
destination = destination
6769
)
6870

71+
math_config <- get_math_rendering(path)
72+
if (!is.null(math_config)) {
73+
override$template$`math-rendering` <- math_config
74+
}
75+
6976
find_and_fix_readme(path, pkgname)
7077

7178
# Prevent favicon building
@@ -98,18 +105,28 @@ build_ropensci_docs <- function(path = ".", destination = NULL, install = FALSE,
98105
invisible(pkg$dst_path)
99106
}
100107

101-
need_mathjax <- function(path){
108+
# we need this to keep supporting the old syntax we had set up
109+
# TODO: PR to packages using it so we can remove those lines!
110+
get_math_rendering <- function(path){
111+
102112
pkgdown_yml <- pkgdown_config_path(path = path)
103-
isTRUE(try({
104-
if(!is.null(pkgdown_yml)){
105-
pkgdown_config <- yaml::read_yaml(pkgdown_yml)
106-
if(isTRUE(pkgdown_config$mathjax) || isTRUE(pkgdown_config$template$params$mathjax)){
107-
message("Site needs mathjax library")
108-
return(TRUE)
109-
}
110-
}
111-
message("Site does not need mathjax")
112-
}))
113+
pkgdown_config <- yaml::read_yaml(pkgdown_yml)
114+
115+
if (is.null(pkgdown_config)) {
116+
return(NULL)
117+
}
118+
119+
math_rendering <- pkgdown_config$template$`math-rendering`
120+
if (!is.null(math_rendering)) {
121+
return(math_rendering)
122+
}
123+
124+
if(isTRUE(pkgdown_config$mathjax) || isTRUE(pkgdown_config$template$params$mathjax)){
125+
return("mathjax")
126+
}
127+
128+
return(NULL)
129+
113130
}
114131

115132
find_and_fix_readme <- function(path, pkg){

README.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,10 @@ If your website is not deploying or you run into another problem, please
2828
open an issue in the [ropensci/docs](https://github.com/ropensci/docs)
2929
repository.
3030

31-
### Mathjax
31+
### Math rendering
3232

33-
if you want to use Mathjax you’ll need to specify it in the `pkgdown`
34-
config file like so:
33+
Please refer to [pkgdown documentation](https://pkgdown.r-lib.org/dev/articles/customise.html#math-rendering).
3534

36-
``` yaml
37-
template:
38-
params:
39-
mathjax: true
40-
```
4135

4236
## Example sites
4337

_pkgdown.yml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ url: https://docs.ropensci.org/rotemplate
22

33
template:
44
package: rotemplate
5+
light-switch: true
56

67
destination: docs
78

inst/pkgdown/_pkgdown.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
template:
22
includes:
3+
in_header: |
4+
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.css" />
5+
<script src="https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.js" data-cfasync="false"></script>
6+
<script src="https://ropensci.org/scripts/matomo.js"></script>
7+
<noscript><p><img src="https://ropensci.matomo.cloud/matomo.php?idsite=1&amp;rec=1" style="border:0;" alt="" /></p></noscript>
38
before_title: '<a href="https://ropensci.org"><img src="https://ropensci.org/img/icon_short_white.svg" id="hexlogo" alt="rOpenSci"></a>'
49
bootstrap: 5
510
bslib:
611
bg: "white"
12+
body-bg-dark: "#212529"
713
fg: "#283140"
814
primary: "#1b6ada"
915
dropdown-link-hover-bg: "#64a4ef"
1016
dropdown-link-hover-color: "white"
1117
dropdown-link-active-color: "white"
12-
headings-color: "#5c677e"
18+
headings-color-light: "#484f5e"
1319
navbar-brand-font-size: "2rem"
1420
navbar-light-color: "white"
1521
navbar-light-brand-color: "white"
@@ -23,7 +29,7 @@ template:
2329
navbar:
2430
structure:
2531
left:
26-
right: [search, intro, reference, articles, tutorials, news, github]
32+
right: [search, intro, reference, articles, tutorials, news, github, lightswitch]
2733

2834

2935
authors:

inst/pkgdown/extra.scss

-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ main h1 img {
202202
/* Because ProximaNova is very thin by default */
203203
h1, h2, h3, h4, h5, h6 {
204204
font-weight: 700;
205-
color: #484f5e;
206205
code {
207206
font-weight: 500;
208207
}

inst/pkgdown/templates/head.html

-99
This file was deleted.

tests/testthat/test-mathjax.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test_that("adding mathjax works", {
2121
)
2222
})
2323
homepage <- xml2::read_html(file.path(docs, "index.html"), encoding = "UTF-8")
24-
script <- xml2::xml_find_first(homepage, ".//head/script[@id='MathJax-script']")
24+
script <- xml2::xml_find_first(homepage, ".//script[contains(@src,'MathJax')]")
2525
# If not present the class is xml_missing
2626
testthat::expect_s3_class(script, "xml_node")
2727
})
@@ -46,6 +46,6 @@ test_that("NOT adding mathjax works", {
4646
)
4747
})
4848
homepage <- xml2::read_html(file.path(docs, "index.html"), encoding = "UTF-8")
49-
script <- xml2::xml_find_first(homepage, ".//head/script[@id='MathJax-script']")
49+
script <- xml2::xml_find_first(homepage, ".//script[contains(@src,'MathJax')]")
5050
testthat::expect_s3_class(script, "xml_missing")
5151
})

0 commit comments

Comments
 (0)