diff --git a/.gitignore b/.gitignore index 76add878f..2ad7ce48b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -dist \ No newline at end of file +api/dist +public/dist \ No newline at end of file diff --git a/.nowignore b/.nowignore index 7d947931c..77592a1c9 100644 --- a/.nowignore +++ b/.nowignore @@ -1,5 +1,6 @@ node_modules -dist +api/dist +public/dist CONTRIBUTING.md README.md Dockerfile diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1fb09b809..a2617dcf3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,8 +2,8 @@ There are two pieces to `og-image` that are worth noting before you begin development. -1. The backend image generator located in [/src/card.ts](https://github.com/zeit/og-image/blob/master/src/card.ts) -2. The frontend inputs located in [/src/browser.ts](https://github.com/zeit/og-image/blob/master/src/browser.ts) +1. The backend image generator located in [/api/index.ts](https://github.com/zeit/og-image/blob/master/api/index.ts) +2. The frontend inputs located in [/web/index.ts](https://github.com/zeit/og-image/blob/master/web/index.ts) The Now 2.0 platform handles [routing](https://github.com/zeit/og-image/blob/master/now.json#L12) in an elegate way for us so deployment is easy. diff --git a/README.md b/README.md index 20f8b573d..469e94b7f 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ You'll want to fork this repository and deploy your own image generator. 4. Make changes by swapping out images, changing colors, etc (see [contributing](https://github.com/zeit/og-image/blob/master/CONTRIBUTING.md) for more info) 5. Run locally with `now dev` and visit [localhost:3000](http://localhost:3000) (if nothing happens, run `npm install -g now`) 6. Deploy to the cloud by running `now` and you'll get a unique URL -7. Setup [GitHub](https://zeit.co/github) to autodeply on push and set an `alias` in [now.json](https://zeit.co/github) to customize your URL. +7. Setup [GitHub](https://zeit.co/github) to autodeply on push and set an `alias` in [now.json](https://zeit.co/docs/v2/advanced/configuration) to customize your URL. Alternatively, you can do a one-click to deploy with the button below. diff --git a/src/chromium.ts b/api/chromium.ts similarity index 94% rename from src/chromium.ts rename to api/chromium.ts index 2c36d0f12..4ce68109a 100644 --- a/src/chromium.ts +++ b/api/chromium.ts @@ -1,5 +1,6 @@ import { launch, Page } from 'puppeteer-core'; import { getOptions } from './options'; +import { FileType } from './types'; let _page: Page | null; async function getPage(isDev: boolean) { diff --git a/src/file.ts b/api/file.ts similarity index 100% rename from src/file.ts rename to api/file.ts diff --git a/src/card.ts b/api/index.ts similarity index 100% rename from src/card.ts rename to api/index.ts diff --git a/src/options.ts b/api/options.ts similarity index 100% rename from src/options.ts rename to api/options.ts diff --git a/src/parser.ts b/api/parser.ts similarity index 97% rename from src/parser.ts rename to api/parser.ts index d53c6c481..4e36933c9 100644 --- a/src/parser.ts +++ b/api/parser.ts @@ -1,5 +1,6 @@ import { IncomingMessage } from 'http'; import { parse } from 'url'; +import { ParsedRequest, Theme } from './types'; export function parseRequest(req: IncomingMessage) { console.log('HTTP ' + req.url); diff --git a/src/sanitizer.ts b/api/sanitizer.ts similarity index 100% rename from src/sanitizer.ts rename to api/sanitizer.ts diff --git a/src/template.ts b/api/template.ts similarity index 92% rename from src/template.ts rename to api/template.ts index f61e0d05f..65ec2ca48 100644 --- a/src/template.ts +++ b/api/template.ts @@ -2,13 +2,14 @@ import { readFileSync } from 'fs'; import marked from 'marked'; import { sanitizeHtml } from './sanitizer'; +import { ParsedRequest } from './types'; const twemoji = require('twemoji'); const twOptions = { folder: 'svg', ext: '.svg' }; const emojify = (text: string) => twemoji.parse(text, twOptions); -const regular = readFileSync(`${__dirname}/../.fonts/Inter-Regular.woff2`).toString('base64'); -const bold = readFileSync(`${__dirname}/../.fonts/Inter-Bold.woff2`).toString('base64'); -const mono = readFileSync(`${__dirname}/../.fonts/Vera-Mono.woff2`).toString('base64'); +const regular = readFileSync(`${__dirname}/../fonts/Inter-Regular.woff2`).toString('base64'); +const bold = readFileSync(`${__dirname}/../fonts/Inter-Bold.woff2`).toString('base64'); +const mono = readFileSync(`${__dirname}/../fonts/Vera-Mono.woff2`).toString('base64'); function getCss(theme: string, fontSize: string) { let background = 'white'; diff --git a/tsconfig.json b/api/tsconfig.json similarity index 92% rename from tsconfig.json rename to api/tsconfig.json index 5bfd454a8..6085bafa1 100644 --- a/tsconfig.json +++ b/api/tsconfig.json @@ -16,7 +16,7 @@ "preserveConstEnums": true, "esModuleInterop": true }, - "exclude": [ - "node_modules" + "include": [ + "./" ] } \ No newline at end of file diff --git a/src/types.d.ts b/api/types.ts similarity index 60% rename from src/types.d.ts rename to api/types.ts index 85a8bb132..e4aafdec9 100644 --- a/src/types.d.ts +++ b/api/types.ts @@ -1,7 +1,7 @@ -type FileType = 'png' | 'jpeg'; -type Theme = 'light' | 'dark'; +export type FileType = 'png' | 'jpeg'; +export type Theme = 'light' | 'dark'; -interface ParsedRequest { +export interface ParsedRequest { fileType: FileType; text: string; theme: Theme; diff --git a/.fonts/Inter-Bold.woff2 b/fonts/Inter-Bold.woff2 similarity index 100% rename from .fonts/Inter-Bold.woff2 rename to fonts/Inter-Bold.woff2 diff --git a/.fonts/Inter-License.txt b/fonts/Inter-License.txt similarity index 100% rename from .fonts/Inter-License.txt rename to fonts/Inter-License.txt diff --git a/.fonts/Inter-Regular.woff2 b/fonts/Inter-Regular.woff2 similarity index 100% rename from .fonts/Inter-Regular.woff2 rename to fonts/Inter-Regular.woff2 diff --git a/.fonts/Vera-License.txt b/fonts/Vera-License.txt similarity index 100% rename from .fonts/Vera-License.txt rename to fonts/Vera-License.txt diff --git a/.fonts/Vera-Mono.woff2 b/fonts/Vera-Mono.woff2 similarity index 100% rename from .fonts/Vera-Mono.woff2 rename to fonts/Vera-Mono.woff2 diff --git a/now.json b/now.json index 4a366a6e9..b61e083f9 100644 --- a/now.json +++ b/now.json @@ -4,15 +4,8 @@ "version": 2, "regions": ["all"], "public": true, - "builds": [ - { "src": "public/**", "use": "@now/static" }, - { "src": "package.json", "use": "@now/static-build" }, - { "src": "src/card.ts", "use": "@now/node@canary", "config": { "maxLambdaSize": "36mb" } } - ], "routes": [ - { "src": "/", "dest": "/public/index.html" }, - { "src": "/(favicon.ico|style.css|robots.txt)", "dest": "/public/$1" }, - { "src": "/dist/browser.js", "dest": "/browser.js" }, - { "src": "/(.+)", "dest": "/src/card.ts" } + { "handle": "filesystem" }, + { "src": "/(.+)", "dest": "/api" } ] } diff --git a/package.json b/package.json index 80d3de0a7..1b4556ae9 100644 --- a/package.json +++ b/package.json @@ -2,25 +2,22 @@ "name": "og-image", "version": "1.0.0", "description": "Generate an open graph image for twitter/facebook/etc", - "main": "dist/card.js", "engines": { "node": "8.10.x" }, "scripts": { - "build": "tsc", - "now-build": "tsc", - "watch": "tsc --watch" + "build": "tsc -p api/tsconfig.json && tsc -p web/tsconfig.json" }, "license": "MIT", "dependencies": { "chrome-aws-lambda": "1.11.1", - "marked": "0.6.1", + "marked": "0.7.0", "puppeteer-core": "1.11.0", "twemoji": "11.3.0" }, "devDependencies": { - "@types/marked": "0.6.1", + "@types/marked": "0.6.5", "@types/puppeteer-core": "1.9.0", - "typescript": "3.3.3333" + "typescript": "3.5.3" } } diff --git a/public/index.html b/public/index.html index fee7d1882..50fcdc611 100644 --- a/public/index.html +++ b/public/index.html @@ -36,7 +36,7 @@