diff --git a/.gitignore b/.gitignore index 74b7586..b624e5d 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ yarn-error.log* # local env files .env .env.local +.env.build .env.development.local .env.test.local .env.production.local diff --git a/pages/api/create-preview-image.ts b/api/create-preview-image.ts similarity index 95% rename from pages/api/create-preview-image.ts rename to api/create-preview-image.ts index 95492ab..80a6ce9 100644 --- a/pages/api/create-preview-image.ts +++ b/api/create-preview-image.ts @@ -3,8 +3,8 @@ import { NextApiRequest, NextApiResponse } from 'next' import got from 'got' import lqip from 'lqip-modern' -import * as types from '../../lib/types' -import * as db from '../../lib/db' +import * as types from 'lib/types' +import * as db from 'lib/db' export default async (req: NextApiRequest, res: NextApiResponse) => { if (req.method !== 'POST') { diff --git a/pages/api/render-social-image/[pageId].ts b/api/render-social-image/[pageId].ts similarity index 84% rename from pages/api/render-social-image/[pageId].ts rename to api/render-social-image/[pageId].ts index 6fa6ca1..08a2614 100644 --- a/pages/api/render-social-image/[pageId].ts +++ b/api/render-social-image/[pageId].ts @@ -3,16 +3,17 @@ import chromium from 'chrome-aws-lambda' import renderSocialImage from 'puppeteer-social-image-transitive-bs' import { getBlockIcon, getBlockTitle } from 'notion-utils' -import { getPage } from 'lib/notion' -import * as types from 'lib/types' +import { mapNotionImageUrl } from '../../lib/map-image-url' +import { getPage } from '../../lib/notion' +import * as types from '../../lib/types' import { siteDescription, defaultPageCover, defaultPageIcon, siteDomain, siteName -} from 'lib/config' -import { getPageDescription } from 'lib/get-page-description' +} from '../../lib/config' +import { getPageDescription } from '../../lib/get-page-description' export interface SocialImageConfig { title: string @@ -71,9 +72,15 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { // TODO: centralize these default config values const image = await createSocialImage({ - imageUrl: block.format?.page_cover ?? defaultPageCover, + imageUrl: mapNotionImageUrl( + block.format?.page_cover ?? defaultPageCover, + block + ), title: getBlockTitle(block, recordMap) ?? siteName, - logo: getBlockIcon(block, recordMap) ?? defaultPageIcon, + logo: mapNotionImageUrl( + getBlockIcon(block, recordMap) ?? defaultPageIcon, + block + ), subtitle: getPageDescription(block, recordMap) ?? siteDescription, watermark: siteDomain }) @@ -101,7 +108,7 @@ async function createSocialImage(params: SocialImageConfig) { const res = await renderSocialImage({ template: 'article', templateParams: params, - templateStyles: `h1 { font-size: 96px; text-align: center; } h2 { font-size: 32px; }`, + templateStyles: `h1 { font-size: 96px; text-align: center; } h2 { font-size: 32px; text-align: center; }`, size: params.size, browser }) diff --git a/pages/api/search-notion.ts b/api/search-notion.ts similarity index 83% rename from pages/api/search-notion.ts rename to api/search-notion.ts index 46a46be..91d7632 100644 --- a/pages/api/search-notion.ts +++ b/api/search-notion.ts @@ -1,7 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next' import * as types from 'lib/types' -import * as notion from 'lib/notion' +import { search } from 'lib/notion' export default async (req: NextApiRequest, res: NextApiResponse) => { if (req.method !== 'POST') { @@ -10,7 +10,7 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { const searchParams: types.SearchParams = req.body - const results = await notion.search(searchParams) + const results = await search(searchParams) res.setHeader( 'Cache-Control',