generated from understory-garden/single-page-gate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatekit.js
59 lines (49 loc) · 1.77 KB
/
gatekit.js
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
import { getSolidDataset, getStringNoLocale, getThing, getUrl } from '@inrupt/solid-client'
import * as base58 from 'micro-base58'
const VOCAB_PREFIX = "https://understory.coop/vocab/garden#"
export const UG = {
noteBody: `${VOCAB_PREFIX}noteBody`,
noteUrl: `${VOCAB_PREFIX}noteUrl`,
usesConcept: `${VOCAB_PREFIX}usesConcept`,
usesConceptIndex: `${VOCAB_PREFIX}usesConceptIndex`,
conceptPrefix: `${VOCAB_PREFIX}conceptPrefix`,
storedAt: `${VOCAB_PREFIX}storedAt`,
usesCSS: `${VOCAB_PREFIX}usesCSS`,
monetizedFor: `${VOCAB_PREFIX}monetizedFor`
}
export const conceptNameToUrlSafeId = (name) =>
base58.encode(name.toLowerCase())
export const urlSafeIdToConceptName = (id) => {
return new TextDecoder().decode(base58.decode(id))
}
export function conceptUriToName(conceptUri){
return urlSafeIdToConceptName(conceptUri.split("#").slice(-1)[0])
}
export function noteUriToName(noteUri){
return urlSafeIdToConceptName(noteUri.split("/").slice(-1)[0].split("\.")[0])
}
export function tagNameToUrlSafeId(tagName){
return encodeURIComponent(tagName)
}
export async function loadNote(url){
const name = noteUriToName(url)
const noteResource = await getSolidDataset(url)
const note = getThing(noteResource, url)
const body = getStringNoLocale(note, UG.noteBody)
return { name, body }
}
export async function loadConcept(indexUrl, url){
const conceptIndex = await getSolidDataset(indexUrl)
const concept = getThing(conceptIndex, url)
const noteUrl = getUrl(concept, UG.storedAt)
return loadNote(noteUrl)
}
export async function loadPublicGnomeConfig(url) {
const gnomeConfigResource = await getSolidDataset(url)
const gnomeConfigThing = getThing(gnomeConfigResource, url)
const gnomeConfig = {
url,
config: gnomeConfigThing
}
return gnomeConfig
}