Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,451 additions
and
403 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
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 was deleted.
Oops, something went wrong.
Binary file not shown.
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,61 @@ | ||
|
||
import path from 'path' | ||
import chromium from 'chrome-aws-lambda' | ||
import ejs from 'ejs' | ||
|
||
import { isDev, domain } from '../../utils/variables' | ||
|
||
// Use different options depending on the environment | ||
const getOptions = async () => { | ||
if (isDev) { | ||
// Path to local chrome executable on different platforms | ||
const chromeExecutables: { [key: string]: string } = { | ||
linux: '/usr/bin/chromium-browser', | ||
win32: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe', | ||
darwin: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' | ||
} | ||
|
||
return { | ||
args: [ '--no-sandbox' ], | ||
executablePath: chromeExecutables[process.platform] || chromeExecutables.linux, | ||
headless: true | ||
} | ||
} | ||
|
||
// Else, use the path of chrome-aws-lambda and its args | ||
return { | ||
args: chromium.args, | ||
executablePath: await chromium.executablePath, | ||
headless: chromium.headless | ||
} | ||
} | ||
|
||
export const generateSocialImage = async (title: string, description: string, icon: string) => { | ||
// Inflate chrome and get options | ||
const opts = await getOptions() | ||
|
||
// Load noto-emoji font | ||
await chromium.font(path.join(__dirname, 'NotoColorEmoji.ttf')) | ||
|
||
// Launch browser | ||
const browser = await chromium.puppeteer.launch(opts) | ||
|
||
// Create new page | ||
const page = await browser.newPage() | ||
await page.setViewport({ | ||
width: 1200, | ||
height: 628 | ||
}) | ||
|
||
// Load the template into the page | ||
const data = { title, description, icon, domain } | ||
const html = await ejs.renderFile(path.join(__dirname, 'template.ejs'), data) | ||
await page.setContent(html, { waitUntil: 'domcontentloaded' }) | ||
|
||
// Take a screenshot of the page | ||
const image = await page.screenshot() | ||
|
||
await browser.close() | ||
|
||
return image | ||
} |
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,98 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
</head> | ||
<body> | ||
<main id="wrapper"> | ||
<div class="content"> | ||
<h1 class="title"><%= icon %> <%= title %></h1> | ||
<p class="description"><%= description %></p> | ||
<p class="domain"><%= domain %></p> | ||
</div> | ||
<div class="logo"> | ||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="53" height="53" viewBox="0 0 53 53"> | ||
<defs> | ||
<linearGradient id="linear-gradient" x1="0.5" x2="0.5" y2="1" gradientUnits="objectBoundingBox"> | ||
<stop offset="0" stop-color="#f5be6b"/> | ||
<stop offset="1" stop-color="#df9930"/> | ||
</linearGradient> | ||
</defs> | ||
<g id="Rechteck_532" data-name="Rechteck 532" stroke="#f5be6b" stroke-width="10" fill="url(#linear-gradient)"> | ||
<rect width="53" height="53" rx="8" stroke="none"/> | ||
<rect x="5" y="5" width="43" height="43" rx="3" fill="none"/> | ||
</g> | ||
</svg> | ||
<span>WebCrate</span> | ||
</div> | ||
</main> | ||
|
||
<style> | ||
:root { | ||
/* Colors */ | ||
--background: #fff; | ||
--background-2nd: #F7F6F4; | ||
--grey: #E8E8E8; | ||
--grey-light: #EEEEEE; | ||
--grey-2nd: #cac9c9; | ||
--text: #474440; | ||
--text-light: #7B7B7B; | ||
--text-dark:#242221; | ||
--accent: #F5BE6B; | ||
--accent-dark: #efa83d; | ||
--red: rgb(197, 63, 63); | ||
--red-light: rgb(230, 104, 104); | ||
--red-dark: rgb(146, 40, 40); | ||
--green: rgb(123, 217, 147); | ||
/* Values */ | ||
--border-radius: 8px; | ||
--click-scale-factor: 0.95; | ||
} | ||
#wrapper { | ||
font-family: "Source Sans Pro",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif; | ||
width: 1200px; | ||
height: 628px; | ||
background: var(--background-2nd); | ||
padding: 10rem; | ||
box-sizing: border-box; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
position: relative; | ||
font-size: 20px; | ||
} | ||
.title { | ||
margin-bottom: 0.5rem; | ||
} | ||
.description { | ||
color: var(--text-light); | ||
} | ||
.domain { | ||
color: var(--accent-dark); | ||
} | ||
.logo { | ||
position: absolute; | ||
bottom: 5rem; | ||
right: 10rem; | ||
display: flex; | ||
align-items: center; | ||
} | ||
.logo span { | ||
font-size: 2rem; | ||
font-weight: 600; | ||
margin-left: 1rem; | ||
color: #474440; | ||
} | ||
</style> | ||
</body> | ||
</html> |
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,5 @@ | ||
|
||
export const isDev = process.env.DETA_RUNTIME !== 'True' && process.env.DETA_RUNTIME !== 'true' | ||
export const isSpace = process.env.DETA_SPACE_APP === 'True' || process.env.DETA_SPACE_APP === 'true' | ||
export const subdomain = process.env.DETA_PATH | ||
export const domain = isDev ? 'localhost:3000' : `${ subdomain }.${ isSpace ? 'deta.app' : 'deta.dev' }` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.