-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f7dc9ce
commit 3e1d5fe
Showing
6 changed files
with
34 additions
and
11 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,4 @@ | ||
#' This is a vector of all the allowed blog post tags. It is stored in a separate file so that it can be referenced | ||
#' by `create_blogpost.R` and `check_post_tags.R`. | ||
|
||
allowed_tags <<- c("Metadata", "SDTM", "ADaM", "TLG", "Shiny", "Community", "Conferences", "Submissions", "Technical") |
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 |
---|---|---|
@@ -1,18 +1,34 @@ | ||
# Get list of blog posts ---- | ||
posts <- list.files("posts", recursive = TRUE, pattern = "*.qmd") | ||
|
||
# Get vector of allowed tags ---- | ||
source("R/allowed_tags.R") | ||
|
||
# Function to extract tags from a post and check them against the allowed list ---- | ||
check_post_tags <- function(post) { | ||
allowable_tags <- c("Metadata", "SDTM", "ADaM", "TLG", "Shiny", "Community", "Conferences", "Submissions", "Technical") | ||
|
||
post_tags <- rmarkdown::yaml_front_matter(file.path("posts", post))$categories | ||
|
||
cross_check <- post_tags %in% allowable_tags | ||
|
||
problematic_tags <- post_tags[!cross_check] | ||
|
||
if (!all(cross_check)) { | ||
stop(paste("The tags selected in:", post, "are not all from the allowed list of tags.")) | ||
cli::format_message('The tag(s) {.val {problematic_tags}} in the post {.val {post}} are not from the allowable list of tags.') | ||
} | ||
} | ||
|
||
# Apply check_post_tags to all blog posts ---- | ||
invisible(lapply(posts, check_post_tags)) | ||
# Apply check_post_tags to all blog posts and find problem posts ---- | ||
check_results <- lapply(posts, check_post_tags) | ||
error_messages <- unlist(Filter(Negate(is.null), check_results)) | ||
|
||
# Construct error message if one or more posts have problematic tags ---- | ||
if(length(error_messages) > 0){ | ||
|
||
error_messages <- c(error_messages, "Please select from the following tags: {.val {allowed_tags}}, or contact one of the maintainers.") | ||
names(error_messages) = rep("x", length(error_messages) - 1) | ||
|
||
concatenated_error_messages = cli::cli_bullets(error_messages) | ||
|
||
cli::cli_abort(concatenated_error_messages) | ||
|
||
} |
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