-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* layout groups * hover fic projects * fetch from supabase and basic layout * why now? * maybe ? * another one * aaaaaah * finally * get address * i18n * i18n fixes * more * one more * move i18n to the server * more finetuning, image generation * card flipping, save image in sb * more translations * fine tuning * fix background * more fixes * scrollable card content
- Loading branch information
1 parent
3c36d49
commit ed56353
Showing
36 changed files
with
1,726 additions
and
999 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,55 @@ | ||
import fetch from 'node-fetch'; | ||
import OpenAI from "openai" | ||
import { createClient } from '@supabase/supabase-js' | ||
|
||
const openai = new OpenAI({apiKey: process.env.OPENAI_API_KEY}) | ||
const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_API_KEY) | ||
|
||
async function _fetchCards() { | ||
const { data, error } = await supabase.from('cards').select('*').eq('image_url', null); | ||
console.log('Cards fetched: ', data.length) | ||
if (error) throw new Error(`error`) | ||
if (!data) throw new Error('No data: ', data) | ||
return data.map(({uuid, name, content, language}) => { | ||
return { | ||
uuid, | ||
name, | ||
content, | ||
language, | ||
} | ||
}) | ||
} | ||
|
||
async function _generateImage(name) { | ||
const image = await openai.images.generate({ | ||
model: "dall-e-3", | ||
prompt: `abstract layered christmas themed with light refracting , very cool subtle minimal christmas illustration, christmas red with subtle highlights. each image is unique for a user, use their name in some way to make it more personal, it doesnt has to be integrated directly: ${name}`, | ||
n: 1, | ||
size: "1024x1024", | ||
}) | ||
return image.data[0].url | ||
} | ||
|
||
async function _fetchImage(imageUrl) { | ||
const response = await fetch(imageUrl); | ||
if (!response.ok) throw new Error('Failed to fetch image'); | ||
return await response.buffer(); | ||
} | ||
|
||
async function _saveImage(blob, uuid) { | ||
const { data, error } = await supabase.storage.from('cards').upload(`${uuid}.jpg`, blob); | ||
if (error) throw new Error('Failed to upload image: ', error); | ||
const imageUrl = `${process.env.SUPABASE_URL}/storage/v1/object/public/${data.fullPath}` | ||
await supabase.from('cards').update({image_url: imageUrl}).eq('uuid', uuid); | ||
} | ||
|
||
async function main() { | ||
const cards = await _fetchCards() | ||
cards.forEach(async (card) => { | ||
const imageUrl = await _generateImage(card.name) | ||
const blob = await _fetchImage(imageUrl) | ||
await _saveImage(blob, card.uuid) | ||
}) | ||
} | ||
|
||
main() |
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,27 @@ | ||
/* * { | ||
outline: 1px solid rgba(255, 0, 0, 0.25); | ||
} */ | ||
|
||
html { | ||
scroll-behavior: smooth; | ||
} | ||
|
||
body { | ||
-webkit-font-smoothing: antialiased; | ||
background: var(--c-light); | ||
color: var(--c-font); | ||
font-size: 125%; | ||
font-family: var(--font-family); | ||
} | ||
|
||
:any-link { | ||
text-decoration-thickness: var(--underline-thickness); | ||
} | ||
|
||
* { | ||
scroll-margin: var(--xl); | ||
overflow-wrap: break-word; | ||
word-wrap: break-word; | ||
word-break: break-word; | ||
hyphens: auto; | ||
} |
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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
<ul> | ||
<li>Name: Luka Harambasic</li> | ||
<li> | ||
E-Mail: <a href="[email protected]">[email protected]</a> | ||
E-Mail: <a href="mailto:[email protected]">[email protected]</a> | ||
</li> | ||
</ul> | ||
<h3>Graphics and Image Sources</h3> | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,72 @@ | ||
import { createClient } from '@supabase/supabase-js' | ||
import type { EntryGenerator, RouteParams } from './$types'; | ||
import { t } from './i18n'; | ||
|
||
const supabase = createClient( | ||
'https://xqlghnitokncvzvxoiyq.supabase.co', | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InhxbGdobml0b2tuY3Z6dnhvaXlxIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTY4MzQyMzYwNSwiZXhwIjoxOTk4OTk5NjA1fQ.QzoaOpgNPQF32zJl5c-Olx6ZEhw03M5mkbAA_zkBrT8' | ||
) | ||
|
||
interface Card { | ||
slug: string, | ||
name: string, | ||
content: string, | ||
language: string, | ||
imageUrl: string, | ||
} | ||
|
||
async function fetchCards(): Promise<Card[]> { | ||
const { data, error } = await supabase.from('cards').select('*') | ||
if (error) { | ||
throw new Error(`error`) | ||
} | ||
if (!data) { | ||
throw new Error('No data: data') | ||
} | ||
return data.map(({uuid, name, content, language, image_url}) => { | ||
return { | ||
slug: uuid, | ||
name, | ||
content, | ||
language, | ||
imageUrl: image_url, | ||
} | ||
}) | ||
} | ||
|
||
function getCardBySlug(slug: string, cards: Card[]): Card | undefined { | ||
return cards.find((card) => card!.slug === slug) | ||
} | ||
|
||
function getEntries(cards: Card[]): RouteParams[] { | ||
return cards.map(({slug}) => ({ slug })) | ||
} | ||
|
||
export const load = async ({params}) => { | ||
const cards = await fetchCards() | ||
const card = getCardBySlug(params.slug, cards) | ||
return { | ||
name: card!.name, | ||
language: card!.language, | ||
slug: card!.slug, | ||
content: card!.content, | ||
imageUrl: card!.imageUrl, | ||
greeting: t('greeting', card!.language, card!.name), | ||
farewell: t('farewell', card!.language), | ||
fullTitle: t('title', card!.language, card!.name), | ||
description: t('description', card!.language), | ||
socialImg: t('socialImg', card!.language), | ||
socialImgAlt: t('socialImgAlt', card!.language), | ||
frontTitle: t('frontTitle', card!.language, card!.name), | ||
frontGenerated: t('frontGenerated', card!.language, card!.name), | ||
footerGenerated: t('footerGenerated', card!.language, card!.name), | ||
footerBy: t('footerBy', card!.language), | ||
} | ||
} | ||
|
||
export const entries: EntryGenerator = async () => { | ||
const cards = await fetchCards() | ||
return getEntries(cards) | ||
} | ||
|
||
export const prerender = true |
Oops, something went wrong.