Repository navigation
Expand file tree
/
Copy pathindex.Rmd
More file actions
60 lines (53 loc) · 1.46 KB
/
Copy pathindex.Rmd
File metadata and controls
60 lines (53 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
title: Keras examples
output: rmarkdown::html_vignette
knit: ({source(here::here("tools/knit.R")); knit_vignette})
---
<div class="container">
```{r echo=FALSE, results = "asis"}
examples <- list.files(".", pattern = ".Rmd", recursive = TRUE)
examples <- examples[examples != "index.Rmd"]
examples <- lapply(examples, function(x) {
out <- rmarkdown::yaml_front_matter(x)
out$handle <- gsub("\\.Rmd", ".html", x)
out
})
card <- function(x) {
category <- x$category %||% ""
badge_type <-
if (category == "basic")
"success"
else if (category == "intermediate")
"warning"
else if (category == "advanced")
"danger"
else
"light"
glue::glue(
'<div class="col">
<div class="card h-100">
<h5 class="card-header bg-transparent">{x$title}</h5>
<div class="card-body d-flex flex-column">
<span class="badge rounded-pill bg-{badge_type} mb-1" style="align-self: flex-start">{category}</span>
<p class="card-text">{x$description}</p>
<a href="{x$handle}" class="btn btn-primary mt-auto">See code</a>
</div>
</div>
</div>
', .trim = FALSE)
}
cards <- lapply(examples, card)
domains <- split(cards, sapply(examples, function(x) x$domain))
cat("```{=html}\n")
for (domain in names(domains)) {
cat("\n")
cat(glue::glue('<h2 class="mt-2">{stringr::str_to_title(domain)}</h2>\n'))
cat(glue::glue('<div class="row row-cols-1 row-cols-md-2 g-4">\n'))
for (card in domains[[domain]]) {
cat(card)
}
cat('</div>\n')
}
cat("```\n")
```
</div>