-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dynamic map location merchant page og images
- Loading branch information
1 parent
92c5cef
commit cf15051
Showing
13 changed files
with
322 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ LNBITS_WALLET_ID= | |
OPENCAGE_API_KEY= | ||
SERVER_CRYPTO_KEY= | ||
SERVER_INIT_VECTOR= | ||
STADIA_API_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ node_modules | |
!.env.example | ||
vite.config.js.timestamp-* | ||
vite.config.ts.timestamp-* | ||
.netlify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
[build] | ||
command = "yarn build" | ||
publish = "build" | ||
|
||
[images] | ||
remote_images = ["https://static.btcmap.org/images/communities/.*", "https://www.openstreetmap.org/.*", "https://avatars.githubusercontent.com/.*" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script lang="ts"> | ||
export let lat: string; | ||
export let lon: string; | ||
export let STADIA_API_KEY: string; | ||
</script> | ||
|
||
<img | ||
src="https://tiles.stadiamaps.com/static_cacheable/osm_bright.png?size=600x315@2x&markers={lat},{lon},custom:https://btcmap.org/icons/og-marker.png,,,,-16,-43&api_key={STADIA_API_KEY}" | ||
alt="merchant location" | ||
width="1200" | ||
height="630" | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { read } from '$app/server'; | ||
import { Resvg } from '@resvg/resvg-js'; | ||
import satori from 'satori'; | ||
import { html as toReactNode } from 'satori-html'; | ||
import Manrope from '/static/fonts/Manrope-Regular.ttf'; | ||
|
||
const fontData = read(Manrope).arrayBuffer(); | ||
|
||
const height = 630; | ||
const width = 1200; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const generateImage = async (component: any) => { | ||
const jsx = toReactNode(`${component.html}<style>${component.css.code}</style>`); | ||
|
||
const svg = await satori(jsx, { | ||
fonts: [ | ||
{ | ||
name: 'Manrope', | ||
data: await fontData, | ||
style: 'normal' | ||
} | ||
], | ||
height, | ||
width | ||
}); | ||
|
||
const resvg = new Resvg(svg, { | ||
fitTo: { | ||
mode: 'width', | ||
value: width | ||
} | ||
}); | ||
|
||
const image = resvg.render(); | ||
|
||
return image.asPng(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { STADIA_API_KEY } from '$env/static/private'; | ||
import { MerchantOG } from '$lib/comp'; | ||
import { generateImage } from '../generateImage'; | ||
import type { RequestHandler } from './$types'; | ||
|
||
export const GET: RequestHandler = async ({ url }) => { | ||
const lat = url.searchParams.get('lat'); | ||
const lon = url.searchParams.get('lon'); | ||
|
||
if (!lat || !lon) return new Response(undefined, { status: 418 }); | ||
|
||
const component = MerchantOG.render({ lat, lon, STADIA_API_KEY }); | ||
|
||
const image = await generateImage(component); | ||
|
||
return new Response(image, { | ||
headers: { | ||
'content-type': 'image/png', | ||
'cache-control': 'max-age=31449600' | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.