Redirect

write_redirected <- function(){
    posts <- list.dirs(
        path = here::here("posts"),
        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, " ", "/","posts","/", posts)
    # write the _redirect file
    alternate_slugs <- function(x){
        people_slugs <- gsub(list.files(path = here::here(x), full.names = TRUE), pattern = "qmd", replacement = "html")
        people_info <- paste0("/", tools::file_path_sans_ext(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"))
    writeLines(out, here::here("www","_redirects"))
}

write_redirected()