# TO USE THIS ARTICLE, THE DESCRIPTION FILE MUST INCLUDE
# Config/Needs/website: gert
# Make sure to copy the gh-pages branch to your local git

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
base_url <-
  "https://pharmaverse.github.io/admiral/" # include the trailing backslash!

# get list of all files in the `gh-pages` branch
df_all_files <- tryCatch(gert::git_ls(ref = "gh-pages"), error = function(x) FALSE)

# if a local user (not on CI) does not have a copy of the `gh-pages` branch, exit silently
if (!isTRUE(as.logical(Sys.getenv("CI"))) && isFALSE(df_all_files)) {
  knitr::knit_exit()
}
# extract all folders in the root of the branch
all_folders <-
  sub("/.*", "", df_all_files$path)[grepl(
    x = df_all_files$path,
    pattern = "/",
    fixed = TRUE
  )] |>
  unique()

# subset to all version folders
all_version_folders <-
  all_folders[grep("^v[0-9]+|dev", x = all_folders)] |>
  rev()
# more dev first if it appears
if ("dev" %in% all_version_folders) {
  all_version_folders <- c("dev", all_version_folders) |> unique()
}

# release dates of prior tags
df_tags <- gert::git_tag_list()
df_tags <- df_tags[df_tags$name %in% all_version_folders, ]
df_tags$date <-
  lapply(
    df_tags$commit,
    FUN = function(x) {
      tryCatch(
        gert::git_commit_info(ref = x)$time |> as.Date() |> as.character(),
        error = function(x) NA
      )
    }
  ) |>
  unlist()
df_tags <- df_tags[!is.na(df_tags$date), ]

lst_tag_dates <-
  paste0(" (", df_tags$date, ")") |>
  as.list() |>
  setNames(df_tags$name)

# string with all markdown links
str_website_links <-
  lapply(
    X = all_version_folders,
    FUN = function(x) {
      x_label <- ifelse(x %in% "dev", "Development Site", x)
      paste0("[", x_label, lst_tag_dates[[x]], "](", paste0(base_url, x), ")")
    }
  ) |>
  unlist() |>
  paste(collapse = "\n\n")

r str_website_links



Roche-GSK/admiral documentation built on April 14, 2025, 12:36 p.m.