# To run to update the examples

library(dplyr)
library(purrr)
library(rvest)

# list of sites
blogs <- tribble(
  ~ site, ~ source, 
  "https://metadocencia.netlify.app/", "https://github.com/MetaDocencia/SitioWeb",
  "https://mariadermit.netlify.app/", "https://github.com/demar01/mariadermit",
  "https://shinydevseries.com/", "https://github.com/shinydevseries/shinydevseries_site",
  "https://r-podcast.org/", "https://github.com/rbind/r-podcast",
  "https://isabella-b.com/", "https://github.com/isabellabenabaye/isabella-b.com",
  # "https://robjhyndman.com/", "https://github.com/rbind/robjhyndman.com",
  "https://www.tidymodels.org/", "https://github.com/tidymodels/tidymodels.org",
  "https://livefreeordichotomize.com/", "https://github.com/LFOD/real-blog",
  "https://hugo-apero-docs.netlify.app/", "https://github.com/hugo-apero/hugo-apero-docs",
  "https://prose.yihui.org/",  "https://github.com/yihui/hugo-prose/tree/master/exampleSite"
)

# get the title
blogs <- blogs %>% 
  mutate(
    title = map_chr(site, ~{
      read_html(.x) %>%
        html_node("title") %>%
        html_text()
    }), 
    title = stringr::str_trim(title)
) 

# takes screenshot
blogs <- blogs %>%
  mutate(
    img = xfun::with_ext(
      paste("images", urltools::domain(blogs$site), sep = "/"), "png")
  )

# export to YAML
blogs %>%
  rename(href = "site") %>%
  mutate(showcase = TRUE) %>%
  purrr::pmap(purrr::lift_ld(as.list)) %>%
  yaml::write_yaml("examples.yml")
# we use as few new dependencies as possible 
blogs <- rmarkdown:::yaml_load_file("examples.yml")
blogs <- do.call(rbind, lapply(blogs, function(x) data.frame(site = x$href, img = x$img)))
# remotes::install_github("rstudio/webshot2")
img_exists <- file.exists(blogs$img)
if (any(!img_exists)) {
  need_screenshot <- blogs[!img_exists, ]
  purrr::pwalk(need_screenshot, function(site, img) {
    message("Screenshoting ", site)
    res <- webshot2::webshot(site, img, cliprect = "viewport")
    # optimize image - require optipng
    webshot2::shrink(res)
  })
}

The examples below illustrate the use of blogdown for making websites and blogs. You can also find a list of examples at https://awesome-blogdown.com/

quillt::examples(yml = "examples.yml")


rstudio/blogdown documentation built on Feb. 5, 2024, 10:09 p.m.