mirror of
https://github.com/d0zingcat/nextjs-notion-starter-kit.git
synced 2026-05-13 23:16:47 +00:00
feat: moving api/
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -27,6 +27,7 @@ yarn-error.log*
|
||||
# local env files
|
||||
.env
|
||||
.env.local
|
||||
.env.build
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
@@ -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') {
|
||||
@@ -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
|
||||
})
|
||||
@@ -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',
|
||||
Reference in New Issue
Block a user