Skip to content

Commit

Permalink
feat: moving api/
Browse files Browse the repository at this point in the history
  • Loading branch information
transitive-bullshit committed Jan 18, 2021
1 parent b26dbba commit 23b712d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ yarn-error.log*
# local env files
.env
.env.local
.env.build
.env.development.local
.env.test.local
.env.production.local
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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
})
Expand Down
4 changes: 2 additions & 2 deletions pages/api/search-notion.ts → api/search-notion.ts
Original file line number Diff line number Diff line change
@@ -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') {
Expand All @@ -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',
Expand Down

0 comments on commit 23b712d

Please sign in to comment.