generated from pharmaverse/admiraltemplate
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add history section and article for previous versions
- Loading branch information
Showing
3 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
--- | ||
title: "Previous Versions of Website" | ||
--- | ||
|
||
```{r, include = FALSE} | ||
# 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 = "#>" | ||
) | ||
``` | ||
|
||
```{r setup, include=FALSE} | ||
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() | ||
} | ||
``` | ||
|
||
```{r include=FALSE} | ||
# 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` |