Skip to content

Commit

Permalink
feat: add Support Me button
Browse files Browse the repository at this point in the history
  • Loading branch information
mk965 committed Jun 29, 2024
1 parent c13b956 commit 162a4cf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions components/Ko-fi.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useEffect } from 'react'
import { siteMetadata } from '~/data/siteMetadata'

export default function Kofi() {
useEffect(() => {
if (!siteMetadata.kofiName) return () => {}
const script = document.createElement('script')
script.src = 'https://storage.ko-fi.com/cdn/scripts/overlay-widget.js'
script.onload = () => {
if ((window as any).kofiWidgetOverlay) {
;(window as any).kofiWidgetOverlay.draw(siteMetadata.kofiName, {
type: 'floating-chat',
'floating-chat.donateButton.text': 'Support me',
'floating-chat.donateButton.background-color': '#00b9fe',
'floating-chat.donateButton.text-color': '#fff',
})
}
}
document.body.appendChild(script)

// Clean up the script if the component is unmounted
return () => {
document.body.removeChild(script)
}
}, [])

return <></>
}
2 changes: 2 additions & 0 deletions components/LayoutWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Footer } from './Footer'
import { Header } from './Header'
import { MobileNav } from './MobileNav'
import { SpeedInsights } from '@vercel/speed-insights/next'
import Kofi from './Ko-fi'

export function LayoutWrapper({ children }) {
let [navShow, setNavShow] = useState(false)
Expand All @@ -20,6 +21,7 @@ export function LayoutWrapper({ children }) {
</div>
</div>
<SpeedInsights />
<Kofi />
</>
)
}
1 change: 1 addition & 0 deletions data/siteMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export let siteMetadata = {
linkedin: 'mengke',
instagram: '_mk965',
},
kofiName: 'mengke',
}

/**
Expand Down

0 comments on commit 162a4cf

Please sign in to comment.