1
1
import { CommunityConference } from "@/lib/types"
2
+
2
3
import "dotenv/config"
3
4
4
- async function getPageMetadata ( url : string ) : Promise < Record < string , string > > {
5
+ async function getPageMetadata ( url : string ) : Promise < Record < string , string > > {
5
6
try {
6
7
const metaTags : Record < string , string > = { }
7
8
const text = await fetch ( url ) . then ( ( r ) => r . text ( ) )
8
-
9
- const description = text . match ( / < m e t a .* ?n a m e = " d e s c r i p t i o n " .* ?c o n t e n t = " ( .* ?) " .* ?> | < m e t a .* ?c o n t e n t = " ( .* ?) " .* ?n a m e = " d e s c r i p t i o n " .* ?> / i)
10
- if ( description && Array . from ( description ) . length > 2 ) metaTags [ 'description' ] = Array . from ( description ) [ 1 ]
11
9
12
- const tags = text . matchAll ( / < m e t a ( p r o p e r t y | n a m e ) = " ( o g | t w i t t e r ) : ( \S + ) " c o n t e n t = " ( \S + ) " / gm)
10
+ const description = text . match (
11
+ / < m e t a .* ?n a m e = " d e s c r i p t i o n " .* ?c o n t e n t = " ( .* ?) " .* ?> | < m e t a .* ?c o n t e n t = " ( .* ?) " .* ?n a m e = " d e s c r i p t i o n " .* ?> / i
12
+ )
13
+ if ( description && Array . from ( description ) . length > 2 )
14
+ metaTags [ "description" ] = Array . from ( description ) [ 1 ]
15
+
16
+ const tags = text . matchAll (
17
+ / < m e t a ( p r o p e r t y | n a m e ) = " ( o g | t w i t t e r ) : ( \S + ) " c o n t e n t = " ( \S + ) " / gm
18
+ )
13
19
for ( const matchGroup of Array . from ( tags ) ) {
14
20
const key = matchGroup [ 3 ]
15
21
const value = matchGroup [ 4 ]
16
22
if ( key && value ) metaTags [ key ] = value
17
23
}
18
-
24
+
19
25
return metaTags
20
26
} catch ( error ) {
21
- console . error ( ' Unable to fetch metadata' , url )
27
+ console . error ( " Unable to fetch metadata" , url )
22
28
return { }
23
29
}
24
30
}
@@ -51,7 +57,13 @@ export async function EthereumEventsImport() {
51
57
const link : string = data . values [ 4 ] [ i ]
52
58
53
59
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
55
67
56
68
let start , end
57
69
try {
@@ -64,20 +76,23 @@ export async function EthereumEventsImport() {
64
76
}
65
77
66
78
let websiteUrl = link
67
- let description = ''
68
- let imageUrl = ''
79
+ let description = ""
80
+ let imageUrl = ""
69
81
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 } `
71
86
const meta = await getPageMetadata ( websiteUrl )
72
-
87
+
73
88
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
75
90
}
76
91
77
92
events . push ( {
78
93
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 ) ,
81
96
to : websiteUrl ,
82
97
location : location ,
83
98
description : description ,
0 commit comments