From 7c2383acf42fe345890a6d70e4d58bd33dd178c0 Mon Sep 17 00:00:00 2001 From: tree Date: Fri, 16 Jun 2023 02:23:05 +0200 Subject: [PATCH] add structured data --- .gitignore | 1 + Makefile | 9 +++++++++ README.md | 2 +- events/meetups.yaml | 42 +++++++++++++++++++++++++++++++++++++++ events/summits.yaml | 18 +++++++++++++++++ index.js | 48 +++++++++++++++++++++++++++++++++++++++++++++ schema.yaml | 34 ++++++++++++++++++++++++++++++++ 7 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 events/meetups.yaml create mode 100644 events/summits.yaml create mode 100644 index.js create mode 100644 schema.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53c37a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dist \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..16c9b6b --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +.PHONY: all build + +all: test build + +test: + deno test --unstable --allow-read index.js + +build: + deno run --unstable --allow-read --allow-write index.js build \ No newline at end of file diff --git a/README.md b/README.md index fca2157..03e2627 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Calendar with all events and links: ### Meetups | # id | date | location | πŸ‘₯ | coincidence | dri | | --- | --- | --- | --- | --- | --- | -| `bcn-1` | 2023-07-?? | πŸ‡ͺπŸ‡Έ Barcelona | 50 | [ETHBarcelona](https://ethbarcelona.com/) | Tree | +| `bcn-1` | 2023-07-?? | πŸ‡ͺπŸ‡Έ Barcelona | 50 | | Tree | | `par-1` | 2023-07-?? | πŸ‡«πŸ‡· Paris || [EthCC 6](https://www.ethcc.io/) | ? | | `waw-1` | 2023-08-?? | πŸ‡΅πŸ‡± Warsaw || [ETHwarsaw](https://www.ethwarsaw.dev/) | Tree | | `ber-1` | *2023-09-??* | *πŸ‡©πŸ‡ͺ Berlin* || [BBW](https://ethrome.org/) w/ [Protocol Berg](https://protocol.berlin/) | Tree | diff --git a/events/meetups.yaml b/events/meetups.yaml new file mode 100644 index 0000000..9f13941 --- /dev/null +++ b/events/meetups.yaml @@ -0,0 +1,42 @@ +- id: w3pm-bcn-1 + date: "2023-07-??" + city: Barcelona + country: es + coincidence: "[ETHBarcelona](https://ethbarcelona.com/)" + lead: TBD + visitors: 50 + +- id: w3pm-waw-1 + date: "2023-08-??" + city: Warsaw + country: pl + coincidence: "[ETHwarsaw](https://www.ethwarsaw.dev/)" + lead: Tree + +- id: w3pm-ber-1 + date: "2023-09-??" + city: Berlin + country: de + coincidence: "[BBW](https://ethrome.org/) w/ [Protocol Berg](https://protocol.berlin/)" + lead: TBD + +- id: w3pm-rom-1 + date: "2023-10-05" + city: Rome + country: it + coincidence: "[ETHRome](https://ethrome.org/)" + lead: PG + +- id: w3pm-ist-1 + date: "2023-11-??" + city: Istanbul + country: tr + coincidence: "[Devconnect Istanbul](https://devconnect.org/)" + lead: TBD + +- id: w3pm-ams-1 + date: "2024/Q2" + city: Amsterdam + country: nl + coincidence: "[ETHDam 2024](https://www.ethdam.com/)" + lead: TBD \ No newline at end of file diff --git a/events/summits.yaml b/events/summits.yaml new file mode 100644 index 0000000..314130f --- /dev/null +++ b/events/summits.yaml @@ -0,0 +1,18 @@ +- id: w3ps1 + date: "2023-06-05" + city: Prague + country: cz + coincidence: "[PBW](https://prgblockweek.com/) w/ [ETHPrague](https://ethprague.com/)" + lead: Tree + visitors: 180 + links: + web: https://prague.web3privacy.info/ + git: https://github.com/web3privacy/w3ps1 + +- id: w3ps2 + date: "2023-11-02" + city: Brno + country: cz + coincidence: "[ETHBrnoΓ—3](https://ethbrno.cz/)" + lead: Tree + visitors: 250 \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..3d9441e --- /dev/null +++ b/index.js @@ -0,0 +1,48 @@ +import Ajv from "npm:ajv@8.8.2"; +import addFormats from "npm:ajv-formats@2.1.1"; +import { load as yamlLoad } from "https://deno.land/x/js_yaml_port@3.14.0/js-yaml.js"; +import { emptyDir } from "https://deno.land/std@0.173.0/fs/mod.ts"; + +const types = [ "summits", "meetups" ] + +async function _loadYaml(fn) { + return yamlLoad(await Deno.readTextFile(fn)); +} + +async function test() { + const ajv = new Ajv({ strict: false }); + addFormats(ajv); + const schema = await _loadYaml("./schema.yaml"); + const validator = ajv.compile(schema); + + for (const type of types) { + Deno.test(`Check schema: ${type}`, async () => { + const list = await _loadYaml(`./events/${type}.yaml`); + if (!validator(list)) { + throw validator.errors; + } + }) + } +} + +async function build() { + const output = {} + for (const type of types) { + const list = await _loadYaml(`./events/${type}.yaml`); + output[type] = list + } + await emptyDir("./dist") + const fn = "./dist/index.json" + await Deno.writeTextFile(fn, JSON.stringify(output, null, 2)) + console.log(`File saved: `) +} + +switch (Deno.args[0] || "test") { + case "test": + await test(); + break; + + case "build": + await build(); + break; +} diff --git a/schema.yaml b/schema.yaml new file mode 100644 index 0000000..26f8bff --- /dev/null +++ b/schema.yaml @@ -0,0 +1,34 @@ +type: array +items: { "$ref": "#/$defs/event" } +$defs: + event: + type: object + additionalProperties: false + required: + - id + - date + - city + - country + properties: + id: + type: string + date: + type: string + city: + type: string + country: + type: string + pattern: "^\\w{2}$" + coincidence: + type: string + lead: + type: string + visitors: + type: number + links: + type: object + additionalProperties: false + patternProperties: + "^[\\w]+": + type: string + format: uri \ No newline at end of file