mirror of
https://github.com/d0zingcat/nextjs-notion-starter-kit.git
synced 2026-05-13 15:09:47 +00:00
feat: add rss feed and cleanup some sitemap code
This commit is contained in:
@@ -12,7 +12,8 @@ import { NavigationLink } from './site-config'
|
||||
import {
|
||||
PageUrlOverridesInverseMap,
|
||||
PageUrlOverridesMap,
|
||||
NavigationStyle
|
||||
NavigationStyle,
|
||||
Site
|
||||
} from './types'
|
||||
|
||||
export const rootNotionPageId: string = parsePageId(
|
||||
@@ -132,6 +133,14 @@ export const api = {
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
export const site: Site = {
|
||||
domain,
|
||||
name,
|
||||
rootNotionPageId,
|
||||
rootNotionSpaceId,
|
||||
description
|
||||
}
|
||||
|
||||
export const fathomId = isDev ? null : process.env.NEXT_PUBLIC_FATHOM_ID
|
||||
export const fathomConfig = fathomId
|
||||
? {
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import * as config from './config'
|
||||
import * as types from './types'
|
||||
|
||||
export const getSiteForDomain = async (
|
||||
domain: string
|
||||
): Promise<types.Site | null> => {
|
||||
return {
|
||||
domain,
|
||||
name: config.name,
|
||||
rootNotionPageId: config.rootNotionPageId,
|
||||
rootNotionSpaceId: config.rootNotionSpaceId,
|
||||
description: config.description
|
||||
} as types.Site
|
||||
}
|
||||
@@ -1,18 +1,31 @@
|
||||
import pMemoize from 'p-memoize'
|
||||
import { getAllPagesInSpace, uuidToId } from 'notion-utils'
|
||||
|
||||
import * as types from './types'
|
||||
import { includeNotionIdInUrls } from './config'
|
||||
import { notion } from './notion-api'
|
||||
import { getCanonicalPageId } from './get-canonical-page-id'
|
||||
import * as config from './config'
|
||||
import * as types from './types'
|
||||
|
||||
const uuid = !!includeNotionIdInUrls
|
||||
|
||||
export const getAllPages = pMemoize(getAllPagesImpl, {
|
||||
export async function getSiteMap(): Promise<types.SiteMap> {
|
||||
const partialSiteMap = await getAllPages(
|
||||
config.rootNotionPageId,
|
||||
config.rootNotionSpaceId
|
||||
)
|
||||
|
||||
return {
|
||||
site: config.site,
|
||||
...partialSiteMap
|
||||
} as types.SiteMap
|
||||
}
|
||||
|
||||
const getAllPages = pMemoize(getAllPagesImpl, {
|
||||
cacheKey: (...args) => JSON.stringify(args)
|
||||
})
|
||||
|
||||
export async function getAllPagesImpl(
|
||||
async function getAllPagesImpl(
|
||||
rootNotionPageId: string,
|
||||
rootNotionSpaceId: string
|
||||
): Promise<Partial<types.SiteMap>> {
|
||||
@@ -1,35 +0,0 @@
|
||||
import pMap from 'p-map'
|
||||
|
||||
import { getAllPages } from './get-all-pages'
|
||||
import { getSites } from './get-sites'
|
||||
import * as types from './types'
|
||||
|
||||
export async function getSiteMaps(): Promise<types.SiteMap[]> {
|
||||
const sites = await getSites()
|
||||
|
||||
const siteMaps = await pMap(
|
||||
sites,
|
||||
async (site, index) => {
|
||||
try {
|
||||
console.log(
|
||||
'getSiteMap',
|
||||
`${index + 1}/${sites.length}`,
|
||||
`(${(((index + 1) / sites.length) * 100) | 0}%)`,
|
||||
site
|
||||
)
|
||||
|
||||
return {
|
||||
site,
|
||||
...(await getAllPages(site.rootNotionPageId, site.rootNotionSpaceId))
|
||||
} as types.SiteMap
|
||||
} catch (err) {
|
||||
console.warn('site build error', index, site, err)
|
||||
}
|
||||
},
|
||||
{
|
||||
concurrency: 4
|
||||
}
|
||||
)
|
||||
|
||||
return siteMaps.filter(Boolean)
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { getSiteForDomain } from './get-site-for-domain'
|
||||
import * as config from './config'
|
||||
import * as types from './types'
|
||||
|
||||
export async function getSites(): Promise<types.Site[]> {
|
||||
return [await getSiteForDomain(config.domain)]
|
||||
}
|
||||
@@ -2,15 +2,12 @@ import { parsePageId } from 'notion-utils'
|
||||
import { ExtendedRecordMap } from 'notion-types'
|
||||
|
||||
import * as acl from './acl'
|
||||
import * as types from './types'
|
||||
import { pageUrlOverrides, pageUrlAdditions, environment } from './config'
|
||||
import { pageUrlOverrides, pageUrlAdditions, environment, site } from './config'
|
||||
import { db } from './db'
|
||||
import { getPage } from './notion'
|
||||
import { getSiteMaps } from './get-site-maps'
|
||||
import { getSiteForDomain } from './get-site-for-domain'
|
||||
import { getSiteMap } from './get-site-map'
|
||||
|
||||
export async function resolveNotionPage(domain: string, rawPageId?: string) {
|
||||
let site: types.Site
|
||||
let pageId: string
|
||||
let recordMap: ExtendedRecordMap
|
||||
|
||||
@@ -47,27 +44,19 @@ export async function resolveNotionPage(domain: string, rawPageId?: string) {
|
||||
}
|
||||
|
||||
if (pageId) {
|
||||
;[site, recordMap] = await Promise.all([
|
||||
getSiteForDomain(domain),
|
||||
getPage(pageId)
|
||||
])
|
||||
recordMap = await getPage(pageId)
|
||||
} else {
|
||||
// handle mapping of user-friendly canonical page paths to Notion page IDs
|
||||
// e.g., /developer-x-entrepreneur versus /71201624b204481f862630ea25ce62fe
|
||||
const siteMaps = await getSiteMaps()
|
||||
const siteMap = siteMaps[0]
|
||||
const siteMap = await getSiteMap()
|
||||
pageId = siteMap?.canonicalPageMap[rawPageId]
|
||||
|
||||
if (pageId) {
|
||||
// TODO: we're not re-using the page recordMap from siteMaps because it is
|
||||
// cached aggressively
|
||||
// site = await getSiteForDomain(domain)
|
||||
// recordMap = siteMap.pageMap[pageId]
|
||||
|
||||
;[site, recordMap] = await Promise.all([
|
||||
getSiteForDomain(domain),
|
||||
getPage(pageId)
|
||||
])
|
||||
recordMap = await getPage(pageId)
|
||||
|
||||
if (useUriToPageIdCache) {
|
||||
try {
|
||||
@@ -91,7 +80,6 @@ export async function resolveNotionPage(domain: string, rawPageId?: string) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
site = await getSiteForDomain(domain)
|
||||
pageId = site.rootNotionPageId
|
||||
|
||||
console.log(site)
|
||||
|
||||
14
lib/types.ts
14
lib/types.ts
@@ -16,15 +16,7 @@ export interface PageProps {
|
||||
error?: PageError
|
||||
}
|
||||
|
||||
export interface Model {
|
||||
id: string
|
||||
userId: string
|
||||
|
||||
createdAt: number
|
||||
updatedAt: number
|
||||
}
|
||||
|
||||
export interface Site extends Model {
|
||||
export interface Site {
|
||||
name: string
|
||||
domain: string
|
||||
|
||||
@@ -40,10 +32,6 @@ export interface Site extends Model {
|
||||
// opengraph metadata
|
||||
description?: string
|
||||
image?: string
|
||||
|
||||
timestamp: Date
|
||||
|
||||
isDisabled: boolean
|
||||
}
|
||||
|
||||
export interface SiteMap {
|
||||
|
||||
Reference in New Issue
Block a user