pkgdown footer: creation date

I would like to get the site creation datetime in the footer of my pkgdown output. As an example, I have hard-coded this to show what I hope to have done automatically:

This hard-coded example was done with this _pkgdown.yml:

> url: ~
> template:
>   bootstrap: 5
>   theme: breeze-light
>   # path: "inst/pkgdown"
> footer:
>   structure:
>     left: developed_by
>     right: [built_with, built_date]
>   components:
>     built_date: "<br>Created: 2023-09-10 12:35 UTC"

I have not found anything already available, such as developed_by and built_with, that I can use.
I see that docs/pkgdown.yml contains last_built; is there some way I can use that?:

pandoc: 3.1.1
pkgdown: 2.0.7
pkgdown_sha: ~
articles:
  ericstrava: ericstrava.html
last_built: 2023-09-10T17:08Z

I had some success making use of javascript in a custom inst/pkgdown/footer.html , but it is additional complexity I would like to avoid. And I was only having success when using build_home(); I was getting errors with build_site().

Any guidance would be appreciated.

I suggest you tag this post with the pkgdown tag , to increase the chance that people interested in pkgdown will see it.

Tagged. Thank for letting me know!

I don't think that pkgdown supports this directly, but the yaml parser does, if you set the option:

options(yaml.eval.expr = TRUE)

Then you can add !expr tags that the yaml parser executes when reading the file:

  components:
    built_date: !expr "format(Sys.time())"
1 Like

@Gabor Many thanks!

I placed the

options(yaml.eval.expr = TRUE)

in the .Rprofile file and changed the _pkgdown.yml file to:

url: ~
template:
  bootstrap: 5
  theme: breeze-light
footer:
  structure:
    left: developed_by
    right: [built_with, built_text, built_date]
  components:
    #built_date: "<br>Created: 2023-09-10 12:35 UTC"
    built_date: !expr "format(Sys.time(), '%Y-%m-%d %H:%M %Z')"
    built_text: "<br>on "

This allows me to build the site locally for development work.

I also changed the .github/workflows/pkgdown.yaml to set the option before creating the pkgdown site:

      - name: Build site
        run: |
          options(yaml.eval.expr=TRUE)
          pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
        shell: Rscript {0}

And now I have an auto-updated date on the pkgdown/gh-pages site every time I push a PR to my main branch:

1 Like

This could be an issue if you are reading a YAML file from an untrusted source, if there is malevolent !expr code in it.

I am not saying that that's very common today, just want to make sure that people are aware of it.

But I don't know if there is a way to set it only for the package that pkgdown is working on.

1 Like

This topic was automatically closed after 45 days. 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.