feat: moving api/

This commit is contained in:
Travis Fischer
2021-01-17 19:45:09 -05:00
parent b26dbba816
commit 23b712d4b9
4 changed files with 19 additions and 11 deletions

1
.gitignore vendored
View File

@@ -27,6 +27,7 @@ yarn-error.log*
# local env files
.env
.env.local
.env.build
.env.development.local
.env.test.local
.env.production.local

View File

@@ -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') {

View File

@@ -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
})

View File

@@ -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',