mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-06 15:10:29 +00:00
fix date
This commit is contained in:
@@ -56,7 +56,7 @@ const CommonHead = ({ meta, children }) => {
|
|||||||
<>
|
<>
|
||||||
<meta
|
<meta
|
||||||
property="article:published_time"
|
property="article:published_time"
|
||||||
content={meta.date || meta.createdTime}
|
content={meta.publishTime}
|
||||||
/>
|
/>
|
||||||
<meta property="article:author" content={BLOG.AUTHOR} />
|
<meta property="article:author" content={BLOG.AUTHOR} />
|
||||||
<meta property="article:section" content={category} />
|
<meta property="article:section" content={category} />
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ export default function formatDate (date, local) {
|
|||||||
const d = new Date(date)
|
const d = new Date(date)
|
||||||
const options = { year: 'numeric', month: 'short', day: 'numeric' }
|
const options = { year: 'numeric', month: 'short', day: 'numeric' }
|
||||||
const res = d.toLocaleDateString(local, options)
|
const res = d.toLocaleDateString(local, options)
|
||||||
return res
|
return local.slice(0, 2).toLowerCase() === 'zh'
|
||||||
|
? res.replace('年', '-').replace('月', '-').replace('日', '')
|
||||||
|
: res
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatDateFmt (timestamp, fmt) {
|
export function formatDateFmt (timestamp, fmt) {
|
||||||
const date = new Date(timestamp)
|
const date = new Date(timestamp)
|
||||||
const o = {
|
const o = {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export async function getAllPosts({ notionPageData, from, pageType }) {
|
|||||||
// Sort by date
|
// Sort by date
|
||||||
if (BLOG.POSTS_SORT_BY === 'date') {
|
if (BLOG.POSTS_SORT_BY === 'date') {
|
||||||
posts.sort((a, b) => {
|
posts.sort((a, b) => {
|
||||||
return b?.sortDate - a?.sortDate
|
return b?.publishDate - a?.publishDate
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return posts
|
return posts
|
||||||
|
|||||||
@@ -20,23 +20,23 @@ import { mapImgUrl, compressImage } from './mapImage'
|
|||||||
* @returns
|
* @returns
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export async function getGlobalNotionData({
|
export async function getGlobalData({
|
||||||
pageId = BLOG.NOTION_PAGE_ID,
|
pageId = BLOG.NOTION_PAGE_ID,
|
||||||
from
|
from
|
||||||
}) {
|
}) {
|
||||||
// 获取Notion数据
|
// 从notion获取
|
||||||
const notionPageData = deepClone(await getNotionPageData({ pageId, from }))
|
const db = deepClone(await getNotionPageData({ pageId, from }))
|
||||||
notionPageData.allNavPages = getNavPages({ allPages: notionPageData.allPages })
|
// 不返回的敏感数据
|
||||||
delete notionPageData.block
|
delete db.block
|
||||||
delete notionPageData.schema
|
delete db.schema
|
||||||
delete notionPageData.rawMetadata
|
delete db.rawMetadata
|
||||||
delete notionPageData.pageIds
|
delete db.pageIds
|
||||||
delete notionPageData.viewIds
|
delete db.viewIds
|
||||||
delete notionPageData.collection
|
delete db.collection
|
||||||
delete notionPageData.collectionQuery
|
delete db.collectionQuery
|
||||||
delete notionPageData.collectionId
|
delete db.collectionId
|
||||||
delete notionPageData.collectionView
|
delete db.collectionView
|
||||||
return notionPageData
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,8 +48,8 @@ function getLatestPosts({ allPages, from, latestPostCount }) {
|
|||||||
const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
|
const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||||
|
|
||||||
const latestPosts = Object.create(allPosts).sort((a, b) => {
|
const latestPosts = Object.create(allPosts).sort((a, b) => {
|
||||||
const dateA = new Date(a?.lastEditedTime || a?.sortDate)
|
const dateA = new Date(a?.lastEditedTime || a?.publishDate)
|
||||||
const dateB = new Date(b?.lastEditedTime || b?.sortDate)
|
const dateB = new Date(b?.lastEditedTime || b?.publishDate)
|
||||||
return dateB - dateA
|
return dateB - dateA
|
||||||
})
|
})
|
||||||
return latestPosts.slice(0, latestPostCount)
|
return latestPosts.slice(0, latestPostCount)
|
||||||
@@ -69,12 +69,12 @@ export async function getNotionPageData({ pageId, from }) {
|
|||||||
console.log('[缓存]:', `from:${from}`, `root-page-id:${pageId}`)
|
console.log('[缓存]:', `from:${from}`, `root-page-id:${pageId}`)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
const pageRecordMap = await getDataBaseInfoByNotionAPI({ pageId, from })
|
const db = await getDataBaseInfoByNotionAPI({ pageId, from })
|
||||||
// 存入缓存
|
// 存入缓存
|
||||||
if (pageRecordMap) {
|
if (db) {
|
||||||
await setDataToCache(cacheKey, pageRecordMap)
|
await setDataToCache(cacheKey, db)
|
||||||
}
|
}
|
||||||
return pageRecordMap
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -298,7 +298,7 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
|
|||||||
// Sort by date
|
// Sort by date
|
||||||
if (BLOG.POSTS_SORT_BY === 'date') {
|
if (BLOG.POSTS_SORT_BY === 'date') {
|
||||||
allPages.sort((a, b) => {
|
allPages.sort((a, b) => {
|
||||||
return b?.sortDate - a?.sortDate
|
return b?.publishDate - a?.publishDate
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,11 +92,9 @@ export default async function getPageProperties(id, block, schema, authToken, ta
|
|||||||
properties.slug += '.html'
|
properties.slug += '.html'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
properties.publishDate = new Date(properties?.date?.start_date || value.created_time).getTime()
|
||||||
properties.sortDate = value?.date?.start_date || value.created_time
|
properties.publishTime = formatDate(properties.publishDate, BLOG.LANG)
|
||||||
properties.createdTime = formatDate(new Date(value.created_time).toString(), BLOG.LANG)
|
properties.lastEditedTime = formatDate(new Date(value?.last_edited_time), BLOG.LANG)
|
||||||
properties.publishTime = value?.date?.start_date ? formatDate(new Date(value?.date?.start_date).toString, BLOG.LANG) : properties.createdTime
|
|
||||||
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
|
||||||
properties.pageIcon = mapImgUrl(block[id].value?.format?.page_icon, block[id].value) ?? ''
|
properties.pageIcon = mapImgUrl(block[id].value?.format?.page_icon, block[id].value) ?? ''
|
||||||
properties.pageCover = mapImgUrl(block[id].value?.format?.page_cover, block[id].value) ?? ''
|
properties.pageCover = mapImgUrl(block[id].value?.format?.page_cover, block[id].value) ?? ''
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export async function generateRss(posts) {
|
|||||||
link: `${BLOG.LINK}/${post.slug}`,
|
link: `${BLOG.LINK}/${post.slug}`,
|
||||||
description: post.summary,
|
description: post.summary,
|
||||||
content: await createFeedContent(post),
|
content: await createFeedContent(post),
|
||||||
date: new Date(post?.publishTime || post?.createdTime)
|
date: new Date(post?.publishTime)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export async function generateSitemapXml({ allPages }) {
|
|||||||
allPages?.forEach(post => {
|
allPages?.forEach(post => {
|
||||||
urls.push({
|
urls.push({
|
||||||
loc: `${BLOG.LINK}/${post.slug}`,
|
loc: `${BLOG.LINK}/${post.slug}`,
|
||||||
lastmod: new Date(post?.publishTime || post?.createdTime).toISOString().split('T')[0],
|
lastmod: new Date(post?.publishTime).toISOString().split('T')[0],
|
||||||
changefreq: 'daily'
|
changefreq: 'daily'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
import { getGlobalData } 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 { getLayoutByTheme } from '@/themes/theme'
|
import { getLayoutByTheme } from '@/themes/theme'
|
||||||
@@ -21,7 +21,7 @@ const NoFound = props => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getStaticProps () {
|
export async function getStaticProps () {
|
||||||
const props = (await getGlobalNotionData({ from: '404' })) || {}
|
const props = (await getGlobalData({ from: '404' })) || {}
|
||||||
return { props }
|
return { props }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import BLOG from '@/blog.config'
|
import BLOG from '@/blog.config'
|
||||||
import { getPostBlocks } from '@/lib/notion'
|
import { getPostBlocks } from '@/lib/notion'
|
||||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
import { getGlobalData } from '@/lib/notion/getNotionData'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { idToUuid } from 'notion-utils'
|
import { idToUuid } from 'notion-utils'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
@@ -87,7 +87,7 @@ export async function getStaticPaths() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const from = 'slug-paths'
|
const from = 'slug-paths'
|
||||||
const { allPages } = await getGlobalNotionData({ from })
|
const { allPages } = await getGlobalData({ from })
|
||||||
return {
|
return {
|
||||||
paths: allPages?.map(row => ({ params: { slug: [row.slug] } })),
|
paths: allPages?.map(row => ({ params: { slug: [row.slug] } })),
|
||||||
fallback: true
|
fallback: true
|
||||||
@@ -102,7 +102,7 @@ export async function getStaticProps({ params: { slug } }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const from = `slug-props-${fullSlug}`
|
const from = `slug-props-${fullSlug}`
|
||||||
const props = await getGlobalNotionData({ from })
|
const props = await getGlobalData({ from })
|
||||||
// 在列表内查找文章
|
// 在列表内查找文章
|
||||||
props.post = props?.allPages?.find((p) => {
|
props.post = props?.allPages?.find((p) => {
|
||||||
return p.slug === fullSlug || p.id === idToUuid(fullSlug)
|
return p.slug === fullSlug || p.id === idToUuid(fullSlug)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
import { getGlobalData } from '@/lib/notion/getNotionData'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useGlobal } from '@/lib/global'
|
import { useGlobal } from '@/lib/global'
|
||||||
import BLOG from '@/blog.config'
|
import BLOG from '@/blog.config'
|
||||||
@@ -27,7 +27,7 @@ const ArchiveIndex = props => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getStaticProps() {
|
export async function getStaticProps() {
|
||||||
const props = await getGlobalNotionData({ from: 'archive-index' })
|
const props = await getGlobalData({ from: 'archive-index' })
|
||||||
// 处理分页
|
// 处理分页
|
||||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||||
delete props.allPages
|
delete props.allPages
|
||||||
@@ -35,13 +35,13 @@ export async function getStaticProps() {
|
|||||||
const postsSortByDate = Object.create(props.posts)
|
const postsSortByDate = Object.create(props.posts)
|
||||||
|
|
||||||
postsSortByDate.sort((a, b) => {
|
postsSortByDate.sort((a, b) => {
|
||||||
return b?.sortDate - a?.sortDate
|
return b?.publishDate - a?.publishDate
|
||||||
})
|
})
|
||||||
|
|
||||||
const archivePosts = {}
|
const archivePosts = {}
|
||||||
|
|
||||||
postsSortByDate.forEach(post => {
|
postsSortByDate.forEach(post => {
|
||||||
const date = formatDateFmt(post.sortDate, 'yyyy-MM')
|
const date = formatDateFmt(post.publishDate, 'yyyy-MM')
|
||||||
if (archivePosts[date]) {
|
if (archivePosts[date]) {
|
||||||
archivePosts[date].push(post)
|
archivePosts[date].push(post)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
import { getGlobalData } from '@/lib/notion/getNotionData'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useGlobal } from '@/lib/global'
|
import { useGlobal } from '@/lib/global'
|
||||||
import BLOG from '@/blog.config'
|
import BLOG from '@/blog.config'
|
||||||
@@ -34,7 +34,7 @@ export default function Category(props) {
|
|||||||
|
|
||||||
export async function getStaticProps({ params: { category } }) {
|
export async function getStaticProps({ params: { category } }) {
|
||||||
const from = 'category-props'
|
const from = 'category-props'
|
||||||
let props = await getGlobalNotionData({ from })
|
let props = await getGlobalData({ from })
|
||||||
|
|
||||||
// 过滤状态
|
// 过滤状态
|
||||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||||
@@ -61,7 +61,7 @@ export async function getStaticProps({ params: { category } }) {
|
|||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const from = 'category-paths'
|
const from = 'category-paths'
|
||||||
const { categoryOptions } = await getGlobalNotionData({ from })
|
const { categoryOptions } = await getGlobalData({ from })
|
||||||
return {
|
return {
|
||||||
paths: Object.keys(categoryOptions).map(category => ({
|
paths: Object.keys(categoryOptions).map(category => ({
|
||||||
params: { category: categoryOptions[category]?.name }
|
params: { category: categoryOptions[category]?.name }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
import { getGlobalData } from '@/lib/notion/getNotionData'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useGlobal } from '@/lib/global'
|
import { useGlobal } from '@/lib/global'
|
||||||
import BLOG from '@/blog.config'
|
import BLOG from '@/blog.config'
|
||||||
@@ -34,7 +34,7 @@ export default function Category(props) {
|
|||||||
|
|
||||||
export async function getStaticProps({ params: { category, page } }) {
|
export async function getStaticProps({ params: { category, page } }) {
|
||||||
const from = 'category-page-props'
|
const from = 'category-page-props'
|
||||||
let props = await getGlobalNotionData({ from })
|
let props = await getGlobalData({ from })
|
||||||
|
|
||||||
// 过滤状态类型
|
// 过滤状态类型
|
||||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.category && post.category.includes(category))
|
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.category && post.category.includes(category))
|
||||||
@@ -56,7 +56,7 @@ export async function getStaticProps({ params: { category, page } }) {
|
|||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const from = 'category-paths'
|
const from = 'category-paths'
|
||||||
const { categoryOptions, allPages } = await getGlobalNotionData({ from })
|
const { categoryOptions, allPages } = await getGlobalData({ from })
|
||||||
const paths = []
|
const paths = []
|
||||||
|
|
||||||
categoryOptions?.forEach(category => {
|
categoryOptions?.forEach(category => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
import { getGlobalData } from '@/lib/notion/getNotionData'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useGlobal } from '@/lib/global'
|
import { useGlobal } from '@/lib/global'
|
||||||
import BLOG from '@/blog.config'
|
import BLOG from '@/blog.config'
|
||||||
@@ -30,7 +30,7 @@ export default function Category(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getStaticProps() {
|
export async function getStaticProps() {
|
||||||
const props = await getGlobalNotionData({ from: 'category-index-props' })
|
const props = await getGlobalData({ from: 'category-index-props' })
|
||||||
delete props.allPages
|
delete props.allPages
|
||||||
return {
|
return {
|
||||||
props,
|
props,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import BLOG from '@/blog.config'
|
import BLOG from '@/blog.config'
|
||||||
import { getPostBlocks } from '@/lib/notion'
|
import { getPostBlocks } from '@/lib/notion'
|
||||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
import { getGlobalData } from '@/lib/notion/getNotionData'
|
||||||
import { generateRss } from '@/lib/rss'
|
import { generateRss } from '@/lib/rss'
|
||||||
import { generateRobotsTxt } from '@/lib/robots.txt'
|
import { generateRobotsTxt } from '@/lib/robots.txt'
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ const Index = props => {
|
|||||||
*/
|
*/
|
||||||
export async function getStaticProps() {
|
export async function getStaticProps() {
|
||||||
const from = 'index'
|
const from = 'index'
|
||||||
const props = await getGlobalNotionData({ from })
|
const props = await getGlobalData({ from })
|
||||||
|
|
||||||
const { siteInfo } = props
|
const { siteInfo } = props
|
||||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import BLOG from '@/blog.config'
|
import BLOG from '@/blog.config'
|
||||||
import { getPostBlocks } from '@/lib/notion'
|
import { getPostBlocks } from '@/lib/notion'
|
||||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
import { getGlobalData } from '@/lib/notion/getNotionData'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { getLayoutByTheme } from '@/themes/theme'
|
import { getLayoutByTheme } from '@/themes/theme'
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ const Page = props => {
|
|||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const from = 'page-paths'
|
const from = 'page-paths'
|
||||||
const { postCount } = await getGlobalNotionData({ from })
|
const { postCount } = await getGlobalData({ from })
|
||||||
const totalPages = Math.ceil(postCount / BLOG.POSTS_PER_PAGE)
|
const totalPages = Math.ceil(postCount / BLOG.POSTS_PER_PAGE)
|
||||||
return {
|
return {
|
||||||
// remove first page, we 're not gonna handle that.
|
// remove first page, we 're not gonna handle that.
|
||||||
@@ -43,7 +43,7 @@ export async function getStaticPaths() {
|
|||||||
|
|
||||||
export async function getStaticProps({ params: { page } }) {
|
export async function getStaticProps({ params: { page } }) {
|
||||||
const from = `page-${page}`
|
const from = `page-${page}`
|
||||||
const props = await getGlobalNotionData({ from })
|
const props = await getGlobalData({ from })
|
||||||
const { allPages } = props
|
const { allPages } = props
|
||||||
const allPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
const allPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||||
// 处理分页
|
// 处理分页
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
import { getGlobalData } from '@/lib/notion/getNotionData'
|
||||||
import { useGlobal } from '@/lib/global'
|
import { useGlobal } from '@/lib/global'
|
||||||
import { getDataFromCache } from '@/lib/cache/cache_manager'
|
import { getDataFromCache } from '@/lib/cache/cache_manager'
|
||||||
import BLOG from '@/blog.config'
|
import BLOG from '@/blog.config'
|
||||||
@@ -31,7 +31,7 @@ const Index = props => {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function getStaticProps({ params: { keyword } }) {
|
export async function getStaticProps({ params: { keyword } }) {
|
||||||
const props = await getGlobalNotionData({
|
const props = await getGlobalData({
|
||||||
from: 'search-props',
|
from: 'search-props',
|
||||||
pageType: ['Post']
|
pageType: ['Post']
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
import { getGlobalData } from '@/lib/notion/getNotionData'
|
||||||
import { useGlobal } from '@/lib/global'
|
import { useGlobal } from '@/lib/global'
|
||||||
import { getDataFromCache } from '@/lib/cache/cache_manager'
|
import { getDataFromCache } from '@/lib/cache/cache_manager'
|
||||||
import BLOG from '@/blog.config'
|
import BLOG from '@/blog.config'
|
||||||
@@ -31,7 +31,7 @@ const Index = props => {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function getStaticProps({ params: { keyword, page } }) {
|
export async function getStaticProps({ params: { keyword, page } }) {
|
||||||
const props = await getGlobalNotionData({
|
const props = await getGlobalData({
|
||||||
from: 'search-props',
|
from: 'search-props',
|
||||||
pageType: ['Post']
|
pageType: ['Post']
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
import { getGlobalData } 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 BLOG from '@/blog.config'
|
import BLOG from '@/blog.config'
|
||||||
@@ -45,7 +45,7 @@ const Search = props => {
|
|||||||
* 浏览器前端搜索
|
* 浏览器前端搜索
|
||||||
*/
|
*/
|
||||||
export async function getStaticProps() {
|
export async function getStaticProps() {
|
||||||
const props = await getGlobalNotionData({
|
const props = await getGlobalData({
|
||||||
from: 'search-props',
|
from: 'search-props',
|
||||||
pageType: ['Post']
|
pageType: ['Post']
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
// pages/sitemap.xml.js
|
// pages/sitemap.xml.js
|
||||||
import { getServerSideSitemap } from 'next-sitemap'
|
import { getServerSideSitemap } from 'next-sitemap'
|
||||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
import { getGlobalData } from '@/lib/notion/getNotionData'
|
||||||
import BLOG from '@/blog.config'
|
import BLOG from '@/blog.config'
|
||||||
|
|
||||||
export const getServerSideProps = async (ctx) => {
|
export const getServerSideProps = async (ctx) => {
|
||||||
const { allPages } = await getGlobalNotionData({ from: 'rss' })
|
const { allPages } = await getGlobalData({ from: 'rss' })
|
||||||
const defaultFields = [
|
const defaultFields = [
|
||||||
{
|
{
|
||||||
loc: `${BLOG.LINK}`,
|
loc: `${BLOG.LINK}`,
|
||||||
@@ -41,7 +41,7 @@ export const getServerSideProps = async (ctx) => {
|
|||||||
const postFields = allPages?.filter(p => p.status === BLOG.NOTION_PROPERTY_NAME.status_publish)?.map(post => {
|
const postFields = allPages?.filter(p => p.status === BLOG.NOTION_PROPERTY_NAME.status_publish)?.map(post => {
|
||||||
return {
|
return {
|
||||||
loc: `${BLOG.LINK}/${post.slug}`,
|
loc: `${BLOG.LINK}/${post.slug}`,
|
||||||
lastmod: new Date(post?.publishTime || post?.createdTime).toISOString().split('T')[0],
|
lastmod: new Date(post?.publishTime).toISOString().split('T')[0],
|
||||||
changefreq: 'daily',
|
changefreq: 'daily',
|
||||||
priority: '0.7'
|
priority: '0.7'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useGlobal } from '@/lib/global'
|
import { useGlobal } from '@/lib/global'
|
||||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
import { getGlobalData } from '@/lib/notion/getNotionData'
|
||||||
import BLOG from '@/blog.config'
|
import BLOG from '@/blog.config'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { getLayoutByTheme } from '@/themes/theme'
|
import { getLayoutByTheme } from '@/themes/theme'
|
||||||
@@ -30,7 +30,7 @@ const Tag = props => {
|
|||||||
|
|
||||||
export async function getStaticProps({ params: { tag } }) {
|
export async function getStaticProps({ params: { tag } }) {
|
||||||
const from = 'tag-props'
|
const from = 'tag-props'
|
||||||
const props = await getGlobalNotionData({ from })
|
const props = await getGlobalData({ from })
|
||||||
|
|
||||||
// 过滤状态
|
// 过滤状态
|
||||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.tags && post.tags.includes(tag))
|
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.tags && post.tags.includes(tag))
|
||||||
@@ -68,7 +68,7 @@ function getTagNames(tags) {
|
|||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const from = 'tag-static-path'
|
const from = 'tag-static-path'
|
||||||
const { tagOptions } = await getGlobalNotionData({ from })
|
const { tagOptions } = await getGlobalData({ from })
|
||||||
const tagNames = getTagNames(tagOptions)
|
const tagNames = getTagNames(tagOptions)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useGlobal } from '@/lib/global'
|
import { useGlobal } from '@/lib/global'
|
||||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
import { getGlobalData } from '@/lib/notion/getNotionData'
|
||||||
import BLOG from '@/blog.config'
|
import BLOG from '@/blog.config'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { getLayoutByTheme } from '@/themes/theme'
|
import { getLayoutByTheme } from '@/themes/theme'
|
||||||
@@ -25,7 +25,7 @@ const Tag = props => {
|
|||||||
|
|
||||||
export async function getStaticProps({ params: { tag, page } }) {
|
export async function getStaticProps({ params: { tag, page } }) {
|
||||||
const from = 'tag-page-props'
|
const from = 'tag-page-props'
|
||||||
const props = await getGlobalNotionData({ from })
|
const props = await getGlobalData({ from })
|
||||||
// 过滤状态、标签
|
// 过滤状态、标签
|
||||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.tags && post.tags.includes(tag))
|
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.tags && post.tags.includes(tag))
|
||||||
// 处理文章数
|
// 处理文章数
|
||||||
@@ -44,7 +44,7 @@ export async function getStaticProps({ params: { tag, page } }) {
|
|||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const from = 'tag-page-static-path'
|
const from = 'tag-page-static-path'
|
||||||
const { tagOptions, allPages } = await getGlobalNotionData({ from })
|
const { tagOptions, allPages } = await getGlobalData({ from })
|
||||||
const paths = []
|
const paths = []
|
||||||
tagOptions?.forEach(tag => {
|
tagOptions?.forEach(tag => {
|
||||||
// 过滤状态类型
|
// 过滤状态类型
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
import { getGlobalData } from '@/lib/notion/getNotionData'
|
||||||
import { useGlobal } from '@/lib/global'
|
import { useGlobal } from '@/lib/global'
|
||||||
import BLOG from '@/blog.config'
|
import BLOG from '@/blog.config'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
@@ -30,7 +30,7 @@ const TagIndex = props => {
|
|||||||
|
|
||||||
export async function getStaticProps() {
|
export async function getStaticProps() {
|
||||||
const from = 'tag-index-props'
|
const from = 'tag-index-props'
|
||||||
const props = await getGlobalNotionData({ from })
|
const props = await getGlobalData({ from })
|
||||||
delete props.allPages
|
delete props.allPages
|
||||||
return {
|
return {
|
||||||
props,
|
props,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export default function ArticleDetail(props) {
|
|||||||
if (!post) {
|
if (!post) {
|
||||||
return <></>
|
return <></>
|
||||||
}
|
}
|
||||||
const date = formatDate(post?.publishTime || post?.createdTime, locale.LOCALE)
|
const date = formatDate(post?.publishTime, locale.LOCALE)
|
||||||
return (
|
return (
|
||||||
<div id="container" className="max-w-5xl overflow-x-auto flex-grow mx-auto w-screen md:w-full ">
|
<div id="container" className="max-w-5xl overflow-x-auto flex-grow mx-auto w-screen md:w-full ">
|
||||||
{post?.type && !post?.type !== 'Page' && post?.pageCover && (
|
{post?.type && !post?.type !== 'Page' && post?.pageCover && (
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export default function HeaderArticle({ post, siteInfo }) {
|
|||||||
const headerImage = post?.pageCover ? `url("${post.pageCover}")` : `url("${siteInfo?.pageCover}")`
|
const headerImage = post?.pageCover ? `url("${post.pageCover}")` : `url("${siteInfo?.pageCover}")`
|
||||||
|
|
||||||
const date = formatDate(
|
const date = formatDate(
|
||||||
post?.publishTime || post?.createdTime,
|
post?.publishTime,
|
||||||
locale.LOCALE
|
locale.LOCALE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export const ArticleInfo = (props) => {
|
|||||||
const { post } = props
|
const { post } = props
|
||||||
|
|
||||||
const { locale } = useGlobal()
|
const { locale } = useGlobal()
|
||||||
const date = formatDate(post?.publishTime || post?.createdTime, locale.LOCALE)
|
const date = formatDate(post?.publishTime, locale.LOCALE)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className='mb-3 dark:text-gray-200'>
|
<section className='mb-3 dark:text-gray-200'>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export const LayoutSlug = props => {
|
|||||||
const { locale } = useGlobal()
|
const { locale } = useGlobal()
|
||||||
|
|
||||||
const date = formatDate(
|
const date = formatDate(
|
||||||
post?.publishTime || post?.createdTime,
|
post?.publishTime,
|
||||||
locale.LOCALE
|
locale.LOCALE
|
||||||
)
|
)
|
||||||
if (!post) {
|
if (!post) {
|
||||||
|
|||||||
Reference in New Issue
Block a user