class: center, middle, inverse, title-slide .title[ # Creating a blog (or website) with blogdown that will not be down ] .author[ ###
Yihui Xie
, RStudio PBC ] .date[ ### 2022/06/22 @ useR! conference 2022 ] --- ## Prerequisites For this talk, I assume that you - have installed the [**blogdown**](https://github.com/rstudio/blogdown) package in R - know what [R Markdown](https://rmarkdown.rstudio.com) is - optional but recommended: - have installed [RStudio](https://www.rstudio.com) - have a [Github](https://github.com) account and a [Netlify](https://netlify.com) account - have [installed](https://happygitwithr.com/install-git.html) and [configured](https://happygitwithr.com/https-pat.html) Git so that you are able to push to Github --- class: inverse, center, middle # Creating a site --- ## Creating websites with blogdown - I will demonstrate three themes: [yihui/hugo-xmin](https://github.com/yihui/hugo-xmin) (minimal/simple), [yihui/hugo-prose](https://github.com/yihui/hugo-prose) (intermediate), [hugo-apero/hugo-apero](https://github.com/hugo-apero/hugo-apero) (sophisticated) - RStudio: File -> New Project -> New Directory -> Website using blogdown - If you do not use RStudio, the equivalent way is `blogdown::new_site()`, e.g., ```r blogdown::new_site(theme = "yihui/hugo-xmin") ``` --- ## Preview a site - Use the RStudio addin "Serve Site". - Or equivalently, call `blogdown::serve_site()` in R. - Normally you only need to serve a site once in an R session. When in doubt, quit R/RStudio and serve the site again. --- ## Add new content - Use the RStudio addin "New Post". - Or equivalently, call `blogdown::new_post()` in R. - [`.Rmd`, `.Rmarkdown`, or `.md`?](https://bookdown.org/yihui/blogdown/output-format.html) --- ## Other themes - There are hundreds of other themes that you may use. - https://bookdown.org/yihui/blogdown/other-themes.html --- class: inverse, center, middle # Deploy a site --- ## The quick and simple method - Sign in Netlify ([app.netlify.com](https://app.netlify.com)). - Run `blogdown::build_site()` in R. - Drag and drop the `public/` folder to Netlify. - Change the random domain to a more meaningful one. - You have got a personal website! - Disadvantage: you will have to repeat this again and again if you need to update the site. - I recommend the next method (i.e., using Git and Github). --- ## The advanced method - It can be harder to set up, but you only need to set up once. - Once you have properly configured Git and are able to push to Github, the site deploy will be automatic. Then you can focus on the site content (Rmd or Markdown files). --- ## Git/Github - [Authentication](https://happygitwithr.com/https-pat.html) (if you haven't done it before) ```r # install usethis if necessary xfun::pkg_load2('usethis') usethis::create_github_token() gitcreds::gitcreds_set() ``` - Initialize a Git repository locally, and push to Github ```r usethis::use_git() # Restart RStudio after initialization usethis::use_github() # Create a Github repo ``` --- ## Netlify - Sign in Netlify ([app.netlify.com](https://app.netlify.com)). - Create a site there from the Git repo. - Change the random domain to a more meaningful one. - You have got a personal website! --- class: inverse, center, middle # Troubleshoot a site --- ## When in doubt, check your site - [Run `blogdown::check_site()`](https://bookdown.org/yihui/blogdown/a-quick-example.html#when-in-doubt-run-blogdowncheck_site) and follow the tips (especially the `[TODO]` items). - There are many possible reasons why your site may fail, e.g., plots not showing up, posts working locally but not on Netlify, etc. The `check_site()` function diagnoses all possible known problems and tell you what to do. --- class: center, middle # Questions? RStudio Community (https://community.rstudio.com) or Stack Overflow (https://stackoverflow.com) ## Thank you! ### Slides: [slides.yihui.org/2022-useR-blogdown.html](https://slides.yihui.org/2022-useR-blogdown.html) ### Video: [vimeo.com/722781853](https://vimeo.com/722781853)