+
-
+
{links?.map(link => collapseRef.current?.updateCollapseHeight(param)}/>)}
+
+ {JSON.parse(CONFIG.MENU_RANDOM_POST) &&
}
+ {JSON.parse(CONFIG.MENU_SEARCH_BUTTON) &&
}
+
)
}
export default Nav
+
+/**
+ *
+ {!JSON.parse(BLOG.THEME_SWITCH) &&
}
+
+
+ */
diff --git a/themes/nobelium/components/RandomPostButton.js b/themes/nobelium/components/RandomPostButton.js
new file mode 100644
index 00000000..a8a0597f
--- /dev/null
+++ b/themes/nobelium/components/RandomPostButton.js
@@ -0,0 +1,26 @@
+import BLOG from '@/blog.config'
+import { useGlobal } from '@/lib/global'
+import { useRouter } from 'next/router'
+
+/**
+ * 随机跳转到一个文章
+ */
+export default function RandomPostButton(props) {
+ const { latestPosts } = props
+ const router = useRouter()
+ const { locale } = useGlobal()
+ /**
+ * 随机跳转文章
+ */
+ function handleClick() {
+ const randomIndex = Math.floor(Math.random() * latestPosts.length)
+ const randomPost = latestPosts[randomIndex]
+ router.push(`${BLOG.SUB_PATH}/${randomPost?.slug}`)
+ }
+
+ return (
+
+
+
+ )
+}
diff --git a/themes/nobelium/components/SearchButton.js b/themes/nobelium/components/SearchButton.js
new file mode 100644
index 00000000..91e805c3
--- /dev/null
+++ b/themes/nobelium/components/SearchButton.js
@@ -0,0 +1,28 @@
+import BLOG from '@/blog.config'
+import { useGlobal } from '@/lib/global'
+import { useRouter } from 'next/router'
+import { useNobeliumGlobal } from '..'
+
+/**
+ * 搜索按钮
+ * @returns
+ */
+export default function SearchButton(props) {
+ const { locale } = useGlobal()
+ const { searchModal } = useNobeliumGlobal()
+ const router = useRouter()
+
+ function handleSearch() {
+ if (BLOG.ALGOLIA_APP_ID) {
+ searchModal.current.openSearch()
+ } else {
+ router.push('/search')
+ }
+ }
+
+ return <>
+
+
+
+ >
+}
diff --git a/themes/nobelium/config.js b/themes/nobelium/config.js
index 75f2e597..18dd8488 100644
--- a/themes/nobelium/config.js
+++ b/themes/nobelium/config.js
@@ -1,13 +1,17 @@
const CONFIG = {
- // 菜单配置
+ NAV_NOTION_ICON: true, // 是否读取Notion图标作为站点头像 ; 否则默认显示黑色SVG方块
+
+ // 特殊菜单
+ MENU_RANDOM_POST: true, // 是否显示随机跳转文章按钮
+ MENU_SEARCH_BUTTON: true, // 是否显示搜索按钮,该按钮支持Algolia搜索
+
+ // 默认菜单配置 (开启自定义菜单后,以下配置则失效,请在Notion中自行配置菜单)
MENU_CATEGORY: false, // 显示分类
MENU_TAG: true, // 显示标签
MENU_ARCHIVE: false, // 显示归档
MENU_SEARCH: true, // 显示搜索
- MENU_RSS: false, // 显示订阅
-
- NAV_NOTION_ICON: true // 是否读取Notion图标作为站点头像
+ MENU_RSS: false // 显示订阅
}
export default CONFIG
diff --git a/themes/nobelium/index.js b/themes/nobelium/index.js
index af1c427e..dae3c2d3 100644
--- a/themes/nobelium/index.js
+++ b/themes/nobelium/index.js
@@ -1,6 +1,6 @@
import BLOG from '@/blog.config'
import CONFIG from './config'
-import React, { useEffect, useState } from 'react'
+import React, { createContext, useEffect, useState, useContext, useRef } from 'react'
import Nav from './components/Nav'
import { Footer } from './components/Footer'
import JumpToTopButton from './components/JumpToTopButton'
@@ -24,6 +24,11 @@ import { Transition } from '@headlessui/react'
import { Style } from './style'
import replaceSearchResult from '@/components/Mark'
import CommonHead from '@/components/CommonHead'
+import AlgoliaSearchModal from '@/components/AlgoliaSearchModal'
+
+// 主题全局状态
+const ThemeGlobalNobelium = createContext()
+export const useNobeliumGlobal = () => useContext(ThemeGlobalNobelium)
/**
* 基础布局 采用左右两侧布局,移动端使用顶部导航栏
@@ -36,51 +41,58 @@ const LayoutBase = props => {
const fullWidth = post?.fullWidth ?? false
const { onLoading } = useGlobal()
+ const searchModal = useRef(null)
return (
-
- {/* SEO相关 */}
-
- {/* SEO相关 */}
-
+
+
+ {/* SEO相关 */}
+
+ {/* SEO相关 */}
+
- {/* 顶部导航栏 */}
-
+ {/* 顶部导航栏 */}
+
- {/* 主区 */}
-
+ {/* 主区 */}
+
-
- {/* 顶部插槽 */}
- {topSlot}
- {children}
-
+
+ {/* 顶部插槽 */}
+ {topSlot}
+ {children}
+
-
+
- {/* 页脚 */}
-
+ {/* 页脚 */}
+
+
+ {/* 右下悬浮 */}
+
+
+
+
+ {/* 左下悬浮 */}
+
+
+
+
+ {/* 搜索框 */}
+
- {/* 右下悬浮 */}
-
-
-
- {/* 左下悬浮 */}
-
-
-
-
+
)
}
From cfab52c569bd2b0f350317e07683ed840ad57cfe Mon Sep 17 00:00:00 2001
From: "tangly1024.com"
Date: Mon, 7 Aug 2023 18:22:39 +0800
Subject: [PATCH 3/6] 4.0.12
---
.env.local | 2 +-
blog.config.js | 4 +-
components/CommonScript.js | 4 +-
components/Twikoo.js | 29 +-
lib/utils.js | 11 +-
package-lock.json | 9371 ++++++++++++++++++++++++++++++++++++
package.json | 2 +-
public/js/cusdis.es.js | 107 +
8 files changed, 9501 insertions(+), 29 deletions(-)
create mode 100644 package-lock.json
create mode 100644 public/js/cusdis.es.js
diff --git a/.env.local b/.env.local
index 691ba963..52c93190 100644
--- a/.env.local
+++ b/.env.local
@@ -1,2 +1,2 @@
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables
-NEXT_PUBLIC_VERSION=4.0.11
\ No newline at end of file
+NEXT_PUBLIC_VERSION=4.0.12
\ No newline at end of file
diff --git a/blog.config.js b/blog.config.js
index 92f980a0..54a056cf 100644
--- a/blog.config.js
+++ b/blog.config.js
@@ -232,7 +232,7 @@ const BLOG = {
// twikoo
COMMENT_TWIKOO_ENV_ID: process.env.NEXT_PUBLIC_COMMENT_ENV_ID || '', // TWIKOO后端地址 腾讯云环境填envId;Vercel环境填域名,教程:https://tangly1024.com/article/notionnext-twikoo
COMMENT_TWIKOO_COUNT_ENABLE: process.env.NEXT_PUBLIC_COMMENT_TWIKOO_COUNT_ENABLE || false, // 博客列表是否显示评论数
- COMMENT_TWIKOO_CDN_URL: process.env.NEXT_PUBLIC_COMMENT_TWIKOO_CDN_URL || 'https://cdn.staticfile.org/twikoo/1.6.16/twikoo.all.min.js', // twikoo客户端cdn
+ COMMENT_TWIKOO_CDN_URL: process.env.NEXT_PUBLIC_COMMENT_TWIKOO_CDN_URL || 'https://cdn.staticfile.org/twikoo/1.6.16/twikoo.min.js', // twikoo客户端cdn
// utterance
COMMENT_UTTERRANCES_REPO:
@@ -262,7 +262,7 @@ const BLOG = {
process.env.NEXT_PUBLIC_COMMENT_CUSDIS_HOST || 'https://cusdis.com', // data-host, change this if you're using self-hosted version
COMMENT_CUSDIS_SCRIPT_SRC:
process.env.NEXT_PUBLIC_COMMENT_CUSDIS_SCRIPT_SRC ||
- 'https://cusdis.com/js/cusdis.es.js', // change this if you're using self-hosted version
+ '/js/cusdis.es.js', // change this if you're using self-hosted version
// gitalk评论插件 更多参考 https://gitalk.github.io/
COMMENT_GITALK_REPO: process.env.NEXT_PUBLIC_COMMENT_GITALK_REPO || '', // 你的Github仓库名,例如 'NotionNext'
diff --git a/components/CommonScript.js b/components/CommonScript.js
index 4bef4da0..fb3c7097 100644
--- a/components/CommonScript.js
+++ b/components/CommonScript.js
@@ -38,7 +38,9 @@ const CommonScript = () => {
/>
>)}
- {BLOG.COMMENT_CUSDIS_APP_ID && }
+ {BLOG.COMMENT_CUSDIS_APP_ID && }
+
+ {BLOG.COMMENT_TWIKOO_ENV_ID &&