From 43b6be392d91f738a36d6ab7b9965efe6b4af10a Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Fri, 30 Jun 2023 11:51:08 +0800 Subject: [PATCH 1/7] =?UTF-8?q?archieve=20=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/formatDate.js | 4 +--- pages/archive/index.js | 7 +++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/formatDate.js b/lib/formatDate.js index 6f274da8..dae1b68a 100644 --- a/lib/formatDate.js +++ b/lib/formatDate.js @@ -9,9 +9,7 @@ export default function formatDate (date, local) { const d = new Date(date) const options = { year: 'numeric', month: 'short', day: 'numeric' } const res = d.toLocaleDateString(local, options) - return local.slice(0, 2).toLowerCase() === 'zh' - ? res.replace('年', '-').replace('月', '-').replace('日', '') - : res + return res } export function formatDateFmt (timestamp, fmt) { diff --git a/pages/archive/index.js b/pages/archive/index.js index 6d0ebe32..ffba2787 100644 --- a/pages/archive/index.js +++ b/pages/archive/index.js @@ -4,6 +4,7 @@ import { useGlobal } from '@/lib/global' import BLOG from '@/blog.config' import { useRouter } from 'next/router' import { getLayoutByTheme } from '@/themes/theme' +import { formatDateFmt } from '@/lib/formatDate' const ArchiveIndex = props => { const { siteInfo } = props @@ -34,15 +35,13 @@ export async function getStaticProps() { const postsSortByDate = Object.create(props.posts) postsSortByDate.sort((a, b) => { - const dateA = new Date(a?.publishTime || a.createdTime) - const dateB = new Date(b?.publishTime || b.createdTime) - return dateB - dateA + return b?.sortDate - a?.sortDate }) const archivePosts = {} postsSortByDate.forEach(post => { - const date = post.date?.start_date?.slice(0, 7) || post.createdTime + const date = formatDateFmt(post.sortDate, 'yyyy-MM') if (archivePosts[date]) { archivePosts[date].push(post) } else { From 8c76b302131fc5292526828c5ff725288d6b09d8 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Fri, 30 Jun 2023 12:06:42 +0800 Subject: [PATCH 2/7] hexo fix card height --- themes/hexo/components/BlogPostCardInfo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/hexo/components/BlogPostCardInfo.js b/themes/hexo/components/BlogPostCardInfo.js index 7d7bb884..4b7feee6 100644 --- a/themes/hexo/components/BlogPostCardInfo.js +++ b/themes/hexo/components/BlogPostCardInfo.js @@ -10,7 +10,7 @@ import BLOG from '@/blog.config' * @returns */ export const BlogPostCardInfo = ({ post, showPreview, showPageCover, showSummary }) => { - return
+ return
{/* 标题 */} Date: Fri, 30 Jun 2023 12:41:20 +0800 Subject: [PATCH 3/7] =?UTF-8?q?feat=20=E4=BF=9D=E7=95=99=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.config.js | 2 +- next.config.js | 3 +++ pages/[...slug].js | 3 --- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/blog.config.js b/blog.config.js index c6c9faea..6e2ff263 100644 --- a/blog.config.js +++ b/blog.config.js @@ -5,7 +5,7 @@ const BLOG = { process.env.NOTION_PAGE_ID || '02ab3b8678004aa69e9e415905ef32a5', PSEUDO_STATIC: false, // 伪静态路径,开启后所有文章URL都以 .html 结尾。 NEXT_REVALIDATE_SECOND: process.env.NEXT_PUBLIC_REVALIDATE_SECOND || 5, // 更新内容缓存间隔 单位(秒);即每个页面有5秒的纯静态期、此期间无论多少次访问都不会抓取notion数据;调大该值有助于节省Vercel资源、同时提升访问速率,但也会使文章更新有延迟。 - THEME: process.env.NEXT_PUBLIC_THEME || 'fukasawa', // 主题, 支持 ['next','hexo',"fukasawa','medium','example','matery','gitbook','simple'] @see https://preview.tangly1024.com + THEME: process.env.NEXT_PUBLIC_THEME || 'hexo', // 主题, 支持 ['next','hexo',"fukasawa','medium','example','matery','gitbook','simple'] @see https://preview.tangly1024.com THEME_SWITCH: process.env.NEXT_PUBLIC_THEME_SWITCH || false, // 是否显示切换主题按钮 LANG: process.env.NEXT_PUBLIC_LANG || 'zh-CN', // e.g 'zh-CN','en-US' see /lib/lang.js for more. SINCE: 2021, // e.g if leave this empty, current year will be used. diff --git a/next.config.js b/next.config.js index a2618bf4..3569ca92 100644 --- a/next.config.js +++ b/next.config.js @@ -73,5 +73,8 @@ module.exports = withBundleAnalyzer({ config.resolve.alias['@theme-components'] = path.resolve(__dirname, 'themes', THEME) return config + }, + experimental: { + scrollRestoration: true } }) diff --git a/pages/[...slug].js b/pages/[...slug].js index 511ca761..663b9fd9 100644 --- a/pages/[...slug].js +++ b/pages/[...slug].js @@ -61,9 +61,6 @@ const Slug = props => { post.toc = getPageTableOfContents(post, post.blockMap) } } - router.events.on('routeChangeComplete', () => { - window.scrollTo({ top: 0, behavior: 'smooth' }) - }) }, [post]) const meta = { From 008ac7e17bf655395b10ff4b009ea6d11467c3f8 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Fri, 30 Jun 2023 12:42:05 +0800 Subject: [PATCH 4/7] 3.16.3 --- .env.local | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.local b/.env.local index 527622a4..fcca03b1 100644 --- a/.env.local +++ b/.env.local @@ -1,2 +1,2 @@ # 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables -NEXT_PUBLIC_VERSION=3.16.2 \ No newline at end of file +NEXT_PUBLIC_VERSION=3.16.3 \ No newline at end of file diff --git a/package.json b/package.json index 18527c97..b99f9e55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "notion-next", - "version": "3.16.2", + "version": "3.16.3", "homepage": "https://github.com/tangly1024/NotionNext.git", "license": "MIT", "repository": { From 0f7e5f2fb9333524b39c5e570a9712e9bbd2e27d Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Fri, 30 Jun 2023 14:28:15 +0800 Subject: [PATCH 5/7] fix date --- components/CommonHead.js | 2 +- lib/formatDate.js | 5 ++- lib/notion/getAllPosts.js | 2 +- lib/notion/getNotionData.js | 42 ++++++++++----------- lib/notion/getPageProperties.js | 8 ++-- lib/rss.js | 2 +- lib/sitemap.xml.js | 2 +- pages/404.js | 4 +- pages/[...slug].js | 6 +-- pages/archive/index.js | 8 ++-- pages/category/[category]/index.js | 6 +-- pages/category/[category]/page/[page].js | 6 +-- pages/category/index.js | 4 +- pages/index.js | 4 +- pages/page/[page].js | 6 +-- pages/search/[keyword]/index.js | 4 +- pages/search/[keyword]/page/[page].js | 4 +- pages/search/index.js | 4 +- pages/sitemap.xml.js | 6 +-- pages/tag/[tag]/index.js | 6 +-- pages/tag/[tag]/page/[page].js | 6 +-- pages/tag/index.js | 4 +- themes/fukasawa/components/ArticleDetail.js | 2 +- themes/hexo/components/HeaderArticle.js | 2 +- themes/matery/components/ArticleInfo.js | 2 +- themes/medium/LayoutSlug.js | 2 +- 26 files changed, 74 insertions(+), 75 deletions(-) diff --git a/components/CommonHead.js b/components/CommonHead.js index 917a32e3..8eb7c8f8 100644 --- a/components/CommonHead.js +++ b/components/CommonHead.js @@ -56,7 +56,7 @@ const CommonHead = ({ meta, children }) => { <> diff --git a/lib/formatDate.js b/lib/formatDate.js index dae1b68a..0d752555 100644 --- a/lib/formatDate.js +++ b/lib/formatDate.js @@ -9,9 +9,10 @@ export default function formatDate (date, local) { const d = new Date(date) const options = { year: 'numeric', month: 'short', day: 'numeric' } 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) { const date = new Date(timestamp) const o = { diff --git a/lib/notion/getAllPosts.js b/lib/notion/getAllPosts.js index c7401030..ad4acde6 100644 --- a/lib/notion/getAllPosts.js +++ b/lib/notion/getAllPosts.js @@ -45,7 +45,7 @@ export async function getAllPosts({ notionPageData, from, pageType }) { // Sort by date if (BLOG.POSTS_SORT_BY === 'date') { posts.sort((a, b) => { - return b?.sortDate - a?.sortDate + return b?.publishDate - a?.publishDate }) } return posts diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 3df1db8f..5a247f8c 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -20,23 +20,23 @@ import { mapImgUrl, compressImage } from './mapImage' * @returns * */ -export async function getGlobalNotionData({ +export async function getGlobalData({ pageId = BLOG.NOTION_PAGE_ID, from }) { - // 获取Notion数据 - const notionPageData = deepClone(await getNotionPageData({ pageId, from })) - notionPageData.allNavPages = getNavPages({ allPages: notionPageData.allPages }) - delete notionPageData.block - delete notionPageData.schema - delete notionPageData.rawMetadata - delete notionPageData.pageIds - delete notionPageData.viewIds - delete notionPageData.collection - delete notionPageData.collectionQuery - delete notionPageData.collectionId - delete notionPageData.collectionView - return notionPageData + // 从notion获取 + const db = deepClone(await getNotionPageData({ pageId, from })) + // 不返回的敏感数据 + delete db.block + delete db.schema + delete db.rawMetadata + delete db.pageIds + delete db.viewIds + delete db.collection + delete db.collectionQuery + delete db.collectionId + delete db.collectionView + return db } /** @@ -48,8 +48,8 @@ function getLatestPosts({ allPages, from, latestPostCount }) { const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published') const latestPosts = Object.create(allPosts).sort((a, b) => { - const dateA = new Date(a?.lastEditedTime || a?.sortDate) - const dateB = new Date(b?.lastEditedTime || b?.sortDate) + const dateA = new Date(a?.lastEditedTime || a?.publishDate) + const dateB = new Date(b?.lastEditedTime || b?.publishDate) return dateB - dateA }) return latestPosts.slice(0, latestPostCount) @@ -69,12 +69,12 @@ export async function getNotionPageData({ pageId, from }) { console.log('[缓存]:', `from:${from}`, `root-page-id:${pageId}`) return data } - const pageRecordMap = await getDataBaseInfoByNotionAPI({ pageId, from }) + const db = await getDataBaseInfoByNotionAPI({ pageId, from }) // 存入缓存 - if (pageRecordMap) { - await setDataToCache(cacheKey, pageRecordMap) + if (db) { + await setDataToCache(cacheKey, db) } - return pageRecordMap + return db } /** @@ -298,7 +298,7 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) { // Sort by date if (BLOG.POSTS_SORT_BY === 'date') { allPages.sort((a, b) => { - return b?.sortDate - a?.sortDate + return b?.publishDate - a?.publishDate }) } diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index 1fbea148..f2ffe306 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -92,11 +92,9 @@ export default async function getPageProperties(id, block, schema, authToken, ta properties.slug += '.html' } } - - properties.sortDate = value?.date?.start_date || value.created_time - properties.createdTime = formatDate(new Date(value.created_time).toString(), 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.publishDate = new Date(properties?.date?.start_date || value.created_time).getTime() + properties.publishTime = formatDate(properties.publishDate, BLOG.LANG) + properties.lastEditedTime = formatDate(new Date(value?.last_edited_time), BLOG.LANG) properties.fullWidth = value.format?.page_full_width ?? false properties.pageIcon = mapImgUrl(block[id].value?.format?.page_icon, block[id].value) ?? '' properties.pageCover = mapImgUrl(block[id].value?.format?.page_cover, block[id].value) ?? '' diff --git a/lib/rss.js b/lib/rss.js index 88f213e7..d40b940b 100644 --- a/lib/rss.js +++ b/lib/rss.js @@ -46,7 +46,7 @@ export async function generateRss(posts) { link: `${BLOG.LINK}/${post.slug}`, description: post.summary, content: await createFeedContent(post), - date: new Date(post?.publishTime || post?.createdTime) + date: new Date(post?.publishTime) }) } diff --git a/lib/sitemap.xml.js b/lib/sitemap.xml.js index 5a626e75..bb5239f1 100644 --- a/lib/sitemap.xml.js +++ b/lib/sitemap.xml.js @@ -24,7 +24,7 @@ export async function generateSitemapXml({ allPages }) { allPages?.forEach(post => { urls.push({ 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' }) }) diff --git a/pages/404.js b/pages/404.js index 2a521d7c..c770385f 100644 --- a/pages/404.js +++ b/pages/404.js @@ -1,4 +1,4 @@ -import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { getGlobalData } from '@/lib/notion/getNotionData' import { useGlobal } from '@/lib/global' import { useRouter } from 'next/router' import { getLayoutByTheme } from '@/themes/theme' @@ -21,7 +21,7 @@ const NoFound = props => { } export async function getStaticProps () { - const props = (await getGlobalNotionData({ from: '404' })) || {} + const props = (await getGlobalData({ from: '404' })) || {} return { props } } diff --git a/pages/[...slug].js b/pages/[...slug].js index 663b9fd9..df93576c 100644 --- a/pages/[...slug].js +++ b/pages/[...slug].js @@ -1,6 +1,6 @@ import BLOG from '@/blog.config' import { getPostBlocks } from '@/lib/notion' -import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { getGlobalData } from '@/lib/notion/getNotionData' import { useEffect, useState } from 'react' import { idToUuid } from 'notion-utils' import { useRouter } from 'next/router' @@ -87,7 +87,7 @@ export async function getStaticPaths() { } const from = 'slug-paths' - const { allPages } = await getGlobalNotionData({ from }) + const { allPages } = await getGlobalData({ from }) return { paths: allPages?.map(row => ({ params: { slug: [row.slug] } })), fallback: true @@ -102,7 +102,7 @@ export async function getStaticProps({ params: { slug } }) { } } const from = `slug-props-${fullSlug}` - const props = await getGlobalNotionData({ from }) + const props = await getGlobalData({ from }) // 在列表内查找文章 props.post = props?.allPages?.find((p) => { return p.slug === fullSlug || p.id === idToUuid(fullSlug) diff --git a/pages/archive/index.js b/pages/archive/index.js index ffba2787..6225373c 100644 --- a/pages/archive/index.js +++ b/pages/archive/index.js @@ -1,4 +1,4 @@ -import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { getGlobalData } from '@/lib/notion/getNotionData' import React from 'react' import { useGlobal } from '@/lib/global' import BLOG from '@/blog.config' @@ -27,7 +27,7 @@ const ArchiveIndex = props => { } 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') delete props.allPages @@ -35,13 +35,13 @@ export async function getStaticProps() { const postsSortByDate = Object.create(props.posts) postsSortByDate.sort((a, b) => { - return b?.sortDate - a?.sortDate + return b?.publishDate - a?.publishDate }) const archivePosts = {} postsSortByDate.forEach(post => { - const date = formatDateFmt(post.sortDate, 'yyyy-MM') + const date = formatDateFmt(post.publishDate, 'yyyy-MM') if (archivePosts[date]) { archivePosts[date].push(post) } else { diff --git a/pages/category/[category]/index.js b/pages/category/[category]/index.js index 3b37cca9..55300733 100644 --- a/pages/category/[category]/index.js +++ b/pages/category/[category]/index.js @@ -1,4 +1,4 @@ -import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { getGlobalData } from '@/lib/notion/getNotionData' import React from 'react' import { useGlobal } from '@/lib/global' import BLOG from '@/blog.config' @@ -34,7 +34,7 @@ export default function Category(props) { export async function getStaticProps({ params: { category } }) { 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') @@ -61,7 +61,7 @@ export async function getStaticProps({ params: { category } }) { export async function getStaticPaths() { const from = 'category-paths' - const { categoryOptions } = await getGlobalNotionData({ from }) + const { categoryOptions } = await getGlobalData({ from }) return { paths: Object.keys(categoryOptions).map(category => ({ params: { category: categoryOptions[category]?.name } diff --git a/pages/category/[category]/page/[page].js b/pages/category/[category]/page/[page].js index c9b0ae1a..2f860c25 100644 --- a/pages/category/[category]/page/[page].js +++ b/pages/category/[category]/page/[page].js @@ -1,4 +1,4 @@ -import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { getGlobalData } from '@/lib/notion/getNotionData' import React from 'react' import { useGlobal } from '@/lib/global' import BLOG from '@/blog.config' @@ -34,7 +34,7 @@ export default function Category(props) { export async function getStaticProps({ params: { category, page } }) { 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)) @@ -56,7 +56,7 @@ export async function getStaticProps({ params: { category, page } }) { export async function getStaticPaths() { const from = 'category-paths' - const { categoryOptions, allPages } = await getGlobalNotionData({ from }) + const { categoryOptions, allPages } = await getGlobalData({ from }) const paths = [] categoryOptions?.forEach(category => { diff --git a/pages/category/index.js b/pages/category/index.js index 7eb5598e..b4872000 100644 --- a/pages/category/index.js +++ b/pages/category/index.js @@ -1,4 +1,4 @@ -import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { getGlobalData } from '@/lib/notion/getNotionData' import React from 'react' import { useGlobal } from '@/lib/global' import BLOG from '@/blog.config' @@ -30,7 +30,7 @@ export default function Category(props) { } export async function getStaticProps() { - const props = await getGlobalNotionData({ from: 'category-index-props' }) + const props = await getGlobalData({ from: 'category-index-props' }) delete props.allPages return { props, diff --git a/pages/index.js b/pages/index.js index 897e6a11..af85c245 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,6 +1,6 @@ import BLOG from '@/blog.config' import { getPostBlocks } from '@/lib/notion' -import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { getGlobalData } from '@/lib/notion/getNotionData' import { generateRss } from '@/lib/rss' import { generateRobotsTxt } from '@/lib/robots.txt' @@ -24,7 +24,7 @@ const Index = props => { */ export async function getStaticProps() { const from = 'index' - const props = await getGlobalNotionData({ from }) + const props = await getGlobalData({ from }) const { siteInfo } = props props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published') diff --git a/pages/page/[page].js b/pages/page/[page].js index 0751b10b..74b7f25b 100644 --- a/pages/page/[page].js +++ b/pages/page/[page].js @@ -1,6 +1,6 @@ import BLOG from '@/blog.config' import { getPostBlocks } from '@/lib/notion' -import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { getGlobalData } from '@/lib/notion/getNotionData' import { useRouter } from 'next/router' import { getLayoutByTheme } from '@/themes/theme' @@ -30,7 +30,7 @@ const Page = props => { export async function getStaticPaths() { const from = 'page-paths' - const { postCount } = await getGlobalNotionData({ from }) + const { postCount } = await getGlobalData({ from }) const totalPages = Math.ceil(postCount / BLOG.POSTS_PER_PAGE) return { // remove first page, we 're not gonna handle that. @@ -43,7 +43,7 @@ export async function getStaticPaths() { export async function getStaticProps({ params: { page } }) { const from = `page-${page}` - const props = await getGlobalNotionData({ from }) + const props = await getGlobalData({ from }) const { allPages } = props const allPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published') // 处理分页 diff --git a/pages/search/[keyword]/index.js b/pages/search/[keyword]/index.js index 22e47639..59e26f96 100644 --- a/pages/search/[keyword]/index.js +++ b/pages/search/[keyword]/index.js @@ -1,4 +1,4 @@ -import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { getGlobalData } from '@/lib/notion/getNotionData' import { useGlobal } from '@/lib/global' import { getDataFromCache } from '@/lib/cache/cache_manager' import BLOG from '@/blog.config' @@ -31,7 +31,7 @@ const Index = props => { * @returns */ export async function getStaticProps({ params: { keyword } }) { - const props = await getGlobalNotionData({ + const props = await getGlobalData({ from: 'search-props', pageType: ['Post'] }) diff --git a/pages/search/[keyword]/page/[page].js b/pages/search/[keyword]/page/[page].js index 090673b9..e706e9b8 100644 --- a/pages/search/[keyword]/page/[page].js +++ b/pages/search/[keyword]/page/[page].js @@ -1,4 +1,4 @@ -import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { getGlobalData } from '@/lib/notion/getNotionData' import { useGlobal } from '@/lib/global' import { getDataFromCache } from '@/lib/cache/cache_manager' import BLOG from '@/blog.config' @@ -31,7 +31,7 @@ const Index = props => { * @returns */ export async function getStaticProps({ params: { keyword, page } }) { - const props = await getGlobalNotionData({ + const props = await getGlobalData({ from: 'search-props', pageType: ['Post'] }) diff --git a/pages/search/index.js b/pages/search/index.js index 527fd96c..9fe02dbb 100644 --- a/pages/search/index.js +++ b/pages/search/index.js @@ -1,4 +1,4 @@ -import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { getGlobalData } from '@/lib/notion/getNotionData' import { useGlobal } from '@/lib/global' import { useRouter } from 'next/router' import BLOG from '@/blog.config' @@ -45,7 +45,7 @@ const Search = props => { * 浏览器前端搜索 */ export async function getStaticProps() { - const props = await getGlobalNotionData({ + const props = await getGlobalData({ from: 'search-props', pageType: ['Post'] }) diff --git a/pages/sitemap.xml.js b/pages/sitemap.xml.js index 9dbb5ab7..a613a277 100644 --- a/pages/sitemap.xml.js +++ b/pages/sitemap.xml.js @@ -1,10 +1,10 @@ // pages/sitemap.xml.js import { getServerSideSitemap } from 'next-sitemap' -import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { getGlobalData } from '@/lib/notion/getNotionData' import BLOG from '@/blog.config' export const getServerSideProps = async (ctx) => { - const { allPages } = await getGlobalNotionData({ from: 'rss' }) + const { allPages } = await getGlobalData({ from: 'rss' }) const defaultFields = [ { 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 => { return { 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', priority: '0.7' } diff --git a/pages/tag/[tag]/index.js b/pages/tag/[tag]/index.js index cd946bb7..a211fc36 100644 --- a/pages/tag/[tag]/index.js +++ b/pages/tag/[tag]/index.js @@ -1,5 +1,5 @@ import { useGlobal } from '@/lib/global' -import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { getGlobalData } from '@/lib/notion/getNotionData' import BLOG from '@/blog.config' import { useRouter } from 'next/router' import { getLayoutByTheme } from '@/themes/theme' @@ -30,7 +30,7 @@ const Tag = props => { export async function getStaticProps({ params: { tag } }) { 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)) @@ -68,7 +68,7 @@ function getTagNames(tags) { export async function getStaticPaths() { const from = 'tag-static-path' - const { tagOptions } = await getGlobalNotionData({ from }) + const { tagOptions } = await getGlobalData({ from }) const tagNames = getTagNames(tagOptions) return { diff --git a/pages/tag/[tag]/page/[page].js b/pages/tag/[tag]/page/[page].js index 6d599f2d..92d01820 100644 --- a/pages/tag/[tag]/page/[page].js +++ b/pages/tag/[tag]/page/[page].js @@ -1,5 +1,5 @@ import { useGlobal } from '@/lib/global' -import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { getGlobalData } from '@/lib/notion/getNotionData' import BLOG from '@/blog.config' import { useRouter } from 'next/router' import { getLayoutByTheme } from '@/themes/theme' @@ -25,7 +25,7 @@ const Tag = props => { export async function getStaticProps({ params: { tag, page } }) { 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)) // 处理文章数 @@ -44,7 +44,7 @@ export async function getStaticProps({ params: { tag, page } }) { export async function getStaticPaths() { const from = 'tag-page-static-path' - const { tagOptions, allPages } = await getGlobalNotionData({ from }) + const { tagOptions, allPages } = await getGlobalData({ from }) const paths = [] tagOptions?.forEach(tag => { // 过滤状态类型 diff --git a/pages/tag/index.js b/pages/tag/index.js index 66f940f3..54dab9a4 100644 --- a/pages/tag/index.js +++ b/pages/tag/index.js @@ -1,4 +1,4 @@ -import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import { getGlobalData } from '@/lib/notion/getNotionData' import { useGlobal } from '@/lib/global' import BLOG from '@/blog.config' import { useRouter } from 'next/router' @@ -30,7 +30,7 @@ const TagIndex = props => { export async function getStaticProps() { const from = 'tag-index-props' - const props = await getGlobalNotionData({ from }) + const props = await getGlobalData({ from }) delete props.allPages return { props, diff --git a/themes/fukasawa/components/ArticleDetail.js b/themes/fukasawa/components/ArticleDetail.js index 8cfdaba4..32559cfb 100644 --- a/themes/fukasawa/components/ArticleDetail.js +++ b/themes/fukasawa/components/ArticleDetail.js @@ -19,7 +19,7 @@ export default function ArticleDetail(props) { if (!post) { return <> } - const date = formatDate(post?.publishTime || post?.createdTime, locale.LOCALE) + const date = formatDate(post?.publishTime, locale.LOCALE) return (
{post?.type && !post?.type !== 'Page' && post?.pageCover && ( diff --git a/themes/hexo/components/HeaderArticle.js b/themes/hexo/components/HeaderArticle.js index c6867b9a..8d727ed8 100644 --- a/themes/hexo/components/HeaderArticle.js +++ b/themes/hexo/components/HeaderArticle.js @@ -14,7 +14,7 @@ export default function HeaderArticle({ post, siteInfo }) { const headerImage = post?.pageCover ? `url("${post.pageCover}")` : `url("${siteInfo?.pageCover}")` const date = formatDate( - post?.publishTime || post?.createdTime, + post?.publishTime, locale.LOCALE ) diff --git a/themes/matery/components/ArticleInfo.js b/themes/matery/components/ArticleInfo.js index c806028d..4fd2cf8b 100644 --- a/themes/matery/components/ArticleInfo.js +++ b/themes/matery/components/ArticleInfo.js @@ -8,7 +8,7 @@ export const ArticleInfo = (props) => { const { post } = props const { locale } = useGlobal() - const date = formatDate(post?.publishTime || post?.createdTime, locale.LOCALE) + const date = formatDate(post?.publishTime, locale.LOCALE) return (
diff --git a/themes/medium/LayoutSlug.js b/themes/medium/LayoutSlug.js index 39b4103e..ac7f2ea9 100644 --- a/themes/medium/LayoutSlug.js +++ b/themes/medium/LayoutSlug.js @@ -20,7 +20,7 @@ export const LayoutSlug = props => { const { locale } = useGlobal() const date = formatDate( - post?.publishTime || post?.createdTime, + post?.publishTime, locale.LOCALE ) if (!post) { From d92a22a5caaa16e13731177fe484a195340802c4 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Fri, 30 Jun 2023 16:56:49 +0800 Subject: [PATCH 6/7] gitbook - footer --- themes/gitbook/LayoutBase.js | 17 ++++++++++------- themes/gitbook/components/Footer.js | 18 +++++++++--------- themes/gitbook/components/NavPostList.js | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/themes/gitbook/LayoutBase.js b/themes/gitbook/LayoutBase.js index 10a9f7bd..071a68a0 100644 --- a/themes/gitbook/LayoutBase.js +++ b/themes/gitbook/LayoutBase.js @@ -27,7 +27,7 @@ const ThemeGlobalMedium = createContext() * @constructor */ const LayoutBase = (props) => { - const { children, meta, post, allNavPages, slotLeft, slotRight, slotTop, siteInfo } = props + const { children, meta, post, allNavPages, slotLeft, slotRight, slotTop } = props const [tocVisible, changeTocVisible] = useState(false) const [pageNavVisible, changePageNavVisible] = useState(false) const [filterPosts, setFilterPosts] = useState(allNavPages) @@ -58,7 +58,7 @@ const LayoutBase = (props) => { {/* 左侧推拉抽屉 */} - +
diff --git a/themes/gitbook/components/Footer.js b/themes/gitbook/components/Footer.js index 744f9e61..a5ef6f8f 100644 --- a/themes/gitbook/components/Footer.js +++ b/themes/gitbook/components/Footer.js @@ -1,8 +1,7 @@ import React from 'react' import BLOG from '@/blog.config' -import DarkModeButton from '@/components/DarkModeButton' -const Footer = ({ title }) => { +const Footer = ({ siteInfo }) => { const d = new Date() const currentYear = d.getFullYear() const copyrightDate = (function () { @@ -14,23 +13,24 @@ const Footer = ({ title }) => { return ( ) diff --git a/themes/gitbook/components/NavPostList.js b/themes/gitbook/components/NavPostList.js index 0ef304d2..5eeeec2c 100644 --- a/themes/gitbook/components/NavPostList.js +++ b/themes/gitbook/components/NavPostList.js @@ -36,7 +36,7 @@ const NavPostList = (props) => { if (!filteredPosts || filteredPosts.length === 0) { return } else { - return
+ return
{/* 文章列表 */} {filteredPosts?.map((group, index) => )}
From acaf488759ea18f4b136895d57310bcb2b169cee Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Fri, 30 Jun 2023 17:22:53 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=8B=96=E6=8B=BD=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E9=BC=A0=E6=A0=87=E6=A0=B7=E5=BC=8F=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.config.js | 2 +- components/Draggable.js | 8 ++++++-- components/Live2D.js | 8 ++++++-- components/ThemeSwitch.js | 5 ++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/blog.config.js b/blog.config.js index 6e2ff263..9ee86fbd 100644 --- a/blog.config.js +++ b/blog.config.js @@ -154,7 +154,7 @@ const BLOG = { WIDGET_PET_LINK: process.env.NEXT_PUBLIC_WIDGET_PET_LINK || 'https://cdn.jsdelivr.net/npm/live2d-widget-model-wanko@1.0.5/assets/wanko.model.json', // 挂件模型地址 @see https://github.com/xiazeyu/live2d-widget-models - WIDGET_PET_SWITCH_THEME: true, // 点击宠物挂件切换博客主题 + WIDGET_PET_SWITCH_THEME: process.env.NEXT_PUBLIC_WIDGET_PET_SWITCH_THEME || true, // 点击宠物挂件切换博客主题 // 音乐播放插件 MUSIC_PLAYER: process.env.NEXT_PUBLIC_MUSIC_PLAYER || false, // 是否使用音乐播放插件 diff --git a/components/Draggable.js b/components/Draggable.js index 397d584d..44d565b8 100644 --- a/components/Draggable.js +++ b/components/Draggable.js @@ -1,4 +1,4 @@ -import { useRef, useEffect } from 'react' +import { useRef, useEffect, useState } from 'react' /** * 可拖拽组件 */ @@ -7,6 +7,7 @@ export const Draggable = (props) => { const { children } = props const draggableRef = useRef(null) const rafRef = useRef(null) + const [moving, setMoving] = useState(false) let currentObj, offsetX, offsetY useEffect(() => { @@ -54,6 +55,8 @@ export const Draggable = (props) => { event.preventDefault() // 阻止默认的滚动行为 document.documentElement.style.overflow = 'hidden' // 防止页面一起滚动 } + + setMoving(true) offsetX = event.mx - currentObj.offsetLeft offsetY = event.my - currentObj.offsetTop @@ -73,6 +76,7 @@ export const Draggable = (props) => { event = e(event) document.documentElement.style.overflow = 'auto' // 恢复默认的滚动行为 cancelAnimationFrame(rafRef.current) + setMoving(false) currentObj = document.ontouchmove = document.ontouchend = document.onmousemove = document.onmouseup = null } @@ -138,7 +142,7 @@ export const Draggable = (props) => { } }, []) - return
+ return
{children}
} diff --git a/components/Live2D.js b/components/Live2D.js index 2fc6327f..6a2fc624 100644 --- a/components/Live2D.js +++ b/components/Live2D.js @@ -26,7 +26,7 @@ export default function Live2D() { }, [theme]) function handleClick() { - if (BLOG.WIDGET_PET_SWITCH_THEME) { + if (JSON.parse(BLOG.WIDGET_PET_SWITCH_THEME)) { switchTheme() } } @@ -35,5 +35,9 @@ export default function Live2D() { return <> } - return + return e.target.classList.add('cursor-grabbing')} + onMouseUp={(e) => e.target.classList.remove('cursor-grabbing')} + /> } diff --git a/components/ThemeSwitch.js b/components/ThemeSwitch.js index 8fba9304..c0e4b1c2 100644 --- a/components/ThemeSwitch.js +++ b/components/ThemeSwitch.js @@ -23,14 +23,13 @@ const ThemeSwitch = () => { return (<>
-
- - {/*
{theme}
*/} +
+