fix: locally linked

This commit is contained in:
Travis Fischer
2024-10-31 20:49:33 -05:00
parent 0e40674e88
commit f6510ea9a1
51 changed files with 4744 additions and 4161 deletions

View File

@@ -1,4 +1,4 @@
import { PageProps } from './types'
import { type PageProps } from './types'
export async function pageAcl({
site,

View File

@@ -7,7 +7,7 @@ export function bootstrap() {
██║ ██╔══██╗██╔══██║██║╚██╗██║╚════██║██║ ██║ ██║╚██╗ ██╔╝██╔══╝ ██╔══██╗╚════██║
██║ ██║ ██║██║ ██║██║ ╚████║███████║██║ ██║ ██║ ╚████╔╝ ███████╗ ██████╔╝███████║
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚══════╝
This site is built using Notion, Next.js, and https://github.com/NotionX/react-notion-x.
`)
}

View File

@@ -5,15 +5,15 @@
* for optional depenencies.
*/
import { parsePageId } from 'notion-utils'
import { PostHogConfig } from 'posthog-js'
import { type PostHogConfig } from 'posthog-js'
import { getEnv, getSiteConfig } from './get-config-value'
import { NavigationLink } from './site-config'
import { type NavigationLink } from './site-config'
import {
NavigationStyle,
PageUrlOverridesInverseMap,
PageUrlOverridesMap,
Site
type NavigationStyle,
type PageUrlOverridesInverseMap,
type PageUrlOverridesMap,
type Site
} from './types'
export const rootNotionPageId: string = parsePageId(

View File

@@ -1,4 +1,4 @@
import { ExtendedRecordMap } from 'notion-types'
import { type ExtendedRecordMap } from 'notion-types'
import {
getCanonicalPageId as getCanonicalPageIdImpl,
parsePageId

View File

@@ -1,5 +1,5 @@
import rawSiteConfig from '../site.config'
import { SiteConfig } from './site-config'
import { type SiteConfig } from './site-config'
if (!rawSiteConfig) {
throw new Error(`Config error: invalid site.config.ts`)

View File

@@ -1,6 +1,6 @@
import { getPageProperty } from 'notion-utils'
import * as types from './types'
import type * as types from './types'
export function getPageTweet(
block: types.Block,

View File

@@ -1,8 +1,8 @@
import { getAllPagesInSpace, uuidToId, getPageProperty } from 'notion-utils'
import { getAllPagesInSpace, getPageProperty, uuidToId } from 'notion-utils'
import pMemoize from 'p-memoize'
import type * as types from './types'
import * as config from './config'
import * as types from './types'
import { includeNotionIdInUrls } from './config'
import { getCanonicalPageId } from './get-canonical-page-id'
import { notion } from './notion-api'
@@ -25,15 +25,15 @@ const getAllPages = pMemoize(getAllPagesImpl, {
cacheKey: (...args) => JSON.stringify(args)
})
const getPage = async (pageId: string, ...args) => {
console.log('\nnotion getPage', uuidToId(pageId))
return notion.getPage(pageId, ...args)
}
async function getAllPagesImpl(
rootNotionPageId: string,
rootNotionSpaceId: string
): Promise<Partial<types.SiteMap>> {
const getPage = async (pageId: string, ...args) => {
console.log('\nnotion getPage', uuidToId(pageId))
return notion.getPage(pageId, ...args)
}
const pageMap = await getAllPagesInSpace(
rootNotionPageId,
rootNotionSpaceId,
@@ -48,7 +48,9 @@ async function getAllPagesImpl(
}
const block = recordMap.block[pageId]?.value
if (!(getPageProperty<boolean|null>('Public', block, recordMap) ?? true)) {
if (
!(getPageProperty<boolean | null>('Public', block, recordMap) ?? true)
) {
return map
}

View File

@@ -1,9 +1,9 @@
import { Block } from 'notion-types'
import { type Block } from 'notion-types'
import { defaultMapImageUrl } from 'react-notion-x'
import { defaultPageCover, defaultPageIcon } from './config'
export const mapImageUrl = (url: string, block: Block) => {
export const mapImageUrl = (url: string | undefined, block: Block) => {
if (url === defaultPageCover || url === defaultPageIcon) {
return url
}

View File

@@ -1,9 +1,9 @@
import { ExtendedRecordMap } from 'notion-types'
import { type ExtendedRecordMap } from 'notion-types'
import { parsePageId, uuidToId } from 'notion-utils'
import { includeNotionIdInUrls } from './config'
import { getCanonicalPageId } from './get-canonical-page-id'
import { Site } from './types'
import { type Site } from './types'
// include UUIDs in page URLs during local development but not in production
// (they're nice for debugging and speed up local dev)

View File

@@ -1,4 +1,8 @@
import { ExtendedRecordMap, SearchParams, SearchResults } from 'notion-types'
import {
type ExtendedRecordMap,
type SearchParams,
type SearchResults
} from 'notion-types'
import { mergeRecordMaps } from 'notion-utils'
import pMap from 'p-map'
import pMemoize from 'p-memoize'

View File

@@ -1,6 +1,10 @@
import got from 'got'
import ky from 'ky'
import lqip from 'lqip-modern'
import { ExtendedRecordMap, PreviewImage, PreviewImageMap } from 'notion-types'
import {
type ExtendedRecordMap,
type PreviewImage,
type PreviewImageMap
} from 'notion-types'
import { getPageImageUrls, normalizeUrl } from 'notion-utils'
import pMap from 'p-map'
import pMemoize from 'p-memoize'
@@ -49,7 +53,7 @@ async function createPreviewImage(
console.warn(`redis error get "${cacheKey}"`, err.message)
}
const { body } = await got(url, { responseType: 'buffer' })
const body = await ky(url).arrayBuffer()
const result = await lqip(body)
console.log('lqip', { ...result.metadata, url, cacheKey })

View File

@@ -1,4 +1,4 @@
import { ExtendedRecordMap } from 'notion-types'
import { type ExtendedRecordMap } from 'notion-types'
import { parsePageId } from 'notion-utils'
import * as acl from './acl'

View File

@@ -1,14 +1,12 @@
// import ky from 'ky'
import ExpiryMap from 'expiry-map'
import fetch from 'isomorphic-unfetch'
import pMemoize from 'p-memoize'
import * as types from './types'
import type * as types from './types'
import { api } from './config'
export const searchNotion = pMemoize(searchNotionImpl, {
cacheKey: (args) => args[0]?.query,
cache: new ExpiryMap(10000)
cache: new ExpiryMap(10_000)
})
async function searchNotionImpl(
@@ -29,7 +27,7 @@ async function searchNotionImpl(
// convert non-2xx HTTP responses into errors
const error: any = new Error(res.statusText)
error.response = res
return Promise.reject(error)
throw error
})
.then((res) => res.json())

View File

@@ -1,4 +1,4 @@
import * as types from './types'
import type * as types from './types'
export interface SiteConfig {
rootNotionPageId: string
@@ -16,7 +16,7 @@ export interface SiteConfig {
newsletter?: string
youtube?: string
zhihu?: string
mastodon?: string;
mastodon?: string
defaultPageIcon?: string | null
defaultPageCover?: string | null

View File

@@ -1,5 +1,6 @@
import { ExtendedRecordMap, PageMap } from 'notion-types'
import { ParsedUrlQuery } from 'querystring'
import { type ParsedUrlQuery } from 'node:querystring'
import { type ExtendedRecordMap, type PageMap } from 'notion-types'
export * from 'notion-types'