Skip to content

Commit

Permalink
Create random avatar when none is available
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiWaldrant committed Nov 22, 2024
1 parent 8fe354b commit e151a78
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
/site_libs
*.rmarkdown
/.luarc.json
/tmp
22 changes: 20 additions & 2 deletions team/_rerender_contributors.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,18 @@ render_author <- function(author) {
email_clean <- tolower(stringr::str_trim(author$info$email))
checksum <- digest::digest(email_clean, algo = "md5", serialize = FALSE)
paste0("https://www.gravatar.com/avatar/", checksum)
} else {
} else if (file.exists("/images/avatar.svg")){
"/images/avatar.svg"
} else {
# generate random avatar
name <- strsplit(author$name, " ")
url <- paste0("https://avatar.iran.liara.run/username?username=",name[[1]][[1]],"+",name[[1]][[2]])
output_dir <- file.path("tmp", gsub(" ", "_", author$name))
if (!dir.exists(output_dir)) {
dir.create(output_dir, recursive = TRUE)
}
download.file(url, file.path(output_dir, "avatar.png"), mode = "wb")
"avatar.png"
}

# process links
Expand Down Expand Up @@ -174,6 +184,11 @@ for (task_name in names(tasks)) {
}

writeLines(txt, file_path)

if (file.exists(file.path("tmp", gsub(" ", "_", author$name), "avatar.png"))) {
file.rename(file.path("tmp", gsub(" ", "_", author$name), "avatar.png"), file.path(dirname(file_path), "avatar.png"))
}

}
}

Expand Down Expand Up @@ -212,7 +227,10 @@ listing:
template: members.ejs
sort: ''
", paste(teams_headers, collapse = "\n"), "
css: team.css
css:
- team.css
- ../_site/site_libs/quarto-contrib/fontawesome6-0.1.0/all.css
- ../_site/site_libs/quarto-contrib/fontawesome6-0.1.0/latex-fontsize.css
---
## Core members
Expand Down
6 changes: 3 additions & 3 deletions team/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ listing:
template: members.ejs
sort: ''
css:
- team.css
- ../_site/site_libs/quarto-contrib/fontawesome6-0.1.0/all.css
- ../_site/site_libs/quarto-contrib/fontawesome6-0.1.0/latex-fontsize.css
- team.css
- ../_site/site_libs/quarto-contrib/fontawesome6-0.1.0/all.css
- ../_site/site_libs/quarto-contrib/fontawesome6-0.1.0/latex-fontsize.css
---

## Core members
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Guanao Yan
image: /images/avatar.svg
image: avatar.png
role: Author
about:
template: jolla
Expand Down

0 comments on commit e151a78

Please sign in to comment.