Redirect

write_redirected <- function(directory){
    posts <- list.dirs(
        path = here::here(directory),
        full.names = FALSE,
        recursive = FALSE
    )
    # extract the slugs
    slugs <- gsub("^(\\d{4}-\\d{2}-\\d{2}-)", "", posts)
    # lines to insert to a netlify _redirect file
    redirects <- paste0("/", slugs, " ", "/",directory,"/", posts)
    # write the _redirect file
    alternate_slugs <- function(x){
        people_slugs <- list.files(path = here::here("docs", x), full.names = TRUE)
        people_info <- paste0("/", basename(people_slugs), " ", "/",x,"/", basename(people_slugs))
    }

o <- unlist(lapply(c("groups", "people"),alternate_slugs))

z <- readLines(here::here("_redirects_base"))

out <- c(redirects, z,o)
    
    writeLines(out, here::here("_redirects"))
}

lapply(c("posts"), write_redirected)
[[1]]
NULL