1
1
import React from "react"
2
- import LayoutConf from "../../components/Conf/Layout"
3
- import HeaderConf from "../../components/Conf/Header"
2
+ import LayoutConf from "../../../ components/Conf/Layout"
3
+ import HeaderConf from "../../../ components/Conf/Header"
4
4
// import ButtonConf from "../../components/Conf/Button"
5
5
import clsx from "clsx"
6
6
import { PageProps , HeadProps } from "gatsby"
7
- import SeoConf from "../../components/Conf/Seo"
8
- import { useLocation } from "@reach/router"
7
+ import SeoConf from "../../../components/Conf/Seo"
9
8
10
- export default ( _props : PageProps ) => {
11
- const { href , search } = useLocation ( )
9
+ export default ( { location , params } : PageProps ) => {
10
+ const search = getSeachParams ( params . hash )
12
11
// const text = "Nice! I got my @GraphQLConf ticket! Get yours too!"
13
12
return (
14
13
< LayoutConf >
@@ -30,7 +29,7 @@ export default (_props: PageProps) => {
30
29
) }
31
30
onClick = { async ( ) => {
32
31
try {
33
- await navigator . clipboard . writeText ( href )
32
+ await navigator . clipboard . writeText ( location . href )
34
33
console . log ( "Content copied to clipboard" )
35
34
} catch ( err ) {
36
35
console . error ( "Failed to copy:" , err )
@@ -42,22 +41,53 @@ export default (_props: PageProps) => {
42
41
</ div >
43
42
</ section >
44
43
</ div >
45
- < img
46
- src = { `https://og-image.the-guild.dev/conf${ search } ` }
47
- className = "block mx-auto"
48
- />
44
+ { search && (
45
+ < img
46
+ src = { `https://og-image.the-guild.dev/conf${ search } ` }
47
+ className = "block mx-auto"
48
+ />
49
+ ) }
49
50
</ div >
50
51
</ LayoutConf >
51
52
)
52
53
}
53
54
54
- export function Head ( _props : HeadProps ) {
55
- const { search } = useLocation ( )
55
+ function getSeachParams ( base64 : string ) : string {
56
+ let string : string
57
+ try {
58
+ string = atob ( base64 )
59
+ } catch ( error ) {
60
+ console . log ( error )
61
+ return ""
62
+ }
63
+
64
+ let list : string [ ] = [ ]
65
+
66
+ try {
67
+ list = JSON . parse ( string )
68
+ } catch ( error ) {
69
+ console . log ( error )
70
+ return ""
71
+ }
72
+
73
+ const [ fullName , jobTitle , company , github ] = list
74
+ const searchParams = new URLSearchParams ( {
75
+ ...( fullName && { fullName } ) ,
76
+ ...( jobTitle && { jobTitle } ) ,
77
+ ...( company && { company } ) ,
78
+ ...( github && { github } ) ,
79
+ } )
80
+ return "?" + searchParams . toString ( )
81
+ }
82
+
83
+ export function Head ( { params } : HeadProps & { hash : string } ) {
56
84
return (
57
85
< SeoConf
58
86
title = "My ticket"
59
87
ogImage = { {
60
- url : `https://og-image.the-guild.dev/conf${ search } ` ,
88
+ url : `https://og-image.the-guild.dev/conf${ getSeachParams (
89
+ params . hash
90
+ ) } `,
61
91
width : 1200 ,
62
92
height : 600 ,
63
93
} }
0 commit comments