Rmarkdown html site - possible to auto generate new pages from a template.Rmd file?

I have a Rmd website with the following files:

  • index.Rmd
  • blah.Rmd
  • blah2.Rmd
  • _site.yml

When I run rmarkdown::render_site() a new website is created in _site.

I would like to automate the creation of new pages to the site. Here is the contents of each of the files above:

index.Rmd:

---
title: "blah"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
\```

## R Markdown

[My home page here]

blah.Rmd:

---
title: "blah"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
\```

## The time Is

This page was generated at `r Sys.time()`

blah2.Rmd is the exact same as blah.Rmd.

_site.yml is:

name: "my-website"
navbar:
  title: "My Website"
  left:
    - text: "Home"
      href: index.html
    - text: "blah"
      href: blah.html
    - text: "blah2"
      href: blah2.html

I would like to copy blah.Rmd, call it template.Rmd and run it e.g. every hour. template.Rmd:

---
title: "blah"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
\```

## The time Is

This page was generated at `r Sys.time()`

I wouldlike to run this new file, template.Rmd every hour and when run, to update the _site.yml with a link to the newly created page. E.g.

name: "my-website"
navbar:
  title: "My Website"
  left:
    - text: "Home"
      href: index.html
    - text: "blah"
      href: blah.html
    - text: "blah2"
      href: blah2.html
    - text: "2020-11-09 17:53:54 UTC"
      href: `2020-11-09 17:53:54 UTC`.html # won't work in this format I guess.

If I was to create the entire site right now, each page, blah and blah2 would say the exact same time. But what I want is the following:

  • Every hour template.Rmd is run and generates a new page to be added to the site. The page name should be Sys.time() or similar.

  • The content of the page, per the example in blah.Rmd is the time that the page was generated.

  • Even though the Rmd file is called template.Rmd, the newly generated page, done each hour, is not called template.html but the timestamp of whent he page was generated.

Is what I am asking possible? Or is there a better approach? Basically I'm trying to build an Rmd site with the ability to append new pages over time without having to regenerate the entire site each time?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.