Skip to content

Commit edf3871

Browse files
committed
fix formatting
1 parent 57590ef commit edf3871

File tree

4 files changed

+63
-35
lines changed

4 files changed

+63
-35
lines changed

.github/workflows/import-community-events.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
- uses: EndBug/add-and-commit@v9
2121
with:
2222
default_author: github_actions
23-
message: 'Update community events'
23+
message: "Update community events"

src/data/community-events.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,4 +545,4 @@
545545
"description": "Bringing developers onchain to build the future of the internet.",
546546
"imageUrl": "https://ethglobal.com/og.png"
547547
}
548-
]
548+
]

src/scripts/events-import.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,57 @@
1-
import { EthereumEventsImport } from "./events/ethereum-events-import"
1+
import fs from "fs"
2+
import path from "path"
3+
24
import { CommunityConference } from "@/lib/types"
5+
36
import localEvents from "../data/community-events.json"
4-
import fs from "fs"
5-
;import path from "path"
67

7-
import "dotenv/config"
8+
import { EthereumEventsImport } from "./events/ethereum-events-import"
89

10+
import "dotenv/config"
911

10-
(async () => {
12+
;(async () => {
1113
const communityEvents = localEvents as CommunityConference[]
1214

1315
console.log("Community Events Import..")
1416
const ethereumEvents = await EthereumEventsImport()
1517
// Can add multiple event sources here in the future
1618

1719
ethereumEvents.forEach((imported) => {
18-
const id = communityEvents.findIndex((local) => tryMatchEvent(imported, local))
20+
const id = communityEvents.findIndex((local) =>
21+
tryMatchEvent(imported, local)
22+
)
1923
if (id > -1) {
2024
const local = communityEvents[id]
21-
if (imported.imageUrl && !local.imageUrl) local.imageUrl = imported.imageUrl
22-
if (imported.description && !local.description) local.description = imported.description
25+
if (imported.imageUrl && !local.imageUrl)
26+
local.imageUrl = imported.imageUrl
27+
if (imported.description && !local.description)
28+
local.description = imported.description
2329
} else {
2430
communityEvents.push(imported)
2531
}
2632
})
2733

2834
// Write to Events.json
29-
const eventsPath = path.join(__dirname, '..', 'data/community-events.json')
35+
const eventsPath = path.join(__dirname, "..", "data/community-events.json")
3036
fs.writeFileSync(eventsPath, JSON.stringify(communityEvents, null, 2))
31-
3237
})()
3338

34-
function tryMatchEvent(imported: CommunityConference, local: CommunityConference) {
35-
if (imported.title.toLocaleLowerCase() === local.title.toLocaleLowerCase()) return true
36-
37-
if (URL.canParse(imported.to) && URL.canParse(local.to)
38-
&& new URL(imported.to).hostname.replace('www.', '') === new URL(local.to).hostname.replace('www.', '')
39-
&& new URL(imported.to).pathname === new URL(local.to).pathname) {
40-
return true
39+
function tryMatchEvent(
40+
imported: CommunityConference,
41+
local: CommunityConference
42+
) {
43+
if (imported.title.toLocaleLowerCase() === local.title.toLocaleLowerCase())
44+
return true
45+
46+
if (
47+
URL.canParse(imported.to) &&
48+
URL.canParse(local.to) &&
49+
new URL(imported.to).hostname.replace("www.", "") ===
50+
new URL(local.to).hostname.replace("www.", "") &&
51+
new URL(imported.to).pathname === new URL(local.to).pathname
52+
) {
53+
return true
4154
}
4255

4356
return false
44-
}
57+
}

src/scripts/events/ethereum-events-import.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
import { CommunityConference } from "@/lib/types"
2+
23
import "dotenv/config"
34

4-
async function getPageMetadata(url: string): Promise<Record<string, string>> {
5+
async function getPageMetadata(url: string): Promise<Record<string, string>> {
56
try {
67
const metaTags: Record<string, string> = {}
78
const text = await fetch(url).then((r) => r.text())
8-
9-
const description = text.match(/<meta.*?name="description".*?content="(.*?)".*?>|<meta.*?content="(.*?)".*?name="description".*?>/i)
10-
if (description && Array.from(description).length > 2) metaTags['description'] = Array.from(description)[1]
119

12-
const tags = text.matchAll(/<meta (property|name)="(og|twitter):(\S+)" content="(\S+)"/gm)
10+
const description = text.match(
11+
/<meta.*?name="description".*?content="(.*?)".*?>|<meta.*?content="(.*?)".*?name="description".*?>/i
12+
)
13+
if (description && Array.from(description).length > 2)
14+
metaTags["description"] = Array.from(description)[1]
15+
16+
const tags = text.matchAll(
17+
/<meta (property|name)="(og|twitter):(\S+)" content="(\S+)"/gm
18+
)
1319
for (const matchGroup of Array.from(tags)) {
1420
const key = matchGroup[3]
1521
const value = matchGroup[4]
1622
if (key && value) metaTags[key] = value
1723
}
18-
24+
1925
return metaTags
2026
} catch (error) {
21-
console.error('Unable to fetch metadata', url)
27+
console.error("Unable to fetch metadata", url)
2228
return {}
2329
}
2430
}
@@ -51,7 +57,13 @@ export async function EthereumEventsImport() {
5157
const link: string = data.values[4][i]
5258

5359
if (!title || !startDate || !endDate || !location) continue
54-
if (startDate.includes("TBD") || endDate.includes("TBD") || !startDate.includes(' ') || !endDate.includes(' ')) continue
60+
if (
61+
startDate.includes("TBD") ||
62+
endDate.includes("TBD") ||
63+
!startDate.includes(" ") ||
64+
!endDate.includes(" ")
65+
)
66+
continue
5567

5668
let start, end
5769
try {
@@ -64,20 +76,23 @@ export async function EthereumEventsImport() {
6476
}
6577

6678
let websiteUrl = link
67-
let description = ''
68-
let imageUrl = ''
79+
let description = ""
80+
let imageUrl = ""
6981
if (link) {
70-
websiteUrl = link.startsWith('https://') || link.startsWith('http://') ? link : `https://${link}`
82+
websiteUrl =
83+
link.startsWith("https://") || link.startsWith("http://")
84+
? link
85+
: `https://${link}`
7186
const meta = await getPageMetadata(websiteUrl)
72-
87+
7388
if (meta.description) description = meta.description
74-
if (meta.image && meta.image.startsWith('http')) imageUrl = meta.image
89+
if (meta.image && meta.image.startsWith("http")) imageUrl = meta.image
7590
}
7691

7792
events.push({
7893
title: title,
79-
startDate: new Date(start).toISOString().substring(0,10),
80-
endDate: new Date(end).toISOString().substring(0,10),
94+
startDate: new Date(start).toISOString().substring(0, 10),
95+
endDate: new Date(end).toISOString().substring(0, 10),
8196
to: websiteUrl,
8297
location: location,
8398
description: description,

0 commit comments

Comments
 (0)