TRAVIS-BLOGDOWN

You write (Rmd) posts, and Travis CI does the rest of work

This is an example website on how to use Travis CI to build and deploy your website automatically. The idea can be applied to Github Pages, Amazon S3, and Netlify, etc. For this particular example, I’m using Github Pages.

Below are some R code chunks. First we show the content of .travis.yml:

cat(readLines('../.travis.yml'), sep = '\n')
language: r
dist: xenial
latex: false

branches:
  only:
    - master

cache:
  packages: yes
  directories:
    - $HOME/bin

script:
  - Rscript -e 'blogdown::install_hugo()'
  - Rscript -e 'blogdown::build_site()'

deploy:
  provider: pages
  skip_cleanup: true
  github_token: $GITHUB_TOKEN
  on:
    branch: master
  local_dir: public
  fqdn: travis-blogdown.yihui.name

Then we show the number of lines of each .html and .css file in the hugo-xmin theme:

# find ../themes/hugo-xmin \( -name '*.html' -o -name '*.css' \) | xargs wc -l
files = list.files(
  '../themes/hugo-xmin', '[.](html|css)$', recursive = TRUE, full.names = TRUE
)
lines = lapply(files, function(f) {
  data.frame(n = length(readLines(f)), file = f)
})
lines = do.call(rbind, lines)
lines = rbind(lines, data.frame(n = sum(lines$n), file = 'total'))
knitr::kable(lines)
n file
12 ../themes/hugo-xmin/exampleSite/layouts/partials/foot_custom.html
18 ../themes/hugo-xmin/layouts/_default/list.html
12 ../themes/hugo-xmin/layouts/_default/single.html
16 ../themes/hugo-xmin/layouts/_default/terms.html
5 ../themes/hugo-xmin/layouts/404.html
0 ../themes/hugo-xmin/layouts/partials/foot_custom.html
9 ../themes/hugo-xmin/layouts/partials/footer.html
0 ../themes/hugo-xmin/layouts/partials/head_custom.html
19 ../themes/hugo-xmin/layouts/partials/header.html
7 ../themes/hugo-xmin/static/css/fonts.css
50 ../themes/hugo-xmin/static/css/style.css
148 total