From 925d41bdbb008d89c9a2962639fa0fde3184468e Mon Sep 17 00:00:00 2001 From: tangly Date: Mon, 17 Oct 2022 21:45:12 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E4=BF=AE=E5=A4=8DH=E6=A0=87=E9=A2=98?= =?UTF-8?q?=E4=B8=8D=E6=8D=A2=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- styles/notion.css | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/styles/notion.css b/styles/notion.css index 6907ff61..c5727c94 100644 --- a/styles/notion.css +++ b/styles/notion.css @@ -388,13 +388,11 @@ .notion-h { position: relative; - display: inline-block; - + display: block; // 修复H标题不换行的问题 font-weight: 600; line-height: 1.3; padding: 3px 2px; margin-bottom: 1px; - max-width: 100%; white-space: pre-wrap; word-break: break-word; From 07d48ae632472081b0f272f86e75c8aa834460c4 Mon Sep 17 00:00:00 2001 From: tangly Date: Mon, 17 Oct 2022 22:06:02 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E4=BA=8C=E7=BA=A7=E7=BC=A9=E8=BF=9Blist?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=B0=8F=E5=86=99=E5=AD=97=E6=AF=8D=E5=B1=95?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- styles/notion.css | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/styles/notion.css b/styles/notion.css index c5727c94..f6a28c5b 100644 --- a/styles/notion.css +++ b/styles/notion.css @@ -388,7 +388,7 @@ .notion-h { position: relative; - display: block; // 修复H标题不换行的问题 + display: block; font-weight: 600; line-height: 1.3; padding: 3px 2px; @@ -653,6 +653,10 @@ svg.notion-page-icon { margin-bottom: 0; } +.notion-list-numbered > .notion-list-numbered { + list-style-type: lower-alpha; +} + .notion-list-disc li { padding-left: 0.1em; } From 96d1a85a93bef965c4239ed581f0c0251a0809fd Mon Sep 17 00:00:00 2001 From: tangly Date: Mon, 17 Oct 2022 22:07:51 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=98=A0=E5=B0=84Notion?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.config.js | 24 +++++++++++++----------- lib/cache/cache_manager.js | 8 ++++---- lib/notion/getAllPageIds.js | 2 +- lib/notion/getNotionData.js | 12 ++++++++++-- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/blog.config.js b/blog.config.js index bf271a5e..212b2801 100644 --- a/blog.config.js +++ b/blog.config.js @@ -128,20 +128,22 @@ const BLOG = { ADSENSE_GOOGLE_ID: process.env.NEXT_PUBLIC_ADSENSE_GOOGLE_ID || '', // 谷歌广告ID e.g ca-pub-xxxxxxxxxxxxxxxx - // 无关紧要的配置 // 自定义配置notion数据库字段名 NOTION_PROPERTY_NAME: { - password: 'password', - type: 'type', - title: 'title', - status: 'status', - summary: 'summary', - slug: 'slug', - category: 'category', - date: 'date', - tags: 'tags', - icon: 'icon' + password: process.env.NEXT_PUBLIC_NOTION_PROPERTY_PASSWORD || 'password', + type: process.env.NEXT_PUBLIC_NOTION_PROPERTY_TYPE || 'type', + title: process.env.NEXT_PUBLIC_NOTION_PROPERTY_TITLE || 'title', + status: process.env.NEXT_PUBLIC_NOTION_PROPERTY_STATUS || 'status', + summary: process.env.NEXT_PUBLIC_NOTION_PROPERTY_SUMMARY || 'summary', + slug: process.env.NEXT_PUBLIC_NOTION_PROPERTY_SLUG || 'slug', + category: process.env.NEXT_PUBLIC_NOTION_PROPERTY_CATEGORY || 'category', + date: process.env.NEXT_PUBLIC_NOTION_PROPERTY_DATE || 'date', + tags: process.env.NEXT_PUBLIC_NOTION_PROPERTY_TAGS || 'tags', + icon: process.env.NEXT_PUBLIC_NOTION_PROPERTY_ICON || 'icon' }, + + ENABLE_CACHE: false, // 开启缓存 会将Notion数据缓存在内存中,稍微提升访问速度,但要更新内容需要多次刷新页面 + AVATAR: '/avatar.png', // 作者头像,被notion中的ICON覆盖。如果没有ICON则取public目录下的avatar.png TITLE: process.env.NEXT_PUBLIC_TITLE || 'NotionNext BLOG', // 站点标题 ,被notion中的页面标题覆盖 DESCRIPTION: diff --git a/lib/cache/cache_manager.js b/lib/cache/cache_manager.js index 6554b014..2a4d8e36 100644 --- a/lib/cache/cache_manager.js +++ b/lib/cache/cache_manager.js @@ -1,7 +1,7 @@ import MemoryCache from './memory_cache' import FileCache from './local_file_cache' import MongoCache from './mongo_db_cache' -const enableCache = true +import BLOG from '@/blog.config' let api if (process.env.MONGO_DB_URL && process.env.MONGO_DB_NAME) { @@ -18,7 +18,7 @@ if (process.env.MONGO_DB_URL && process.env.MONGO_DB_NAME) { * @returns */ export async function getDataFromCache(key) { - if (!enableCache) { + if (!BLOG.ENABLE_CACHE) { return null } const dataFromCache = await api.getCache(key) @@ -29,14 +29,14 @@ export async function getDataFromCache(key) { } export async function setDataToCache(key, data) { - if (!enableCache || !data) { + if (!BLOG.ENABLE_CACHE || !data) { return } await api.setCache(key, data) } export async function delCacheData(key) { - if (!enableCache) { + if (!BLOG.ENABLE_CACHE) { return } await api.delCache(key) diff --git a/lib/notion/getAllPageIds.js b/lib/notion/getAllPageIds.js index 1fbca908..44b80d38 100644 --- a/lib/notion/getAllPageIds.js +++ b/lib/notion/getAllPageIds.js @@ -11,7 +11,7 @@ export default function getAllPageIds (collectionQuery, collectionId, collection view?.collection_group_results?.blockIds?.forEach(id => pageSet.add(id)) // table视图 }) pageIds = [...pageSet] - console.log('PageIds: 从collectionQuery获取', collectionQuery) + console.log('PageIds: 从collectionQuery获取', collectionQuery, pageIds.length) } else if (viewIds && viewIds.length > 0) { const ids = collectionView[viewIds[0]].value.page_sort console.log('PageIds: 从viewId获取', viewIds) diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index bf54561c..b243fadf 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -251,13 +251,21 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { collectionData.push(properties) } } + // 读取映射 配置 + console.log('当前Notion映射配置-(在blog.config.js中配置)', BLOG.NOTION_PROPERTY_NAME) + const { type, status } = BLOG.NOTION_PROPERTY_NAME const allPages = collectionData.filter(post => { - return post.title && ['Page'].indexOf(post?.type?.[0]) > -1 && (post?.status?.[0] === 'Published' || post?.status?.[0] === 'Invisible') + return post && post[type] && + ['Page'].indexOf(post[type]?.[0]) > -1 && + (post[status]?.[0] === 'Published' || post[status]?.[0] === 'Invisible') }) const allPosts = collectionData.filter(post => { - return post.title && ['Post'].indexOf(post?.type?.[0]) > -1 && post?.status?.[0] === 'Published' + return post && post[status] && + ['Post'].indexOf(post[type]?.[0]) > -1 && + post[status]?.[0] === 'Published' }) + console.error('全部单页', allPages.length, '全部博客', allPosts.length) // Sort by date if (BLOG.POSTS_SORT_BY === 'date') { From c5efc841ba70aed6eb251592feb6952af0f201af Mon Sep 17 00:00:00 2001 From: tangly Date: Tue, 18 Oct 2022 12:03:35 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getNotionData.js | 2 +- lib/notion/getPostBlocks.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index b243fadf..177c4900 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -265,7 +265,7 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { ['Post'].indexOf(post[type]?.[0]) > -1 && post[status]?.[0] === 'Published' }) - console.error('全部单页', allPages.length, '全部博客', allPosts.length) + console.log('全部单页', allPages.length, '全部博客', allPosts.length) // Sort by date if (BLOG.POSTS_SORT_BY === 'date') { diff --git a/lib/notion/getPostBlocks.js b/lib/notion/getPostBlocks.js index dfd3988e..f5712b8c 100644 --- a/lib/notion/getPostBlocks.js +++ b/lib/notion/getPostBlocks.js @@ -35,7 +35,7 @@ async function getPageWithRetry(id, from, retryAttempts = 3) { const authToken = BLOG.NOTION_ACCESS_TOKEN || null const api = new NotionAPI({ authToken, userTimeZone: 'Asia/ShangHai' }) const pageData = await api.getPage(id) - console.info('[响应成功]:', `from:${from}`, `id:${id}`) + console.info('[响应成功]:', `from:${from}`) return pageData } catch (e) { console.warn('[响应异常]:', e) From 1fcafeb214ecae42052b47ed30987a6326b357d0 Mon Sep 17 00:00:00 2001 From: tangly Date: Tue, 18 Oct 2022 16:30:38 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E6=96=87=E7=AB=A0=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89Notion=E5=AD=97=E6=AE=B5=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.config.js | 3 + components/CommonHead.js | 2 +- components/NotionPage.js | 2 +- lib/notion/getAllTags.js | 4 +- lib/notion/getNotionData.js | 51 ++++---- lib/notion/getPageProperties.js | 12 +- lib/rss.js | 2 +- pages/{article/[slug].js => [...slug].js} | 16 ++- pages/[slug].js | 115 ------------------ pages/index.js | 5 +- themes/example/LayoutArchive.js | 2 +- themes/example/LayoutCategory.js | 2 +- themes/example/LayoutSearch.js | 2 +- themes/example/LayoutTag.js | 2 +- themes/example/components/BlogList.js | 2 +- themes/example/components/SideBar.js | 2 +- themes/fukasawa/components/ArticleAround.js | 4 +- themes/fukasawa/components/BlogCard.js | 4 +- themes/fukasawa/components/BlogPostArchive.js | 2 +- themes/hexo/components/ArticleAdjacent.js | 4 +- themes/hexo/components/ArticleRecommend.js | 2 +- themes/hexo/components/BlogPostArchive.js | 2 +- themes/hexo/components/BlogPostCard.js | 4 +- themes/hexo/components/LatestPostsGroup.js | 4 +- themes/medium/LayoutArchive.js | 2 +- themes/medium/components/ArticleAround.js | 4 +- themes/medium/components/BlogPostCard.js | 4 +- themes/next/components/BlogAround.js | 4 +- themes/next/components/BlogPostArchive.js | 2 +- themes/next/components/BlogPostCard.js | 6 +- themes/next/components/LatestPostsGroup.js | 4 +- themes/next/components/RecommendPosts.js | 2 +- 32 files changed, 91 insertions(+), 187 deletions(-) rename pages/{article/[slug].js => [...slug].js} (90%) delete mode 100644 pages/[slug].js diff --git a/blog.config.js b/blog.config.js index 212b2801..e0fd64c7 100644 --- a/blog.config.js +++ b/blog.config.js @@ -31,6 +31,9 @@ const BLOG = { BACKGROUND_DARK: '#000000', // use hex value, don't forget '#' SUB_PATH: '', // leave this empty unless you want to deploy in a folder + POST_URL_PREFIX: process.env.NEXT_PUBLIC_POST_URL_PREFIX || 'article', // POST类型文章的默认路径前缀,例如默认POST类型的路径是 /article/[slug] + // 如果此项配置为 '' 空, 则文章将没有前缀路径,使用场景: 希望 文章前缀路径为 /post 的情况 支持多级 + POST_LIST_STYLE: 'page', // ['page','scroll] 文章列表样式:页码分页、单页滚动加载 POST_LIST_PREVIEW: process.env.NEXT_PUBLIC_POST_PREVIEW || 'false', // 是否在列表加载文章预览 POST_PREVIEW_LINES: 12, // 预览博客行数 diff --git a/components/CommonHead.js b/components/CommonHead.js index d8aea1fc..de4c7d25 100644 --- a/components/CommonHead.js +++ b/components/CommonHead.js @@ -44,7 +44,7 @@ const CommonHead = ({ meta, children }) => { {JSON.parse(BLOG.ANALYTICS_BUSUANZI_ENABLE) && } - {meta?.type === 'article' && ( + {meta?.type === 'Post' && ( <> { // return 'https://www.notion.so/' + id.replace(/-/g, '') - return '/article/' + id.replace(/-/g, '') + return '/' + id.replace(/-/g, '') } function getMediumZoomMargin() { diff --git a/lib/notion/getAllTags.js b/lib/notion/getAllTags.js index 33e82f51..098f62fb 100644 --- a/lib/notion/getAllTags.js +++ b/lib/notion/getAllTags.js @@ -7,7 +7,9 @@ import { isIterable } from '../utils' * @param tagOptions tags的下拉选项 * @returns {Promise<{}|*[]>} */ -export function getAllTags({ allPosts, sliceCount = 0, tagOptions }) { +export function getAllTags({ allPages, sliceCount = 0, tagOptions }) { + const allPosts = allPages.filter(page => page.type === 'Post') + if (!allPosts || !tagOptions) { return [] } diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 177c4900..21a43c37 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -21,8 +21,7 @@ import getPageProperties from './getPageProperties' */ export async function getGlobalNotionData({ pageId = BLOG.NOTION_PAGE_ID, - from, - pageType = ['Post'] + from }) { // 获取Notion数据 const notionPageData = deepClone(await getNotionPageData({ pageId, from })) @@ -42,7 +41,9 @@ export async function getGlobalNotionData({ * @param {*}} param0 * @returns */ -function getLatestPosts({ allPosts, from, latestPostCount }) { +function getLatestPosts({ allPages, from, latestPostCount }) { + const allPosts = allPages.filter(page => page.type === 'Post') + const latestPosts = Object.create(allPosts).sort((a, b) => { const dateA = new Date(a?.lastEditedTime || a?.createdTime || a?.date?.start_date) const dateB = new Date(b?.lastEditedTime || b?.createdTime || b?.date?.start_date) @@ -82,7 +83,7 @@ function getCustomNav({ allPages }) { const customNav = [] if (allPages && allPages.length > 0) { allPages.forEach(p => { - if (p?.status?.[0] === 'Published') { + if (p?.status === 'Published' && p?.type === 'Page') { if (p?.slug?.indexOf('http') === 0) { customNav.push({ icon: p.icon || null, name: p.title, to: p.slug, show: true }) } else { @@ -101,7 +102,7 @@ function getCustomNav({ allPages }) { */ function getTagOptions(schema) { if (!schema) return {} - const tagSchema = Object.values(schema).find(e => e.name === 'tags') + const tagSchema = Object.values(schema).find(e => e.name === BLOG.NOTION_PROPERTY_NAME.tags) return tagSchema?.options || [] } @@ -112,7 +113,7 @@ function getTagOptions(schema) { */ function getCategoryOptions(schema) { if (!schema) return {} - const categorySchema = Object.values(schema).find(e => e.name === 'category') + const categorySchema = Object.values(schema).find(e => e.name === BLOG.NOTION_PROPERTY_NAME.category) return categorySchema?.options || [] } @@ -121,7 +122,8 @@ function getCategoryOptions(schema) { * @param allPosts * @returns {Promise<{}|*[]>} */ -function getAllCategories({ allPosts, categoryOptions, sliceCount = 0 }) { +function getAllCategories({ allPages, categoryOptions, sliceCount = 0 }) { + const allPosts = allPages.filter(page => page.type === 'Post') if (!allPosts || !categoryOptions) { return [] } @@ -220,7 +222,7 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { // Check Type Page-Database和Inline-Database if ( rawMetadata?.type !== 'collection_view_page' && - rawMetadata?.type !== 'collection_view' + rawMetadata?.type !== 'collection_view' ) { console.warn(`pageId "${pageId}" is not a database`) return null @@ -252,24 +254,23 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { } } // 读取映射 配置 - console.log('当前Notion映射配置-(在blog.config.js中配置)', BLOG.NOTION_PROPERTY_NAME) - const { type, status } = BLOG.NOTION_PROPERTY_NAME + let postCount = 0 const allPages = collectionData.filter(post => { - return post && post[type] && - ['Page'].indexOf(post[type]?.[0]) > -1 && - (post[status]?.[0] === 'Published' || post[status]?.[0] === 'Invisible') - }) - const allPosts = collectionData.filter(post => { - return post && post[status] && - ['Post'].indexOf(post[type]?.[0]) > -1 && - post[status]?.[0] === 'Published' - }) - console.log('全部单页', allPages.length, '全部博客', allPosts.length) + if (post.type === 'Post' && (post.status === 'Published' || post.status === 'Invisible')) { + postCount++ + } + + return post && + post.type && + (post.type === 'Post' || post.type === 'Page') && + (post.status === 'Published' || post.status === 'Invisible') + } + ) // Sort by date if (BLOG.POSTS_SORT_BY === 'date') { - allPosts.sort((a, b) => { + allPages.sort((a, b) => { const dateA = new Date(a?.date?.start_date || a.createdTime) const dateB = new Date(b?.date?.start_date || b.createdTime) return dateB - dateA @@ -277,15 +278,13 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { } const customNav = getCustomNav({ allPages }) - const postCount = allPosts?.length || 0 - const categories = getAllCategories({ allPosts, categoryOptions, sliceCount: BLOG.PREVIEW_CATEGORY_COUNT }) - const tags = getAllTags({ allPosts, tagOptions, sliceCount: BLOG.PREVIEW_TAG_COUNT }) - const latestPosts = getLatestPosts({ allPosts, from, latestPostCount: 5 }) + const categories = getAllCategories({ allPages, categoryOptions, sliceCount: BLOG.PREVIEW_CATEGORY_COUNT }) + const tags = getAllTags({ allPages, tagOptions, sliceCount: BLOG.PREVIEW_TAG_COUNT }) + const latestPosts = getLatestPosts({ allPages, from, latestPostCount: 5 }) return { siteInfo, allPages, - allPosts, collection, collectionQuery, collectionId, diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index 33324928..4061632c 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -58,6 +58,7 @@ async function getPageProperties(id, block, schema, authToken, tagOptions, siteI } } } + // 设置自定义字段 const fieldNames = BLOG.NOTION_PROPERTY_NAME if (fieldNames) { @@ -65,7 +66,16 @@ async function getPageProperties(id, block, schema, authToken, tagOptions, siteI if (fieldNames[key] && properties[fieldNames[key]]) properties[key] = properties[fieldNames[key]] }) } - properties.slug = properties.slug ?? properties.id + + properties.type = properties.type[0] + properties.status = properties.status[0] + + if (properties.type === 'Post') { + properties.slug = BLOG.POST_URL_PREFIX + '/' + (properties.slug ?? properties.id) + } else { + properties.slug = (properties.slug ?? properties.id) + } + properties.createdTime = formatDate(new Date(value.created_time).toString(), BLOG.LANG) properties.lastEditedTime = formatDate(new Date(value?.last_edited_time).toString(), BLOG.LANG) properties.fullWidth = value.format?.page_full_width ?? false diff --git a/lib/rss.js b/lib/rss.js index 9c394c2c..9019f061 100644 --- a/lib/rss.js +++ b/lib/rss.js @@ -38,7 +38,7 @@ export async function generateRss(posts) { feed.addItem({ title: post.title, guid: `${post.id}`, - link: `${BLOG.LINK}/article/${post.slug}`, + link: `${BLOG.LINK}/${post.slug}`, description: post.summary, content: await createFeedContent(post), date: new Date(post?.date?.start_date || post?.createdTime) diff --git a/pages/article/[slug].js b/pages/[...slug].js similarity index 90% rename from pages/article/[slug].js rename to pages/[...slug].js index a0f2bb55..0cef2223 100644 --- a/pages/article/[slug].js +++ b/pages/[...slug].js @@ -62,8 +62,8 @@ const Slug = props => { const meta = { title: `${post?.title} | ${siteInfo?.title}`, description: post?.summary, - type: 'article', - slug: 'article/' + post?.slug, + type: post.type, + slug: post?.slug, image: post?.page_cover, category: post?.category?.[0], tags: post?.tags @@ -95,13 +95,16 @@ export async function getStaticPaths() { } export async function getStaticProps({ params: { slug } }) { - const from = `slug-props-${slug}` + // slug 是个数组 + const fullSlug = slug.join('/') + const from = `slug-props-${fullSlug}` const props = await getGlobalNotionData({ from, pageType: ['Post'] }) - const allPosts = props.allPosts - props.post = props.allPosts.find((p) => { - return p.slug === slug || p.id === idToUuid(slug) + const allPosts = props.allPages.filter(page => page.type === 'Post') + props.post = allPosts.find((p) => { + return p.slug === fullSlug || p.id === idToUuid(fullSlug) }) if (!props.post) { + console.warn('无效地址', fullSlug) return { props, revalidate: 1 } } props.post.blockMap = await getPostBlocks(props.post.id, 'slug') @@ -114,6 +117,7 @@ export async function getStaticProps({ params: { slug } }) { allPosts, BLOG.POST_RECOMMEND_COUNT ) + delete props.allPages return { props, revalidate: 1 diff --git a/pages/[slug].js b/pages/[slug].js deleted file mode 100644 index 64b949e9..00000000 --- a/pages/[slug].js +++ /dev/null @@ -1,115 +0,0 @@ -import BLOG from '@/blog.config' -import { getPostBlocks } from '@/lib/notion' -import { getGlobalNotionData } from '@/lib/notion/getNotionData' -import { useGlobal } from '@/lib/global' -import * as ThemeMap from '@/themes' -import React from 'react' -import { useRouter } from 'next/router' -import { isBrowser } from '@/lib/utils' - -/** - * 根据notion的slug访问页面,针对类型为Page的页面 - * @param {*} props - * @returns - */ -const Slug = props => { - const { theme, changeLoadingState } = useGlobal() - const ThemeComponents = ThemeMap[theme] - const { post } = props - - if (!post) { - changeLoadingState(true) - const router = useRouter() - setTimeout(() => { - if (isBrowser()) { - const article = document.getElementById('container') - if (!article) { - router.push('/404').then(() => { - console.warn('找不到页面', router.asPath) - }) - } - } - }, 5000) - const meta = { title: `${props?.siteInfo?.title || BLOG.TITLE} | loading` } - return - } - - changeLoadingState(false) - - // 文章锁🔐 - const [lock, setLock] = React.useState(post.password && post.password !== '') - React.useEffect(() => { - if (post.password && post.password !== '') { - setLock(true) - } else { - setLock(false) - } - }, [post]) - - /** - * 验证文章密码 - * @param {*} result - */ - const validPassword = result => { - if (result) { - setLock(false) - } - } - - const { siteInfo } = props - const meta = { - title: `${post?.title} | ${siteInfo?.title}`, - description: post?.summary, - type: 'article', - slug: 'article/' + post?.slug, - image: post?.page_cover, - category: post?.category?.[0], - tags: post?.tags - } - - props = { ...props, meta, lock, setLock, validPassword } - - return -} - -export async function getStaticPaths() { - if (!BLOG.isProd) { - return { - paths: [], - fallback: true - } - } - - const from = 'slug-paths' - const { allPages } = await getGlobalNotionData({ from, pageType: ['Page'] }) - - return { - paths: allPages.map(row => ({ params: { slug: row.slug } })), - fallback: true - } -} - -export async function getStaticProps({ params: { slug } }) { - const from = `slug-props-${slug}` - const props = await getGlobalNotionData({ from, pageType: ['Page'] }) - const { allPages } = props - const page = allPages?.find(p => p.slug === slug) - if (!page) { - return { props: {}, revalidate: 1 } - } - - try { - page.blockMap = await getPostBlocks(page.id, 'slug') - } catch (error) { - console.error('获取文章详情失败', error) - } - - props.post = page - - return { - props, - revalidate: 1 - } -} - -export default Slug diff --git a/pages/index.js b/pages/index.js index bc519e2c..3c49f983 100644 --- a/pages/index.js +++ b/pages/index.js @@ -11,8 +11,9 @@ const Index = props => { export async function getStaticProps() { const from = 'index' - const props = await getGlobalNotionData({ from, pageType: ['Post'] }) - const { allPosts, siteInfo } = props + const props = await getGlobalNotionData({ from }) + const { allPages, siteInfo } = props + const allPosts = allPages.filter(page => page.type === 'Post') const meta = { title: `${siteInfo?.title} | ${siteInfo?.description}`, description: siteInfo?.description, diff --git a/themes/example/LayoutArchive.js b/themes/example/LayoutArchive.js index a8bc68ee..b85860e0 100644 --- a/themes/example/LayoutArchive.js +++ b/themes/example/LayoutArchive.js @@ -43,7 +43,7 @@ export const LayoutArchive = props => { {' '}   diff --git a/themes/example/LayoutCategory.js b/themes/example/LayoutCategory.js index ef344ea2..a9c99d90 100644 --- a/themes/example/LayoutCategory.js +++ b/themes/example/LayoutCategory.js @@ -30,7 +30,7 @@ export const LayoutCategory = props => { {postsToShow.map(p => (

- + {p.title}

diff --git a/themes/example/LayoutSearch.js b/themes/example/LayoutSearch.js index 29a07f99..7c5dbafb 100644 --- a/themes/example/LayoutSearch.js +++ b/themes/example/LayoutSearch.js @@ -62,7 +62,7 @@ export const LayoutSearch = props => { {postsToShow.map(p => (

- + {p.title}

diff --git a/themes/example/LayoutTag.js b/themes/example/LayoutTag.js index e9809123..f60653e3 100644 --- a/themes/example/LayoutTag.js +++ b/themes/example/LayoutTag.js @@ -28,7 +28,7 @@ export const LayoutTag = props => { {postsToShow.map(p => (

- + {p.title}

diff --git a/themes/example/components/BlogList.js b/themes/example/components/BlogList.js index ec2e7a88..1a45d6f7 100644 --- a/themes/example/components/BlogList.js +++ b/themes/example/components/BlogList.js @@ -23,7 +23,7 @@ export const BlogList = (props) => { {posts.map(p => (

- + {p.title}

diff --git a/themes/example/components/SideBar.js b/themes/example/components/SideBar.js index 0e90fe1c..0e737fa3 100644 --- a/themes/example/components/SideBar.js +++ b/themes/example/components/SideBar.js @@ -30,7 +30,7 @@ export const SideBar = (props) => {
    {latestPosts?.map(p => { - return + return
  • {p.title}
  • })} diff --git a/themes/fukasawa/components/ArticleAround.js b/themes/fukasawa/components/ArticleAround.js index 4fb99f1f..1b145b33 100644 --- a/themes/fukasawa/components/ArticleAround.js +++ b/themes/fukasawa/components/ArticleAround.js @@ -10,12 +10,12 @@ export default function ArticleAround ({ prev, next }) { return <> } return
    - + {prev.title} - + {next.title} diff --git a/themes/fukasawa/components/BlogCard.js b/themes/fukasawa/components/BlogCard.js index f7235c71..3cde4df0 100644 --- a/themes/fukasawa/components/BlogCard.js +++ b/themes/fukasawa/components/BlogCard.js @@ -13,7 +13,7 @@ const BlogCard = ({ post, showSummary }) => { className="animate__animated animate__fadeIn flex flex-col-reverse justify-between duration-300" >
    - + {
    {CONFIG_FUKA.POST_LIST_COVER && post?.page_cover && ( - +
    {/* eslint-disable-next-line @next/next/no-img-element */} {
    {post.date?.start_date}{' '}   - + {post.title} diff --git a/themes/hexo/components/ArticleAdjacent.js b/themes/hexo/components/ArticleAdjacent.js index 3ce2d17d..f5d14574 100644 --- a/themes/hexo/components/ArticleAdjacent.js +++ b/themes/hexo/components/ArticleAdjacent.js @@ -11,12 +11,12 @@ export default function ArticleAdjacent ({ prev, next }) { return <> } return
    - + {prev.title} - + {next.title} diff --git a/themes/hexo/components/ArticleRecommend.js b/themes/hexo/components/ArticleRecommend.js index c1273c8a..f5d0b0f3 100644 --- a/themes/hexo/components/ArticleRecommend.js +++ b/themes/hexo/components/ArticleRecommend.js @@ -35,7 +35,7 @@ export default function ArticleRecommend({ recommendPosts, siteInfo }) { {
    {post.date?.start_date}{' '}   - + {post.title} diff --git a/themes/hexo/components/BlogPostCard.js b/themes/hexo/components/BlogPostCard.js index 95bfcfbf..3cb65f81 100644 --- a/themes/hexo/components/BlogPostCard.js +++ b/themes/hexo/components/BlogPostCard.js @@ -14,7 +14,7 @@ const BlogPostCard = ({ post, showSummary }) => { className="animate__animated animate__fadeIn flex flex-col-reverse lg:flex-row justify-between duration-300" >
    - + {
    {CONFIG_HEXO.POST_LIST_COVER && !showPreview && post?.page_cover && !post.results && ( - +
    {/* eslint-disable-next-line @next/next/no-img-element */} {
    {latestPosts.map(post => { - const selected = currentPath === `${BLOG.SUB_PATH}/article/${post.slug}` + const selected = currentPath === `${BLOG.SUB_PATH}/${post.slug}` const headerImage = post?.page_cover ? `url("${post.page_cover}")` : `url("${siteInfo?.pageCover}")` @@ -34,7 +34,7 @@ const LatestPostsGroup = ({ latestPosts, siteInfo }) => { diff --git a/themes/medium/LayoutArchive.js b/themes/medium/LayoutArchive.js index 487734ba..2f4abb2a 100644 --- a/themes/medium/LayoutArchive.js +++ b/themes/medium/LayoutArchive.js @@ -45,7 +45,7 @@ export const LayoutArchive = props => { {' '}   diff --git a/themes/medium/components/ArticleAround.js b/themes/medium/components/ArticleAround.js index 6d613d41..0c4363cc 100644 --- a/themes/medium/components/ArticleAround.js +++ b/themes/medium/components/ArticleAround.js @@ -10,12 +10,12 @@ export default function ArticleAround ({ prev, next }) { return <> } return
    - + {prev.title} - + {next.title} diff --git a/themes/medium/components/BlogPostCard.js b/themes/medium/components/BlogPostCard.js index f4edc4e2..9ad4c46c 100644 --- a/themes/medium/components/BlogPostCard.js +++ b/themes/medium/components/BlogPostCard.js @@ -16,7 +16,7 @@ const BlogPostCard = ({ post, showSummary }) => { className="animate__animated animate__fadeIn duration-300 mb-6 max-w-7xl border-b dark:border-gray-800 " >
    - + {
    - + {locale.COMMON.ARTICLE_DETAIL} diff --git a/themes/next/components/BlogAround.js b/themes/next/components/BlogAround.js index fa9e17fc..9e5f3d6f 100644 --- a/themes/next/components/BlogAround.js +++ b/themes/next/components/BlogAround.js @@ -10,12 +10,12 @@ export default function BlogAround ({ prev, next }) { return <> } return
    - {prev && + {prev && {prev.title} } - {next && + {next && {next.title} diff --git a/themes/next/components/BlogPostArchive.js b/themes/next/components/BlogPostArchive.js index d2d6f857..65049ce4 100644 --- a/themes/next/components/BlogPostArchive.js +++ b/themes/next/components/BlogPostArchive.js @@ -29,7 +29,7 @@ const BlogPostArchive = ({ posts = [], archiveTitle }) => {
    {post.date?.start_date}{' '}   - + {post.title} diff --git a/themes/next/components/BlogPostCard.js b/themes/next/components/BlogPostCard.js index ae2b0b16..3f45add3 100644 --- a/themes/next/components/BlogPostCard.js +++ b/themes/next/components/BlogPostCard.js @@ -18,7 +18,7 @@ const BlogPostCard = ({ post, showSummary }) => { className="flex flex-col-reverse justify-between duration-300" > {latestPosts.map(post => { - const selected = currentPath === `${BLOG.SUB_PATH}/article/${post.slug}` + const selected = currentPath === `${BLOG.SUB_PATH}/${post.slug}` return ( diff --git a/themes/next/components/RecommendPosts.js b/themes/next/components/RecommendPosts.js index c25a710c..d35c65ae 100644 --- a/themes/next/components/RecommendPosts.js +++ b/themes/next/components/RecommendPosts.js @@ -18,7 +18,7 @@ const RecommendPosts = ({ recommendPosts }) => {
      {recommendPosts.map(post => (
    • - + {post.title} From c80450c410723aac2493ca3a1c13facd82f4121d Mon Sep 17 00:00:00 2001 From: tangly Date: Tue, 18 Oct 2022 16:42:55 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getAllPageIds.js | 4 ++-- pages/archive/index.js | 5 ++++- pages/category/[category].js | 4 +++- pages/page/[page].js | 4 +++- pages/search/[keyword].js | 4 +++- pages/search/index.js | 4 +++- pages/tag/[tag].js | 3 ++- 7 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/notion/getAllPageIds.js b/lib/notion/getAllPageIds.js index 44b80d38..e8f6dd8f 100644 --- a/lib/notion/getAllPageIds.js +++ b/lib/notion/getAllPageIds.js @@ -11,10 +11,10 @@ export default function getAllPageIds (collectionQuery, collectionId, collection view?.collection_group_results?.blockIds?.forEach(id => pageSet.add(id)) // table视图 }) pageIds = [...pageSet] - console.log('PageIds: 从collectionQuery获取', collectionQuery, pageIds.length) + // console.log('PageIds: 从collectionQuery获取', collectionQuery, pageIds.length) } else if (viewIds && viewIds.length > 0) { const ids = collectionView[viewIds[0]].value.page_sort - console.log('PageIds: 从viewId获取', viewIds) + // console.log('PageIds: 从viewId获取', viewIds) for (const id of ids) { pageIds.push(id) } diff --git a/pages/archive/index.js b/pages/archive/index.js index fda51dc5..098da940 100644 --- a/pages/archive/index.js +++ b/pages/archive/index.js @@ -20,7 +20,10 @@ const ArchiveIndex = props => { export async function getStaticProps() { const props = await getGlobalNotionData({ from: 'archive-index' }) - props.posts = props.allPosts + const { allPages } = props + const allPosts = allPages.filter(page => page.type === 'Post') + // 处理分页 + props.posts = allPosts return { props, revalidate: 1 diff --git a/pages/category/[category].js b/pages/category/[category].js index ac44bb05..6c07adcf 100644 --- a/pages/category/[category].js +++ b/pages/category/[category].js @@ -26,7 +26,9 @@ export default function Category(props) { export async function getStaticProps({ params: { category } }) { const from = 'category-props' let props = await getGlobalNotionData({ from }) - const posts = props.allPosts.filter( + const { allPages } = props + const allPosts = allPages.filter(page => page.type === 'Post') + const posts = allPosts.filter( post => post && post.category && post.category.includes(category) ) props = { ...props, posts, category } diff --git a/pages/page/[page].js b/pages/page/[page].js index f86b0902..a7b49e82 100644 --- a/pages/page/[page].js +++ b/pages/page/[page].js @@ -38,8 +38,10 @@ export async function getStaticProps({ params: { page } }) { const from = `page-${page}` const props = await getGlobalNotionData({ from }) props.page = page + const { allPages } = props + const allPosts = allPages.filter(page => page.type === 'Post') // 处理分页 - props.posts = props.allPosts.slice( + props.posts = allPosts.slice( BLOG.POSTS_PER_PAGE * (page - 1), BLOG.POSTS_PER_PAGE * page ) diff --git a/pages/search/[keyword].js b/pages/search/[keyword].js index 03fb8109..3de56ed1 100644 --- a/pages/search/[keyword].js +++ b/pages/search/[keyword].js @@ -35,7 +35,9 @@ export async function getStaticProps({ params: { keyword } }) { from: 'search-props', pageType: ['Post'] }) - props.posts = await filterByMemCache(props.allPosts, keyword) + const { allPages } = props + const allPosts = allPages.filter(page => page.type === 'Post') + props.posts = await filterByMemCache(allPosts, keyword) props.keyword = keyword return { props, diff --git a/pages/search/index.js b/pages/search/index.js index 30e97c95..7cee6392 100644 --- a/pages/search/index.js +++ b/pages/search/index.js @@ -52,7 +52,9 @@ export async function getStaticProps() { from: 'search-props', pageType: ['Post'] }) - props.posts = props.allPosts + const { allPages } = props + const allPosts = allPages.filter(page => page.type === 'Post') + props.posts = allPosts return { props, revalidate: 1 diff --git a/pages/tag/[tag].js b/pages/tag/[tag].js index 121dc973..37606158 100644 --- a/pages/tag/[tag].js +++ b/pages/tag/[tag].js @@ -28,7 +28,8 @@ export async function getStaticProps({ params: { tag } }) { includePage: false, tagsCount: 0 }) - const { allPosts } = props + const { allPages } = props + const allPosts = allPages.filter(page => page.type === 'Post') props.posts = allPosts.filter( post => post && post.tags && post.tags.includes(tag) ) From d708c7c6381b6b85eb29f63a8041fa6a080347c1 Mon Sep 17 00:00:00 2001 From: tangly Date: Tue, 18 Oct 2022 16:47:09 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E9=80=82=E9=85=8D=E5=8D=95=E9=A1=B5?= =?UTF-8?q?=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/[...slug].js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/[...slug].js b/pages/[...slug].js index 0cef2223..39246577 100644 --- a/pages/[...slug].js +++ b/pages/[...slug].js @@ -99,8 +99,7 @@ export async function getStaticProps({ params: { slug } }) { const fullSlug = slug.join('/') const from = `slug-props-${fullSlug}` const props = await getGlobalNotionData({ from, pageType: ['Post'] }) - const allPosts = props.allPages.filter(page => page.type === 'Post') - props.post = allPosts.find((p) => { + props.post = props.allPages.find((p) => { return p.slug === fullSlug || p.id === idToUuid(fullSlug) }) if (!props.post) { @@ -109,6 +108,7 @@ export async function getStaticProps({ params: { slug } }) { } props.post.blockMap = await getPostBlocks(props.post.id, 'slug') + const allPosts = props.allPages.filter(page => page.type === 'Post') const index = allPosts.indexOf(props.post) props.prev = allPosts.slice(index - 1, index)[0] ?? allPosts.slice(-1)[0] props.next = allPosts.slice(index + 1, index + 2)[0] ?? allPosts[0] From 47a349dd1880bc6d9f09a387e3b8500d40faf2b9 Mon Sep 17 00:00:00 2001 From: tangly Date: Tue, 18 Oct 2022 16:55:57 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E5=85=A8=E6=96=87=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/cache/cache_manager.js | 17 +++++++++-------- pages/search/[keyword].js | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/cache/cache_manager.js b/lib/cache/cache_manager.js index 2a4d8e36..8796d3f4 100644 --- a/lib/cache/cache_manager.js +++ b/lib/cache/cache_manager.js @@ -17,19 +17,20 @@ if (process.env.MONGO_DB_URL && process.env.MONGO_DB_NAME) { * @param {*} key * @returns */ -export async function getDataFromCache(key) { - if (!BLOG.ENABLE_CACHE) { +export async function getDataFromCache(key, force) { + if (BLOG.ENABLE_CACHE || force) { + const dataFromCache = await api.getCache(key) + if (JSON.stringify(dataFromCache) === '[]') { + return null + } + return api.getCache(key) + } else { return null } - const dataFromCache = await api.getCache(key) - if (JSON.stringify(dataFromCache) === '[]') { - return null - } - return api.getCache(key) } export async function setDataToCache(key, data) { - if (!BLOG.ENABLE_CACHE || !data) { + if (!data) { return } await api.setCache(key, data) diff --git a/pages/search/[keyword].js b/pages/search/[keyword].js index 3de56ed1..dc992481 100644 --- a/pages/search/[keyword].js +++ b/pages/search/[keyword].js @@ -109,7 +109,7 @@ async function filterByMemCache(allPosts, keyword) { } for (const post of allPosts) { const cacheKey = 'page_block_' + post.id - const page = await getDataFromCache(cacheKey) + const page = await getDataFromCache(cacheKey, true) const tagContent = post.tags && Array.isArray(post.tags) ? post.tags.join(' ') : '' const categoryContent = post.category && Array.isArray(post.category) ? post.category.join(' ') : '' const articleInfo = post.title + post.summary + tagContent + categoryContent @@ -123,7 +123,7 @@ async function filterByMemCache(allPosts, keyword) { indexContent = appendText(indexContent, properties, 'caption') }) } - console.log('全文搜索缓存', cacheKey, page != null) + // console.log('全文搜索缓存', cacheKey, page != null) post.results = [] let hitCount = 0 for (const i in indexContent) { From 5a9d0fe5cc120cbb6f117d54f277901eda40606a Mon Sep 17 00:00:00 2001 From: tangly Date: Tue, 18 Oct 2022 18:30:55 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=AF=BC=E8=88=AA=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/hexo/components/Header.js | 7 ++++++- themes/hexo/components/Logo.js | 2 +- themes/hexo/components/MenuButtonGroupTop.js | 10 +++++----- themes/hexo/components/NavButtonGroup.js | 21 ++++++++++++++++++++ themes/hexo/components/TopNav.js | 5 ++++- themes/hexo/config_hexo.js | 2 ++ 6 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 themes/hexo/components/NavButtonGroup.js diff --git a/themes/hexo/components/Header.js b/themes/hexo/components/Header.js index e1fbd29a..6497f95c 100644 --- a/themes/hexo/components/Header.js +++ b/themes/hexo/components/Header.js @@ -1,6 +1,7 @@ import { useEffect, useState } from 'react' import Typed from 'typed.js' import CONFIG_HEXO from '../config_hexo' +import NavButtonGroup from './NavButtonGroup' let wrapperTop = 0 let windowTop = 0 @@ -74,7 +75,7 @@ const Header = props => { className="duration-500 md:bg-fixed w-full bg-cover bg-center h-screen bg-black text-white" style={{ backgroundImage: - `linear-gradient(rgba(0, 0, 0, 0.8), rgba(0,0,0,0.2), rgba(0,0,0,0.2), rgba(0,0,0,0.2), rgba(0, 0, 0, 0.8) ),url("${siteInfo?.pageCover}")` + `linear-gradient(rgba(0, 0, 0, 0.9), rgba(0,0,0,0.5), rgba(0,0,0,0.3), rgba(0,0,0,0.5), rgba(0, 0, 0, 0.9) ),url("${siteInfo?.pageCover}")` }} >
      @@ -82,6 +83,10 @@ const Header = props => {
      + + {/* 首页导航插件 */} + { CONFIG_HEXO.HOME_NAV_BUTTONS && } +
      { diff --git a/themes/hexo/components/Logo.js b/themes/hexo/components/Logo.js index e1adeb3d..f281cb99 100644 --- a/themes/hexo/components/Logo.js +++ b/themes/hexo/components/Logo.js @@ -6,7 +6,7 @@ const Logo = props => { const { siteInfo } = props return
      -
      {siteInfo?.title || BLOG.TITLE}
      +
      {siteInfo?.title || BLOG.TITLE}
      } diff --git a/themes/hexo/components/MenuButtonGroupTop.js b/themes/hexo/components/MenuButtonGroupTop.js index c8d087fc..d27dfc69 100644 --- a/themes/hexo/components/MenuButtonGroupTop.js +++ b/themes/hexo/components/MenuButtonGroupTop.js @@ -9,9 +9,9 @@ const MenuButtonGroupTop = (props) => { let links = [ { icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: CONFIG_HEXO.MENU_SEARCH }, - { icon: 'fas fa-archive', name: locale.COMMON.ARTICLE, to: '/archive', show: CONFIG_HEXO.MENU_ARCHIVE }, - { icon: 'fas fa-folder', name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_HEXO.MENU_CATEGORY }, - { icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: CONFIG_HEXO.MENU_TAG } + { icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', show: CONFIG_HEXO.MENU_ARCHIVE } + // { icon: 'fas fa-folder', name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_HEXO.MENU_CATEGORY }, + // { icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: CONFIG_HEXO.MENU_TAG } ] if (customNav) { @@ -22,8 +22,8 @@ const MenuButtonGroupTop = (props) => { {links.map(link => { if (link.show) { return - -
      + +
      {link.name}
      diff --git a/themes/hexo/components/NavButtonGroup.js b/themes/hexo/components/NavButtonGroup.js new file mode 100644 index 00000000..e33f7f8c --- /dev/null +++ b/themes/hexo/components/NavButtonGroup.js @@ -0,0 +1,21 @@ + +import React from 'react' +import Link from 'next/link' + +/** + * 首页导航大按钮组件 + * @param {*} props + * @returns + */ +const NavButtonGroup = (props) => { + const { categories } = props + + return
      +} +export default NavButtonGroup diff --git a/themes/hexo/components/TopNav.js b/themes/hexo/components/TopNav.js index 3cd3528f..1969fe3d 100644 --- a/themes/hexo/components/TopNav.js +++ b/themes/hexo/components/TopNav.js @@ -30,6 +30,7 @@ const TopNav = props => { const nav = document.querySelector('#sticky-nav') const header = document.querySelector('#header') const showNav = scrollS <= windowTop || scrollS < 5 || (header && scrollS <= header.clientHeight)// 非首页无大图时影藏顶部 滚动条置顶时隐藏 + // 是否将导航栏透明 const navTransparent = (scrollS < document.documentElement.clientHeight - 12 && router.route === '/') || scrollS < 300 // 透明导航条的条件 if (header && navTransparent) { @@ -37,11 +38,13 @@ const TopNav = props => { nav && nav.classList.replace('text-black', 'text-white') nav && nav.classList.replace('border', 'border-transparent') nav && nav.classList.replace('shadow-md', 'shadow-none') + nav && nav.classList.replace('dark:bg-hexo-black-gray', 'transparent') } else { nav && nav.classList.replace('bg-none', 'bg-white') nav && nav.classList.replace('text-white', 'text-black') nav && nav.classList.replace('border-transparent', 'border') nav && nav.classList.replace('shadow-none', 'shadow-md') + nav && nav.classList.replace('transparent', 'dark:bg-hexo-black-gray') } if (!showNav) { @@ -118,7 +121,7 @@ const TopNav = props => { {/* 导航栏 */} -