Skip to content

Instantly share code, notes, and snippets.

View nikolaswise's full-sized avatar
🌵

Nikolas Wise nikolaswise

🌵
View GitHub Profile
@nikolaswise
nikolaswise / event-delegator.js
Last active March 2, 2020 16:50
this delegates events!
// 🎄🐊.js
// Advent Alligator, the Event Delegator
let delegations = new Map();
const noop = () => {}
const delegate = (node, action) => (e) => {
delegations[node]
.filter(del => del.action === action)

SmugMug Design System

Homework for Michal

Color:

Color Name Color Hex Value
Green #6EB801
Light Green #81D600
@nikolaswise
nikolaswise / mdsm.js
Created August 4, 2020 15:11
Plugin for MarkdownIt (https://github.com/markdown-it/markdown-it) that turns markdown image syntax into Figure tags with syntax for responsive image sizes via lazysizes: https://afarkas.github.io/lazysizes/index.html, http://afarkas.github.io/lazysizes/rias/
const splitCDN = (uri) => {
let imgArr = uri.split('/')
let filename = imgArr.pop()
let size = imgArr.pop()
let base = imgArr.join('/')
return { base, size, filename }
}
const getCDNBase = (uri) => {
let { base } = splitCDN(uri)
@nikolaswise
nikolaswise / rdfa2json.js
Created March 29, 2024 12:06
Given a string pf HTML and a URI, extract simple RDFa microdata into JSON
const arrayify = target => Array.isArray(target) ? target : [target]
export const rdfa2json = (htmlString, uri) => {
const parser = new DOMParser()
let html = parser
.parseFromString(htmlString, "text/html")
const propertyNodes = [...html.querySelectorAll('[property]')]
let predicates = propertyNodes
.map(node => {
@nikolaswise
nikolaswise / html2jsonld.js
Created March 29, 2024 12:07
Given a directory of html, extract all the RDFa statements and write a JSON-LD file.
import fs from 'fs'
import path from 'path'
import { JSDOM } from 'jsdom'
// https://gist.github.com/nikolaswise/d3c9cc914f1168bdf244cdc797c64eb8
import { rdfa2json } from './rdfa2json.js'
let origin = process.env.origin
global.DOMParser = new JSDOM().window.DOMParser
const handleError = (err) => {
@nikolaswise
nikolaswise / jsonld2nodelinkarrays.js
Created March 29, 2024 12:25
Take a JSON-LD object and cast it into two arrays, one of nodes and one of links, for rendering with a D3 network visualization.
const fn = (jsonLD, linkType) => {
let nodes = jsonLD['@graph']
.filter(n => n)
.map(n => {
n.level = 0
return n
})
let connections = subjects["@graph"].map(node => {
return {