Closed maelle closed 3 years ago
If we decide to do that, the values for navbar and type could be in the pkg object i.e. computed by as_pkgdown()
.
FWIW, sharing experience: I had the same 🤔 when I set the bootswatch key but did not get the primary navbar background as bootswatch gallery. I was expecting bg-primary
I think.
Sounds like this is a good idea. Do you want to implement it @maelle?
it'd go into #1740
Given that there are only ~20 bootswatch themes and they change fairly irregularly, I think we could just use whichever default the preview uses:
library(xml2)
library(purrr)
library(stringr)
themes <- bslib::bootswatch_themes(4)
preview <- paste0("https://bootswatch.com/", themes)
html <- map(preview, read_html)
navbar_class <- function(html) {
html %>%
xml_find_first(".//div[contains(@class, 'navbar')]") %>%
xml_attr("class")
}
classes <- html %>%
map_chr(navbar_class) %>%
str_remove("navbar navbar-expand-lg fixed-top ") %>%
str_split(" ")
print(tibble::tibble(
theme = themes,
navbar = classes %>% map_chr(1) %>% str_remove("navbar-"),
bg = classes %>% map_chr(2) %>% str_remove("bg-"),
), n = Inf)
#> # A tibble: 21 × 3
#> theme navbar bg
#> <chr> <chr> <chr>
#> 1 cerulean dark primary
#> 2 cosmo dark primary
#> 3 cyborg dark dark
#> 4 darkly dark primary
#> 5 flatly dark primary
#> 6 journal light light
#> 7 litera light light
#> 8 lumen light light
#> 9 lux light light
#> 10 materia dark primary
#> 11 minty dark primary
#> 12 pulse dark primary
#> 13 sandstone dark primary
#> 14 simplex light light
#> 15 sketchy light light
#> 16 slate dark primary
#> 17 solar dark dark
#> 18 spacelab light light
#> 19 superhero dark dark
#> 20 united dark primary
#> 21 yeti dark primary
Created on 2021-10-13 by the reprex package (v2.0.1)
Hmmm, can simplify a bit because it's straight forward to guess the type
from the bg
:
# A tibble: 3 × 3
bg type n
<chr> <chr> <int>
1 dark dark 3
2 light light 7
3 primary dark 11
So we just need to store the default bg
:
library(xml2)
library(purrr)
library(stringr)
themes <- bslib::bootswatch_themes(4)
preview <- paste0("https://bootswatch.com/", themes)
html <- map(preview, read_html)
navbar_class <- function(html) {
html %>%
xml_find_first(".//div[contains(@class, 'navbar')]") %>%
xml_attr("class")
}
classes <- html %>%
map_chr(navbar_class) %>%
str_remove("navbar navbar-expand-lg fixed-top ") %>%
str_split(" ")
df <- tibble::tibble(
theme = themes,
type = classes %>% map_chr(1) %>% str_remove("navbar-"),
bg = classes %>% map_chr(2) %>% str_remove("bg-"),
)
df %>% dplyr::count(bg, type)
#> # A tibble: 3 × 3
#> bg type n
#> <chr> <chr> <int>
#> 1 dark dark 3
#> 2 light light 7
#> 3 primary dark 11
dput(setNames(df$bg, df$theme))
#> c(cerulean = "primary", cosmo = "primary", cyborg = "dark", darkly = "primary",
#> flatly = "primary", journal = "light", litera = "light", lumen = "light",
#> lux = "light", materia = "primary", minty = "primary", pulse = "primary",
#> sandstone = "primary", simplex = "light", sketchy = "light",
#> slate = "primary", solar = "dark", spacelab = "light", superhero = "dark",
#> united = "primary", yeti = "primary")
Created on 2021-10-14 by the reprex package (v2.0.1)
Very nice :sparkles:
I am wondering whether the default value for the navbar bg and type should be respectively dark and primary when using Bootswatch themes, which would directly make the website look more like what's in the Bootswatch gallery.
What do you think @apreshill?
Question inspired by #1749