Created
April 8, 2023 10:50
-
-
Save hrbrmstr/9baf0521ac5e0fb5d799e79f72cd6225 to your computer and use it in GitHub Desktop.
Janky R script to create the HTML page for https://rud.is/webr-experiments/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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