-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtalks.qmd
More file actions
211 lines (185 loc) · 7.52 KB
/
talks.qmd
File metadata and controls
211 lines (185 loc) · 7.52 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
---
title: "Talks"
---
```{r}
#| echo: false
#| warning: false
#| message: false
#| results: asis
talk_files <- list.files("content/talks", pattern = "index\\.md$", recursive = TRUE, full.names = TRUE)
trim <- function(x) gsub("^\\s+|\\s+$", "", x)
escape_html <- function(x) {
if (is.na(x) || !nzchar(x)) return("")
x <- gsub("&", "&", x, fixed = TRUE)
x <- gsub("<", "<", x, fixed = TRUE)
x <- gsub(">", ">", x, fixed = TRUE)
x
}
escape_attr <- function(x) {
if (is.na(x) || !nzchar(x)) return("")
x <- gsub("&", "&", x, fixed = TRUE)
x <- gsub("\"", """, x, fixed = TRUE)
x <- gsub("<", "<", x, fixed = TRUE)
x <- gsub(">", ">", x, fixed = TRUE)
x
}
read_front <- function(path) {
lines <- readLines(path, warn = FALSE)
d <- which(trim(lines) == "---")
if (length(d) < 2) return(character(0))
lines[(d[1] + 1):(d[2] - 1)]
}
get_field <- function(front, field) {
if (!length(front)) return(NA_character_)
m <- grep(paste0("^", field, ":"), front)
if (!length(m)) return(NA_character_)
v <- sub(paste0("^", field, ":\\s*"), "", front[m[1]])
v <- gsub('^"|"$', "", trim(v))
if (!nzchar(v)) return(NA_character_)
v
}
youtube_embed <- function(url) {
if (is.na(url) || !nzchar(url)) return(NA_character_)
u <- trim(url)
if (grepl("youtu\\.be/", u)) {
id <- sub(".*youtu\\.be/([^?&/]+).*", "\\1", u)
return(paste0("https://www.youtube-nocookie.com/embed/", id))
}
if (grepl("youtube\\.com/watch", u)) {
id <- sub(".*[?&]v=([^?&/]+).*", "\\1", u)
return(paste0("https://www.youtube-nocookie.com/embed/", id))
}
if (grepl("youtube\\.com/embed/", u)) return(sub("youtube\\.com/embed/", "youtube-nocookie.com/embed/", u))
if (grepl("youtube-nocookie\\.com/embed/", u)) return(u)
NA_character_
}
youtube_thumbnail <- function(url) {
if (is.na(url) || !nzchar(url)) return(NA_character_)
u <- trim(url)
id <- NA_character_
if (grepl("youtu\\.be/", u)) {
id <- sub(".*youtu\\.be/([^?&/]+).*", "\\1", u)
} else if (grepl("youtube\\.com/watch", u)) {
id <- sub(".*[?&]v=([^?&/]+).*", "\\1", u)
} else if (grepl("youtube(?:-nocookie)?\\.com/embed/", u)) {
id <- sub(".*embed/([^?&/]+).*", "\\1", u)
}
if (is.na(id) || !nzchar(id)) return(NA_character_)
paste0("https://i.ytimg.com/vi/", id, "/hqdefault.jpg")
}
talks <- lapply(talk_files, function(path) {
slug <- basename(dirname(path))
front <- read_front(path)
date_raw <- get_field(front, "date")
date_short <- ifelse(is.na(date_raw), NA_character_, substr(gsub("'", "", date_raw), 1, 10))
date_obj <- suppressWarnings(as.Date(date_short))
img_candidates <- c("featured.png", "featured.jpg", "featured.jpeg", "featured.webp")
img_path <- NA_character_
for (img in img_candidates) {
p <- file.path(dirname(path), img)
if (file.exists(p)) {
img_path <- gsub("^content/", "content/", p)
break
}
}
abstract <- get_field(front, "abstract")
summary <- get_field(front, "summary")
abs_text <- ifelse(!is.na(abstract) && nzchar(abstract), abstract, summary)
data.frame(
slug = slug,
title = get_field(front, "title"),
date = date_short,
date_obj = date_obj,
event = get_field(front, "event"),
event_url = get_field(front, "event_url"),
abstract = abs_text,
url_video = get_field(front, "url_video"),
url_slides = get_field(front, "url_slides"),
url_pdf = get_field(front, "url_pdf"),
image = img_path,
stringsAsFactors = FALSE
)
})
talks <- do.call(rbind, talks)
talks <- talks[!(tolower(trim(talks$slug)) == "talks" | tolower(trim(talks$title)) == "recent & upcoming talks"), ]
talks <- talks[order(talks$date_obj, decreasing = TRUE, na.last = TRUE), ]
cat('<div class="talk-grid">\n')
for (i in seq_len(nrow(talks))) {
t <- talks[i, ]
ttl <- escape_html(ifelse(is.na(t$title), t$slug, t$title))
d <- ifelse(is.na(t$date), "Date unavailable", t$date)
ev <- ifelse(is.na(t$event), "Venue not specified", escape_html(t$event))
cat('<article class="talk-card">\n')
cat('<div class="talk-card-media">\n')
if (!is.na(t$image) && nzchar(t$image)) {
ttl_attr <- escape_attr(ttl)
cat('<img src="', t$image, '" alt="Talk image: ', ttl_attr, '">\n', sep = "")
} else {
cat('<div class="talk-card-image-placeholder">Talk image</div>\n')
}
cat('<a class="talk-card-overlay" href="#talk-', t$slug, '">Talk description</a>\n', sep = "")
cat('</div>\n')
cat('<div class="talk-card-body">\n')
cat('<h3>', ttl, '</h3>\n', sep = "")
cat('<p class="meta">', d, ' · ', ev, '</p>\n', sep = "")
cat('</div>\n')
cat('</article>\n')
}
cat('</div>\n')
cat('\n## Talk Descriptions\n\n')
for (i in seq_len(nrow(talks))) {
t <- talks[i, ]
ttl <- escape_html(ifelse(is.na(t$title), t$slug, t$title))
d <- ifelse(is.na(t$date), "Date unavailable", t$date)
abs <- ifelse(is.na(t$abstract), "No abstract available.", escape_html(t$abstract))
ev <- ifelse(is.na(t$event), "Venue not specified", escape_html(t$event))
embed <- youtube_embed(t$url_video)
cat('<section id="talk-', t$slug, '" class="talk-detail">\n', sep = "")
cat('<h3>', ttl, '</h3>\n', sep = "")
cat('<p class="meta"><strong>Date:</strong> ', d, '</p>\n', sep = "")
if (!is.na(t$event_url) && nzchar(t$event_url)) {
cat('<p class="meta"><strong>Venue:</strong> <a href="', t$event_url, '">', ev, '</a></p>\n', sep = "")
} else {
cat('<p class="meta"><strong>Venue:</strong> ', ev, '</p>\n', sep = "")
}
cat('<p class="talk-summary"><strong>Abstract:</strong> ', abs, '</p>\n', sep = "")
cat('<p class="talk-links">')
if (!is.na(t$url_slides) && nzchar(t$url_slides)) cat('<a href="', t$url_slides, '">Slides</a> ', sep = "")
if (!is.na(t$url_pdf) && nzchar(t$url_pdf)) cat('<a href="', t$url_pdf, '">Related page/PDF</a> ', sep = "")
if (!is.na(t$url_video) && nzchar(t$url_video)) cat('<a href="', t$url_video, '">Video link</a>', sep = "")
cat('</p>\n')
if (!is.na(embed) && nzchar(embed)) {
ttl_attr <- escape_attr(ttl)
watch_url <- escape_attr(t$url_video)
embed_attr <- escape_attr(embed)
thumb <- youtube_thumbnail(t$url_video)
thumb_attr <- escape_attr(ifelse(is.na(thumb), "", thumb))
cat('<div class="talk-video">', sep = "")
cat('<div class="video-fallback-frame js-video-embed" data-embed="', embed_attr, '" data-title="Video: ', ttl_attr, '" data-watch="', watch_url, '">', sep = "")
if (nzchar(thumb_attr)) {
cat('<a class="video-fallback-link video-thumb-link" href="', watch_url, '"><img src="', thumb_attr, '" alt="Video thumbnail: ', ttl_attr, '"><span>Watch on YouTube</span></a>', sep = "")
} else {
cat('<a class="video-fallback-link" href="', watch_url, '">Watch on YouTube</a>', sep = "")
}
cat('</div></div>\n')
}
cat('<p><a href="#top">Back to top</a></p>\n')
cat('</section>\n')
}
cat('
<script>
window.addEventListener("DOMContentLoaded", function () {
var canEmbed = window.location.protocol === "http:" || window.location.protocol === "https:";
var nodes = document.querySelectorAll(".js-video-embed");
nodes.forEach(function (el) {
if (!canEmbed) return;
var src = el.getAttribute("data-embed") || "";
var title = el.getAttribute("data-title") || "Video";
var sep = src.indexOf("?") === -1 ? "?" : "&";
var finalSrc = src + sep + "rel=0&modestbranding=1";
el.innerHTML = \'<iframe src="\' + finalSrc + \'" title="\' + title + \'" loading="lazy" referrerpolicy="strict-origin-when-cross-origin" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>\';
});
});
</script>
')
```