GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — node-solid-server/lib/rdf-notification-template.mjs at main · nodeSolidServer/node-solid-server Expand file tree/ Copy pathrdf-notification-template.mjsMore file actions 76 lines (66 loc) · 2.03 KB / Copy pathrdf-notification-template.mjsFile metadata and controls76 lines (66 loc) · 2.03 KB 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 import { v4 as uuid } from 'uuid' const CONTEXT_ACTIVITYSTREAMS = 'https://www.w3.org/ns/activitystreams' const CONTEXT_NOTIFICATION = 'https://www.w3.org/ns/solid/notification/v1' const CONTEXT_XML_SCHEMA = 'http://www.w3.org/2001/XMLSchema' function generateJSONNotification ({ activity: type, eventID, date: published, object, target, state = undefined }) { return { published, type, id: `urn:uuid:${uuid()}`, ...(eventID) && { state: eventID }, object, ...(type === 'Add') && { target }, ...(type === 'Remove') && { origin: target } } } function generateTurtleNotification ({ activity, eventID, date, object, target }) { let targetLine = '' let stateLine = '' if (activity === 'Add') { targetLine = `\n as:target <${target}> ;` } if (activity === 'Remove') { targetLine = `\n as:origin <${target}> ;` } if (eventID) { stateLine = `\n notify:state "${eventID}" ;` } return `@prefix as: <${CONTEXT_ACTIVITYSTREAMS}#> . @prefix notify: <${CONTEXT_NOTIFICATION}#> . @prefix xsd: <${CONTEXT_XML_SCHEMA}#> . <urn:uuid:${uuid.v4()}> a as:${activity} ; as:object <${object}> ;${targetLine}${stateLine} as:published "${date}"^^xsd:dateTime .`.replaceAll('\n', '\r\n') } function serializeToJSONLD (notification, isActivityStreams = false) { notification['@context'] = [CONTEXT_NOTIFICATION] if (!isActivityStreams) { notification['@context'].unshift(CONTEXT_ACTIVITYSTREAMS) } return JSON.stringify(notification, null, 2) } export default function rdfTemplate (props) { const { mediaType } = props if (mediaType[0] === 'application/activity+json' || (mediaType[0] === 'application/ld+json' && mediaType[1].get('profile')?.toLowerCase() === 'https://www.w3.org/ns/activitystreams')) { return serializeToJSONLD(generateJSONNotification(props), true) } if (mediaType[0] === 'application/ld+json') { return serializeToJSONLD(generateJSONNotification(props)) } if (mediaType[0] === 'text/turtle') { return generateTurtleNotification(props) } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |