mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-05 15:10:26 +00:00
伪静态&刷新缓存时间
This commit is contained in:
@@ -59,7 +59,6 @@ const BLOG = {
|
|||||||
CONTACT_TELEGRAM: 'https://t.me/tangly_1024', // 你的telegram 地址 例如 https://t.me/tangly_1024
|
CONTACT_TELEGRAM: 'https://t.me/tangly_1024', // 你的telegram 地址 例如 https://t.me/tangly_1024
|
||||||
CONTACT_LINKEDIN: '', // 你的linkedIn 首页
|
CONTACT_LINKEDIN: '', // 你的linkedIn 首页
|
||||||
|
|
||||||
|
|
||||||
// 鼠标点击烟花特效
|
// 鼠标点击烟花特效
|
||||||
FIREWORKS: process.env.NEXT_PUBLIC_FIREWORKS || false, // 鼠标点击烟花特效
|
FIREWORKS: process.env.NEXT_PUBLIC_FIREWORKS || false, // 鼠标点击烟花特效
|
||||||
|
|
||||||
@@ -161,6 +160,9 @@ const BLOG = {
|
|||||||
DESCRIPTION:
|
DESCRIPTION:
|
||||||
process.env.NEXT_PUBLIC_DESCRIPTION || '这是一个由NotionNext生成的站点', // 站点描述,被notion中的页面描述覆盖
|
process.env.NEXT_PUBLIC_DESCRIPTION || '这是一个由NotionNext生成的站点', // 站点描述,被notion中的页面描述覆盖
|
||||||
|
|
||||||
|
PSEUDO_STATIC: true, // 伪静态路径,开启后所有文章URL都以 .html 结尾。
|
||||||
|
NEXT_REVALIDATE_SECOND: 5, // 刷新页面的时间间隔 单位 秒
|
||||||
|
|
||||||
isProd: process.env.VERCEL_ENV === 'production', // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables) isProd: process.env.VERCEL_ENV === 'production' // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables)
|
isProd: process.env.VERCEL_ENV === 'production', // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables) isProd: process.env.VERCEL_ENV === 'production' // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables)
|
||||||
VERSION: process.env.NEXT_PUBLIC_VERSION // 版本号
|
VERSION: process.env.NEXT_PUBLIC_VERSION // 版本号
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -224,8 +224,7 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) {
|
|||||||
post.type &&
|
post.type &&
|
||||||
(post.type === 'Post' || post.type === 'Page') &&
|
(post.type === 'Post' || post.type === 'Page') &&
|
||||||
(post.status === 'Published' || post.status === 'Invisible')
|
(post.status === 'Published' || post.status === 'Invisible')
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
// Sort by date
|
// Sort by date
|
||||||
if (BLOG.POSTS_SORT_BY === 'date') {
|
if (BLOG.POSTS_SORT_BY === 'date') {
|
||||||
|
|||||||
@@ -76,6 +76,13 @@ export default async function getPageProperties(id, block, schema, authToken, ta
|
|||||||
properties.slug = (properties.slug ?? properties.id)
|
properties.slug = (properties.slug ?? properties.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 开启伪静态路径
|
||||||
|
if (BLOG.PSEUDO_STATIC) {
|
||||||
|
if (!properties.slug.endsWith('.html')) {
|
||||||
|
properties.slug += '.html'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
properties.createdTime = formatDate(new Date(value.created_time).toString(), BLOG.LANG)
|
properties.createdTime = formatDate(new Date(value.created_time).toString(), BLOG.LANG)
|
||||||
properties.lastEditedTime = formatDate(new Date(value?.last_edited_time).toString(), BLOG.LANG)
|
properties.lastEditedTime = formatDate(new Date(value?.last_edited_time).toString(), BLOG.LANG)
|
||||||
properties.fullWidth = value.format?.page_full_width ?? false
|
properties.fullWidth = value.format?.page_full_width ?? false
|
||||||
@@ -87,25 +94,25 @@ export default async function getPageProperties(id, block, schema, authToken, ta
|
|||||||
}) || []
|
}) || []
|
||||||
delete properties.content
|
delete properties.content
|
||||||
return properties
|
return properties
|
||||||
|
}
|
||||||
// 从Block获取封面图;优先取PageCover,否则取内容图片
|
|
||||||
function getImageUrl(imgObj, blockVal) {
|
// 从Block获取封面图;优先取PageCover,否则取内容图片
|
||||||
if (!imgObj) {
|
function getImageUrl(imgObj, blockVal) {
|
||||||
return null
|
if (!imgObj) {
|
||||||
}
|
return null
|
||||||
if (imgObj.startsWith('/')) {
|
}
|
||||||
return 'https://www.notion.so' + imgObj // notion内部图片转相对路径为绝对路径
|
if (imgObj.startsWith('/')) {
|
||||||
}
|
return 'https://www.notion.so' + imgObj // notion内部图片转相对路径为绝对路径
|
||||||
|
}
|
||||||
if (imgObj.startsWith('http')) {
|
|
||||||
// 判断如果是notion上传的图片要拼接访问token
|
if (imgObj.startsWith('http')) {
|
||||||
const u = new URL(imgObj)
|
// 判断如果是notion上传的图片要拼接访问token
|
||||||
if (u.pathname.startsWith('/secure.notion-static.com') && u.hostname.endsWith('.amazonaws.com')) {
|
const u = new URL(imgObj)
|
||||||
return defaultMapImageUrl(imgObj, blockVal) // notion上传的图片需要转换请求地址
|
if (u.pathname.startsWith('/secure.notion-static.com') && u.hostname.endsWith('.amazonaws.com')) {
|
||||||
}
|
return defaultMapImageUrl(imgObj, blockVal) // notion上传的图片需要转换请求地址
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// 其他图片链接 或 emoji
|
|
||||||
return imgObj
|
// 其他图片链接 或 emoji
|
||||||
}
|
return imgObj
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,8 +95,10 @@ export async function getStaticPaths() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getStaticProps({ params: { slug } }) {
|
export async function getStaticProps({ params: { slug } }) {
|
||||||
// slug 是个数组
|
let fullSlug = slug.join('/')
|
||||||
const fullSlug = slug.join('/')
|
if (BLOG.PSEUDO_STATIC) {
|
||||||
|
fullSlug += '.html'
|
||||||
|
}
|
||||||
const from = `slug-props-${fullSlug}`
|
const from = `slug-props-${fullSlug}`
|
||||||
const props = await getGlobalNotionData({ from })
|
const props = await getGlobalNotionData({ from })
|
||||||
props.post = props.allPages.find((p) => {
|
props.post = props.allPages.find((p) => {
|
||||||
@@ -106,13 +108,13 @@ export async function getStaticProps({ params: { slug } }) {
|
|||||||
if (!props.post) {
|
if (!props.post) {
|
||||||
const pageId = slug.slice(-1)[0]
|
const pageId = slug.slice(-1)[0]
|
||||||
if (pageId.length < 32) {
|
if (pageId.length < 32) {
|
||||||
return { props, revalidate: 1 }
|
return { props, revalidate: BLOG.NEXT_REVALIDATE_SECOND }
|
||||||
}
|
}
|
||||||
const post = await getNotion(pageId)
|
const post = await getNotion(pageId)
|
||||||
if (post) {
|
if (post) {
|
||||||
props.post = post
|
props.post = post
|
||||||
} else {
|
} else {
|
||||||
return { props, revalidate: 1 }
|
return { props, revalidate: BLOG.NEXT_REVALIDATE_SECOND }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
props.post.blockMap = await getPostBlocks(props.post.id, 'slug')
|
props.post.blockMap = await getPostBlocks(props.post.id, 'slug')
|
||||||
@@ -130,7 +132,7 @@ export async function getStaticProps({ params: { slug } }) {
|
|||||||
delete props.allPages
|
delete props.allPages
|
||||||
return {
|
return {
|
||||||
props,
|
props,
|
||||||
revalidate: 1
|
revalidate: BLOG.NEXT_REVALIDATE_SECOND
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useGlobal } from '@/lib/global'
|
import { useGlobal } from '@/lib/global'
|
||||||
import * as ThemeMap from '@/themes'
|
import * as ThemeMap from '@/themes'
|
||||||
|
import BLOG from '@/blog.config'
|
||||||
|
|
||||||
const ArchiveIndex = props => {
|
const ArchiveIndex = props => {
|
||||||
const { theme, locale } = useGlobal()
|
const { theme, locale } = useGlobal()
|
||||||
@@ -26,7 +27,7 @@ export async function getStaticProps() {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
props,
|
props,
|
||||||
revalidate: 1
|
revalidate: BLOG.NEXT_REVALIDATE_SECOND
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export async function getStaticProps({ params: { category } }) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
props,
|
props,
|
||||||
revalidate: 1
|
revalidate: BLOG.NEXT_REVALIDATE_SECOND
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export async function getStaticProps({ params: { category, page } }) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
props,
|
props,
|
||||||
revalidate: 1
|
revalidate: BLOG.NEXT_REVALIDATE_SECOND
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import React from 'react'
|
|||||||
import { useGlobal } from '@/lib/global'
|
import { useGlobal } from '@/lib/global'
|
||||||
import * as ThemeMap from '@/themes'
|
import * as ThemeMap from '@/themes'
|
||||||
import { getAllCategories } from '@/lib/notion/getAllCategories'
|
import { getAllCategories } from '@/lib/notion/getAllCategories'
|
||||||
|
import BLOG from '@/blog.config'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分类首页
|
* 分类首页
|
||||||
@@ -30,6 +31,6 @@ export async function getStaticProps() {
|
|||||||
delete props.categoryOptions
|
delete props.categoryOptions
|
||||||
return {
|
return {
|
||||||
props,
|
props,
|
||||||
revalidate: 1
|
revalidate: BLOG.NEXT_REVALIDATE_SECOND
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export async function getStaticProps() {
|
|||||||
meta,
|
meta,
|
||||||
...props
|
...props
|
||||||
},
|
},
|
||||||
revalidate: 5
|
revalidate: BLOG.NEXT_REVALIDATE_SECOND
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export async function getStaticProps({ params: { page } }) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
props,
|
props,
|
||||||
revalidate: 1
|
revalidate: BLOG.NEXT_REVALIDATE_SECOND
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export async function getStaticProps({ params: { keyword } }) {
|
|||||||
props.keyword = keyword
|
props.keyword = keyword
|
||||||
return {
|
return {
|
||||||
props,
|
props,
|
||||||
revalidate: 1
|
revalidate: BLOG.NEXT_REVALIDATE_SECOND
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export async function getStaticProps({ params: { keyword, page } }) {
|
|||||||
props.page = page
|
props.page = page
|
||||||
return {
|
return {
|
||||||
props,
|
props,
|
||||||
revalidate: 1
|
revalidate: BLOG.NEXT_REVALIDATE_SECOND
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
|||||||
import { useGlobal } from '@/lib/global'
|
import { useGlobal } from '@/lib/global'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import * as ThemeMap from '@/themes'
|
import * as ThemeMap from '@/themes'
|
||||||
|
import BLOG from '@/blog.config'
|
||||||
|
|
||||||
const Search = props => {
|
const Search = props => {
|
||||||
const { posts, siteInfo } = props
|
const { posts, siteInfo } = props
|
||||||
@@ -58,7 +59,7 @@ export async function getStaticProps() {
|
|||||||
props.posts = allPosts
|
props.posts = allPosts
|
||||||
return {
|
return {
|
||||||
props,
|
props,
|
||||||
revalidate: 1
|
revalidate: BLOG.NEXT_REVALIDATE_SECOND
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export async function getStaticProps({ params: { tag, page } }) {
|
|||||||
delete props.allPages
|
delete props.allPages
|
||||||
return {
|
return {
|
||||||
props,
|
props,
|
||||||
revalidate: 1
|
revalidate: BLOG.NEXT_REVALIDATE_SECOND
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user