Skip to content

Commit

Permalink
lot of work
Browse files Browse the repository at this point in the history
  • Loading branch information
burningtree committed Oct 24, 2023
1 parent a737565 commit 512668e
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
.sl
output
output
.cache
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ consolidate:
mkdir ./output/data
cp ./dist/bundle.json ./output/data/index.json

extend:
deno run --unstable --allow-read --allow-write --allow-net utils/extend.js

fmt:
deno fmt utils/*.js
4 changes: 3 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ collections:
companies: {}
people:
model: person
projects: {}
projects: {}
extenders:
eips: {}
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion data/people/mario-havel/index.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: Mario Havel
links:
twitter: https://twitter.com/TMIYChao
twitter: https://twitter.com/TMIYChao
github: https://github.com/taxmeifyoucan
3 changes: 3 additions & 0 deletions data/people/micah-zoltu/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: Micah Zoltu
links:
github: https://github.com/MicahZoltu
4 changes: 4 additions & 0 deletions data/people/peter-szilagyi/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: Péter Szilágyi
emails:
- [email protected]
- [email protected]
6 changes: 5 additions & 1 deletion data/people/vitalik-buterin/index.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
name: Vitalik Buterin
links:
twitter: https://twitter.com/VitalikButerin
github: https://github.com/vbuterin
twitter: https://twitter.com/VitalikButerin
emails:
- [email protected]
- [email protected]
5 changes: 5 additions & 0 deletions data/projects/eas/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: Ethereum Attestation Service
abbreviations:
- EAS
links:
web: https://attest.sh/
7 changes: 6 additions & 1 deletion schema/person.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ properties:
type: object
additionalProperties:
type: string
format: uri
format: uri
emails:
type: array
items:
type: string
format: email
44 changes: 44 additions & 0 deletions utils/extend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Engine from "./engine.js";
import cheerio from "npm:[email protected]";
import { ensureDir, exists } from "https://deno.land/[email protected]/fs/mod.ts";

const e = new Engine();
await e.init();

const CACHE_DIR = "./.cache";

const tools = {
async loadHtmlUrl(url) {
await ensureDir(CACHE_DIR);
const hash = Array.from(
new Uint8Array(
await crypto.subtle.digest("SHA-256", (new TextEncoder()).encode(url)),
),
).map((b) => b.toString(16).padStart(2, "0")).join("");
const cacheFn = `${CACHE_DIR}/${hash}`;

if (await exists(cacheFn)) {
console.log(`Cache found! ${hash}`);
return cheerio.load(await Deno.readTextFile(cacheFn));
}

console.log(`Getting ${url}`);
const resp = await fetch(url, {
headers: {
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15",
},
});
const output = await resp.text();
await Deno.writeTextFile(cacheFn, output);
return cheerio.load(output);
}
}

for (const extId in e.config.extenders) {
console.log(`Running extender: ${extId}`)
const ext = await import(`./extenders/${extId}.js`)
await ext.process(e, tools)
}

console.log(`Extending done`)
83 changes: 83 additions & 0 deletions utils/extenders/eips.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
export async function process(db, _) {
const authors = {}
const $ = await _.loadHtmlUrl("https://eips.ethereum.org/all")
for (const el of $('table.eiptable tr').toArray()) {
const eipnum = $('td.eipnum a', el).text()
for (const a of $('td.author', el).text().split(', ')) {
if (!a) {
continue
}
if (!authors[a]) {
authors[a] = []
}
authors[a].push(eipnum)
}
}

const matrix = []

for (const a of Object.keys(authors)) {
const info = {}

// name
const nameMatch = a.match(/^([^<^\()]+)/)
if (!nameMatch) {
console.log(`Bad name? ${a}`)
}
info.name = nameMatch[1].trim()

// github handle
const ghMatch = a.match(/\(@([^\)]+)\)/)
if (ghMatch) {
info.github = ghMatch[1]
}
// email
const emailMatch = a.match(/<([^>]+)>/)
if (emailMatch) {
info.email = emailMatch[1]
}
//console.log(`${a} - ${JSON.stringify(info)}`)

const dbFind = db.collections.people.find(p => {
if (info.github && p.index.links?.github?.toLowerCase() === `https://github.com/${info.github.toLowerCase()}`) {
return true
}
if (info.email && p.index.emails?.includes(info.email)) {
return true
}
})
if (dbFind) {
let matrixItem = matrix.find(mi => mi.slug === dbFind.index.slug)
if (!matrixItem) {
matrixItem = {
slug: dbFind.index.slug,
info,
eips: [],
}
matrix.push(matrixItem)
}
matrixItem.eips = matrixItem.eips.concat(authors[a]).sort()
} else {
matrix.push({
slug: null,
info,
eips: authors[a]
})
}
//console.log(`${info.name} -> ${dbFind ? dbFind.index.slug : 'x'}`)
}
//console.log(matrix)

// finishing, modify or create people

for (const p of matrix) {
if (p.slug) {
console.log(`${p.info.name} => ${p.slug} (auto)`)
continue
}
const duplicates = []

console.log(`-----\n${p.info.name} (${JSON.stringify(p)})\n`)
prompt("Do you want to create new one?")
}
}
2 changes: 1 addition & 1 deletion web/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const bundle = await loadBundle();
<ul>
{config.categories.map((cat) => (
<li class="text-xl mb-3">
<a href={`/category/${cat.col}`} class="hover:underline">{cat.name}</a> ({bundle.data[cat.col]?.length})
<a href={`/category/${cat.col}`} class="hover:underline">{cat.name}</a>
</li>
))}
</ul>
Expand Down
4 changes: 4 additions & 0 deletions web/src/pages/[id].astro
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ const item = bundle.data[catData.col].find(i => i.slug === Astro.params.id)

<Layout>
<h1 class="text-4xl">{item.name}</h1>
<div class="mt-4">{item.description}</div>

<pre class="bg-gray-200 mt-20 p-4 text-sm mb-4"><code>{JSON.stringify(item, null, 2)}</code></pre>

<a href={`https://github.com/ethereumeg/ethcd/edit/main/data/${catData.col}/${item.slug}/index.yaml`}>Edit this item</a>
</Layout>

0 comments on commit 512668e

Please sign in to comment.