Skip to content

Commit

Permalink
Use Font Awesome 5 for GitHub/GitLab icons. Close #231.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdblischak committed Dec 22, 2020
1 parent a4967ca commit fb307bf
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ break the cross-references and require an update. See this
* Added more documention to `wflow_build()` to explain when it does and doesn't
load code defined in a `.Rprofile` file (idea from @pcarbo).

* Bug fix: `wflow_use_github()` and `wflow_use_gitlab()` now use Font Awesome 5
syntax to insert icons into the navigation bar when a recent version of
rmarkdown is installed (>= 2.6) (bug report from @christianholland, #231)

# workflowr 1.6.2

This patch release of workflowr includes minor improvements, updated
Expand Down
14 changes: 14 additions & 0 deletions R/utility.R
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,17 @@ create_newlines <- function(m) {
m <- paste(m, collapse = "\n\n")
return(m)
}

# Get Font Awesome icon for a brand
#
# Decide between Font Awesome 4 and 5
# https://github.com/rstudio/rmarkdown/issues/1991
get_fa_brand_icon <- function(brand) {
if (utils::packageVersion("rmarkdown") < "2.6") {
# Font Awesome 4: rmarkdown adds preceding "fa"
return(sprintf("fa-%s", brand))
}

# Font Awesome 5
return(sprintf("fab fa-%s", brand))
}
2 changes: 1 addition & 1 deletion R/wflow_use_github.R
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ wflow_use_github <- function(username = NULL,

host <- get_host_from_remote(path = project)
if (navbar_link && !is.na(host)) {
site_yml$navbar$right <- list(list(icon = "fa-github",
site_yml$navbar$right <- list(list(icon = get_fa_brand_icon("github"),
text = "Source code",
href = host))
yaml::write_yaml(site_yml, file = site_yml_fname)
Expand Down
2 changes: 1 addition & 1 deletion R/wflow_use_gitlab.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ wflow_use_gitlab <- function(username = NULL, repository = NULL,

host <- get_host_from_remote(path = project)
if (navbar_link && !is.na(host)) {
site_yml$navbar$right <- list(list(icon = "fa-gitlab",
site_yml$navbar$right <- list(list(icon = get_fa_brand_icon("gitlab"),
text = "Source code",
href = host))
yaml::write_yaml(site_yml, file = site_yml_fname)
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-vig-gitlab.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ test_that("Setup GitLab infrastructure", {
expect_equal(length(git_status$untracked), 0)
site_yml_fname <- file.path(s$analysis, "_site.yml")
site_yml <- yaml::yaml.load_file(site_yml_fname)
expect_identical(site_yml$navbar$right[[1]][["icon"]], "fa-gitlab")
expect_identical(site_yml$navbar$right[[1]][["icon"]],
workflowr:::get_fa_brand_icon("gitlab"))
expect_identical(site_yml$output_dir, "../public")
})

Expand Down
9 changes: 6 additions & 3 deletions tests/testthat/test-wflow_use_github.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ test_that("wflow_use_github automates local GitHub configuration", {
output_dir <- site_yml$output_dir
expect_identical("../docs", output_dir)
# Adds a link to the GitHub repository in the navigation bar
expect_identical(site_yml$navbar$right[[1]]$icon, "fa-github")
expect_identical(site_yml$navbar$right[[1]]$icon,
workflowr:::get_fa_brand_icon("github"))
expect_identical(site_yml$navbar$right[[1]]$href,
sprintf("https://github.com/%s/%s", username, repository))
# Configures the Git remote settings to use GitHub
Expand Down Expand Up @@ -73,7 +74,8 @@ test_that("wflow_use_github can be used post GitLab", {
output_dir <- site_yml$output_dir
expect_identical("../docs", output_dir)
# Adds a link to the GitHub repository in the navigation bar
expect_identical(site_yml$navbar$right[[1]]$icon, "fa-github")
expect_identical(site_yml$navbar$right[[1]]$icon,
workflowr:::get_fa_brand_icon("github"))
expect_identical(site_yml$navbar$right[[1]]$href,
sprintf("https://github.com/%s/%s", username, repository))
# Configures the Git remote settings to use GitHub
Expand Down Expand Up @@ -221,7 +223,8 @@ test_that("wflow_use_github works when site has been published", {
output_dir <- site_yml$output_dir
expect_identical("../docs", output_dir)
# Adds a link to the GitHub repository in the navigation bar
expect_identical(site_yml$navbar$right[[1]]$icon, "fa-github")
expect_identical(site_yml$navbar$right[[1]]$icon,
workflowr:::get_fa_brand_icon("github"))
expect_identical(site_yml$navbar$right[[1]]$href,
sprintf("https://github.com/%s/%s", username, repository))
# Configures the Git remote settings to use GitHub
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-wflow_use_gitlab.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ test_that("wflow_use_gitlab automates local GitLab configuration", {
output_dir <- site_yml$output_dir
expect_identical("../public", output_dir)
# Adds a link to the GitLab repository in the navigation bar
expect_identical(site_yml$navbar$right[[1]]$icon, "fa-gitlab")
expect_identical(site_yml$navbar$right[[1]]$icon,
workflowr:::get_fa_brand_icon("gitlab"))
expect_identical(site_yml$navbar$right[[1]]$href,
sprintf("https://gitlab.com/%s/%s", username, repository))
# Creates the required file .gitlab-ci.yml
Expand Down Expand Up @@ -154,7 +155,8 @@ test_that("wflow_use_gitlab works when site has been published", {
output_dir <- site_yml$output_dir
expect_identical("../public", output_dir)
# Adds a link to the GitLab repository in the navigation bar
expect_identical(site_yml$navbar$right[[1]]$icon, "fa-gitlab")
expect_identical(site_yml$navbar$right[[1]]$icon,
workflowr:::get_fa_brand_icon("gitlab"))
expect_identical(site_yml$navbar$right[[1]]$href,
sprintf("https://gitlab.com/%s/%s", username, repository))
# Creates the required file .gitlab-ci.yml
Expand Down

0 comments on commit fb307bf

Please sign in to comment.