Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #128

Merged
merged 2 commits into from
Nov 26, 2024
Merged

Dev #128

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: saros.base
Title: Base Tools for Semi-Automatic Reporting of Ordinary Surveys
Version: 0.2.5
Version: 0.2.6
Authors@R: c(
person(given = "Stephan",
family = "Daus",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export(get_organize_by_opts)
export(initialize_saros_project)
export(read_default_draft_report_args)
export(refine_chapter_overview)
export(remove_entry_from_sidebar)
export(setup_access_restrictions)
export(write_default_draft_report_args)
importFrom(fs,dir_ls)
Expand Down
39 changes: 39 additions & 0 deletions R/remove_entry_from_sidebar.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#' Removes entries in sidebar if containing a filename regex pattern.
#'
#' @param path String, path to where your html-files are located. Defaults to "_site"
#' @param filename_as_regex Character vector of regex patterns to search for. Defaults to c("report\\.pdf", "report\\.docx")
#'
#' @export
#' @return Invisibly returns files processed

remove_entry_from_sidebar <-
function(path = "_site",
filename_as_regex = c(
"report\\.pdf",
"report\\.docx"
)) {
fs::dir_ls(
path = path, all = FALSE, recurse = TRUE,
type = "file", regexp = "\\.html"
) |>
lapply(FUN = function(.x) {
pattern_to_remove <-
paste0(
"<li class=\"sidebar-item\">\\s*<div class=\"sidebar-item-container\">\\s*<a href=\"[^\"]*",
filename_as_regex, "\"[^>]*>\\s*<span class=\"menu-text\">[^<]*</span></a>\\s*</div>\\s*</li>"
)
.x |>
readLines() |>
paste0(collapse = "\n") |>
stringi::stri_replace_all_regex(
pattern = pattern_to_remove,
replacement = ""
) |>
stringi::stri_split_lines() |>
unlist()
writeLines(con = .x, sep = "\n")
.x
}) |>
unlist() |>
invisible()

Check warning on line 38 in R/remove_entry_from_sidebar.R

View check run for this annotation

Codecov / codecov/patch

R/remove_entry_from_sidebar.R#L15-L38

Added lines #L15 - L38 were not covered by tests
}
22 changes: 22 additions & 0 deletions man/remove_entry_from_sidebar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading