Skip to content

Commit 988f94f

Browse files
committed
add icons to repositories in HTML output of register
codecheckers/register#28
1 parent 953da29 commit 988f94f

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

R/register.R

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ register_render <- function(register = read.csv("register.csv", as.is = TRUE),
6767
FUN = function(repository) {
6868
spec <- parse_repository_spec(repository)
6969

70-
if (!is.na(spec)) {
70+
if (!any(is.na(spec))) {
7171
urrl <- "#"
7272

7373
if (spec[["type"]] == "github") {
@@ -97,27 +97,61 @@ register_render <- function(register = read.csv("register.csv", as.is = TRUE),
9797
}
9898
check_times <- parsedate::parse_date(check_times)
9999
register_table$`Check date` <- format(check_times, "%Y-%m-%d")
100-
100+
101+
md_columns_widths <- "|:-------|:--------------------------------|:------------------|:---|:--------------------------|:----------|"
101102
if("md" %in% outputs) {
102103
capture.output(
103104
cat("---\ntitle: CODECHECK Register\n---"),
104105
knitr::kable(register_table, format = "markdown"),
105106
file = "register.md"
106107
)
107-
# hack to reduce colum width of 4th column
108+
# hack to reduce column width of 4th column
108109
md_table <- readLines("register.md")
109-
md_table[6] <- "|:-----------|:--------------------------|:---------------------|:---|:--------------------------------------|:----------|"
110+
md_table[6] <- md_column_widths
110111
writeLines(md_table, "docs/register.md")
111112
file.remove("register.md")
112113
# TODO: fix table column width, e.g. via using a register.Rmd with kableExtra
113114
}
114115

115116
# render register to HTML
116117
if("html" %in% outputs) {
117-
rmarkdown::render(input = "docs/register.md",
118+
# add icons to the Repository column for HTML output, use a copy of the register.md
119+
# so the inline HTML is not in the .md output
120+
register_table$Repository <- sapply(X = register$Repository,
121+
FUN = function(repository) {
122+
spec <- parse_repository_spec(repository)
123+
124+
if (!any(is.na(spec))) {
125+
urrl <- "#"
126+
127+
if (spec[["type"]] == "github") {
128+
urrl <- paste0("https://github.com/", spec[["repo"]])
129+
paste0("<i class='fa fa-github'></i>&nbsp;[", spec[["repo"]], "](", urrl, ")")
130+
} else if (spec[["type"]] == "osf") {
131+
urrl <- paste0("https://osf.io/", spec[["repo"]])
132+
paste0("<i class='ai ai-osf'></i>&nbsp;[", spec[["repo"]], "](", urrl, ")")
133+
} else {
134+
repository
135+
}
136+
} else {
137+
repository
138+
}
139+
})
140+
capture.output(
141+
cat("---\ntitle: CODECHECK Register\n---"),
142+
knitr::kable(register_table, format = "markdown"),
143+
file = "docs/register-icons.md"
144+
)
145+
md_table <- readLines("docs/register-icons.md")
146+
file.remove("docs/register-icons.md")
147+
md_table[6] <- md_columns_widths
148+
writeLines(md_table, "docs/register-icons.md")
149+
150+
rmarkdown::render(input = "docs/register-icons.md",
118151
# next paths are relative to input file
119152
output_yaml = "html_document.yml",
120153
output_file = "index.html")
154+
file.remove("docs/register-icons.md")
121155
}
122156

123157
# render register to JSON

0 commit comments

Comments
 (0)