Open medewitt opened 5 years ago
nav_bar[nav.start:nav.end] <- gsub('href="', paste0('href="', directory_depth$path_addition), nav_bar[nav.start:nav.end], fixed=TRUE)
nav_bar[nav.start:nav.end] <- gsub(paste0(directory_depth$path_addition, "http"), "http", nav_bar[nav.start:nav.end], fixed=TRUE)
nav_bar[grep(pattern = 'href="', nav_bar)]
grep(pattern = 'href="', nav_bar)
start <- readLines("dashboards/library/lib100_2.html") new <- c(nav_bar, start) writeLines(new, "dashboards/library/lib100_2.html")
library(tidyverse) library(fs) library(here)
Find the index
index_dir <- fs::dir_info(here())
Supply the document that you want to edit
document_name <- "lib100_dashboard"
Look within the subdirectory and list everything
dashboard_dir <- fs::dir_info("dashboards", recursive = T)
Find the path for the index
website_index <- index_dir %>% filter(grepl("index.html", x = path)) %>% pull(path)
Read in index
index_files <- readLines(website_index)
Zip out what you want to include on the subdirectories
start_header<- which(grepl("", index_files)) +1 end_header <- which(grepl("
Create the nab bar that you want to append
nav_bar <- index_files[start_header:end_header]
Do some analysis to see what you need to add
directory_depth <- dashboard_dir %>% filter(grepl(".html", x = path), grepl(document_name, path, ignore.case = T)) %>% mutate(n = str_count(path, "/")) %>% mutate(path_addition = paste(rep("../",n), collapse = "")) %>% select(path, path_addition)
nav_bar[grep("site_libs", nav_bar)]
Add structure of site_libs and the sytle files to inherit
nav_bar <- gsub(pattern = "site_libs", replacement = paste0(directory_depth$path_addition, "site_libs"), x = nav_bar)
nav_bar <- gsub(pattern = 'css\\style.css', replacement = paste0(directory_depth$path_addition, 'css\\style.css'), x = nav_bar) nav_bar[grep('css\\style.css', nav_bar)]
edit the html to fix the nav-bar, editing all links within the code section
nav.start <- grep(pattern=' <div class=\"navbar-header\">', nav_bar) nav.end <- grep(pattern='