Skip to content

Instantly share code, notes, and snippets.

@sbalci
Forked from hrbrmstr/webr-experiments.R
Created April 8, 2023 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbalci/0ddbd4e8246b54e8a145bf742031640c to your computer and use it in GitHub Desktop.
Save sbalci/0ddbd4e8246b54e8a145bf742031640c to your computer and use it in GitHub Desktop.
Janky R script to create the HTML page for https://rud.is/webr-experiments/
#!/usr/bin/env Rscript
library(httr, include.only = c("GET", "add_headers", "content"))
library(jsonlite, include.only = c("fromJSON", "write_json"))
library(glue, include.only = c("glue"))
GITHUB_TOKEN <- Sys.getenv("GITHUB_TOKEN")
JSON_FILE <- "webr-experiments.json"
HTML_FILE <- "webr-experiments/index.html"
url <- "https://api.github.com/search/repositories?q=user:hrbrmstr+topic:webr-experiment&per_page=100"
response <- GET(url, add_headers(Authorization = glue("token {GITHUB_TOKEN}")))
json_data <- fromJSON(content(response, "text"), flatten = TRUE)
write_json(json_data$items, JSON_FILE)
repos <- json_data$items[order(as.POSIXct(json_data$items$created_at, format = "%Y-%m-%dT%H:%M:%SZ"), decreasing = TRUE), ]
html_lines <- c("<ul>")
for (idx in seq_along(repos$topics)) {
repo <- repos[idx,]
description <- repo$description
html_url <- repo$html_url
homepage <- repo$homepage
topics <- repo$topics[[1]]
created_at <- as.Date(repo$created_at)
topics_html <- paste0('<span class="topic">', topics[topics != "webr-experiment"], '</span>', collapse = ' ')
html_lines <- c(html_lines, glue('<li><span class="date">{created_at}</span> {description}: <a target=_blank class="gh" href="{html_url}"><i class="fab fa-github"></i></a> <a target=_blank href="{homepage}" class="ex"><i class="fa fa-external-link-alt"></i></a><br/>{topics_html}</li>'))
}
html_lines <- c(html_lines, "</ul>")
HEAD <- '
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🧪 🕸️ hrbrmstr\'s WebR Experiments Index</title>
<meta property="og:title" content="🧪 🕸️ hrbrmstr\'s WebR Experiments Index">
<meta property="twitter:title" content="🧪 🕸️ hrbrmstr\'s WebR Experiments Index">
<meta name="description" content="🧪 🕸️ hrbrmstr\'s WebR Experiments Index">
<meta property="og:description" content="🧪 🕸️ hrbrmstr\'s WebR Experiments Index">
<meta property="twitter:description" content="🧪 🕸️ hrbrmstr\'s WebR Experiments Index">
<meta property="og:site" content="https://rud.is/webr-experiments/">
<meta property="og:site_name" content="🧪 🕸️ WebR Exeriments">
<meta property="twitter:site_name" content="@hrbrmstr">
<meta property="twitter:domain" content="rud.is">
<meta property="twitter:card" content="summary_large_image">
<link href="/css/webr-experiments.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
<h1>🧪 🕸️ hrbrmstr\'s WebR Experiments Index</h1>
'
html_lines <- c(HEAD, html_lines, "</body></html>")
writeLines(html_lines, HTML_FILE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment