Chapter 10 Tips and tricks

This chapter reinforces some basic tips and tricks for you to consider while developing your website.

10.1 Serve your website locally

The blogdown package includes a handy function called serve_site(). Running this function in the R console with your website’s RStudio Project loaded will render a local copy of your entire website in the RStudio “Viewer” pane. Image

While serving your website locally, the local version will update in real-time as you make and save changes to your website’s codebase. This feature of blogdown, known as LiveReload, lets you experiment with changes to your website and receive instant feedback.

10.2 Push updates to GitHub

Any time you make changes to your website, such as integrating Google Analytics or authoring a new post, you will need to push these changes to your GitHub repository to force Netlify to rebuild and redeploy your website to the internet.

Assuming you have already pushed your website to GitHub, use the add > commit > push Git workflow to push updates. I recommend pushing updates frequently to keep your GitHub repository up-to-date.

# add all files to the local Git repository
git add --all

# commit files and include a brief message
git commit -m "brief message describing your changes"

# push files to GitHub
git push origin master

10.3 Check your website

At any point during the development of your website, consider running blogdown::check_site() in the R console. This function will run a number of checks against your website to discover any problems.

10.4 Rebuild a clean website

While developing your website, you should be serving your website locally to observe the effects of your edits in real-time. Sometimes, for a number of reasons, the local rendering of your website ceases to reflect your edits. If this or any other issue surfaces, I recommend running the following R code to rebuild a clean website:

# clean the website generated by blogdown
rmarkdown::clean_site()

# build the website
blogdown::build_site()

# serve the website locally
blogdown::serve_site()

If you continue to experience buggy behavior, try restarting RStudio and running the code again.

10.5 Find free images

If you need images for your website (e.g. post thumbnail), I recommend using free images from Unsplash.