diff --git a/themes/hexo/components/TocDrawerButton.js b/themes/hexo/components/TocDrawerButton.js
index 144af536..fc87cefc 100644
--- a/themes/hexo/components/TocDrawerButton.js
+++ b/themes/hexo/components/TocDrawerButton.js
@@ -10,10 +10,10 @@ import CONFIG_HEXO from '../config_hexo'
* @constructor
*/
const TocDrawerButton = (props) => {
+ const { locale } = useGlobal()
if (!CONFIG_HEXO.WIDGET_TOC) {
return <>>
}
- const { locale } = useGlobal()
return (
)
diff --git a/themes/medium/LayoutBase.js b/themes/medium/LayoutBase.js
index 0361af90..9621ca8e 100644
--- a/themes/medium/LayoutBase.js
+++ b/themes/medium/LayoutBase.js
@@ -1,5 +1,5 @@
import CommonHead from '@/components/CommonHead'
-import React from 'react'
+import { useState, createContext, useContext } from 'react'
import Footer from './components/Footer'
import InfoCard from './components/InfoCard'
import RevolverMaps from './components/RevolverMaps'
@@ -12,6 +12,7 @@ import { useGlobal } from '@/lib/global'
import { useRouter } from 'next/router'
import Live2D from '@/components/Live2D'
import BLOG from '@/blog.config'
+const ThemeGlobalMedium = createContext()
/**
* 基础布局 采用左右两侧布局,移动端使用顶部导航栏
@@ -23,9 +24,10 @@ const LayoutBase = props => {
const { children, meta, showInfoCard = true, slotRight, slotTop, siteInfo } = props
const { locale } = useGlobal()
const router = useRouter()
+ const [tocVisible, changeTocVisible] = useState(false)
return (
-
+
{/* 桌面端左侧菜单 */}
@@ -62,9 +64,10 @@ const LayoutBase = props => {
{/* 移动端底部 */}
+
+
)
}
export default LayoutBase
+export const useMediumGlobal = () => useContext(ThemeGlobalMedium)
diff --git a/themes/medium/LayoutSlug.js b/themes/medium/LayoutSlug.js
index bdeec1a5..086215fc 100644
--- a/themes/medium/LayoutSlug.js
+++ b/themes/medium/LayoutSlug.js
@@ -2,27 +2,102 @@ import LayoutBase from './LayoutBase'
import { useGlobal } from '@/lib/global'
import React from 'react'
import Catalog from './components/Catalog'
-import { ArticleDetail } from './components/ArticleDetail'
import { ArticleLock } from './components/ArticleLock'
+import JumpToTopButton from './components/JumpToTopButton'
+import formatDate from '@/lib/formatDate'
+import BLOG from '@/blog.config'
+import Link from 'next/link'
+import NotionPage from '@/components/NotionPage'
+import CONFIG_MEDIUM from './config_medium'
+import Comment from '@/components/Comment'
+import ArticleAround from './components/ArticleAround'
+import TocDrawer from './components/TocDrawer'
+import CategoryItem from './components/CategoryItem'
+import TagItemMini from './components/TagItemMini'
export const LayoutSlug = props => {
- const { post, lock, validPassword } = props
+ const { post, prev, next, siteInfo, lock, validPassword } = props
const { locale } = useGlobal()
+ const date = formatDate(
+ post?.date?.start_date || post?.createdTime,
+ locale.LOCALE
+ )
if (!post) {
return
+ />
}
const slotRight = post?.toc && post?.toc?.length > 3 && (
-
-
-
+
+
+
+
)
return (
-
- {!lock ? : }
-
+
+ {/* 文章锁 */}
+ {lock && }
+
+ {!lock &&
+
+ {/* title */}
+
{post?.title}
+
+ {/* meta */}
+
+
+
{date}
+
|
+
{post.lastEditedTime}
+
+
+
+
+
+
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+

+
+
+ {BLOG.AUTHOR}
+
+
+
+
+
+ {/* Notion文章主体 */}
+
+
+
+
+
+
+ {CONFIG_MEDIUM.POST_DETAIL_CATEGORY && post.category &&
}
+
+ {CONFIG_MEDIUM.POST_DETAIL_TAG && post?.tagItems?.map(tag => )}
+
+
+ {post.type === 'Post' && }
+
+
+
+
+
}
+
)
}
diff --git a/themes/medium/components/ArticleDetail.js b/themes/medium/components/ArticleDetail.js
deleted file mode 100644
index 296a7145..00000000
--- a/themes/medium/components/ArticleDetail.js
+++ /dev/null
@@ -1,78 +0,0 @@
-import Comment from '@/components/Comment'
-import Link from 'next/link'
-import ArticleAround from './ArticleAround'
-import CategoryItem from './CategoryItem'
-import TagItemMini from './TagItemMini'
-import CONFIG_MEDIUM from '../config_medium'
-import formatDate from '@/lib/formatDate'
-import { useGlobal } from '@/lib/global'
-import BLOG from '@/blog.config'
-import NotionPage from '@/components/NotionPage'
-import React from 'react'
-
-export const ArticleDetail = props => {
- const { post, prev, next, siteInfo } = props
- const { locale } = useGlobal()
-
- const date = formatDate(
- post?.date?.start_date || post?.createdTime,
- locale.LOCALE
- )
- return (
-
-
- {/* title */}
-
{post?.title}
-
- {/* meta */}
-
-
-
{date}
-
|
-
{post.lastEditedTime}
-
-
-
-
-
-
- {/* eslint-disable-next-line @next/next/no-img-element */}
-

-
-
- {BLOG.AUTHOR}
-
-
-
-
- {/* Notion文章主体 */}
-
-
-
-
-
-
- {CONFIG_MEDIUM.POST_DETAIL_CATEGORY && post.category &&
}
-
- {CONFIG_MEDIUM.POST_DETAIL_TAG && post?.tagItems?.map(tag => )}
-
-
- {post.type === 'Post' && }
-
-
-
- );
-}
diff --git a/themes/medium/components/BottomMenuBar.js b/themes/medium/components/BottomMenuBar.js
index 83bdb83e..45215f50 100644
--- a/themes/medium/components/BottomMenuBar.js
+++ b/themes/medium/components/BottomMenuBar.js
@@ -1,16 +1,19 @@
import Link from 'next/link'
import React from 'react'
+import { useMediumGlobal } from '../LayoutBase'
import JumpToTopButton from './JumpToTopButton'
-export default function BottomMenuBar ({ className }) {
+export default function BottomMenuBar ({ post, className }) {
+ const { tocVisible, changeTocVisible } = useMediumGlobal()
+ const showTocBotton = post?.toc?.length > 0
+
+ const toggleToc = () => {
+ changeTocVisible(!tocVisible)
+ }
+
return (
-
-
-
-
-
@@ -19,6 +22,14 @@ export default function BottomMenuBar ({ className }) {
+ {showTocBotton &&
+
+
}
+ { !showTocBotton &&
+
+
+
+ }
)
diff --git a/themes/medium/components/Catalog.js b/themes/medium/components/Catalog.js
index b92cc880..af5e4555 100644
--- a/themes/medium/components/Catalog.js
+++ b/themes/medium/components/Catalog.js
@@ -2,7 +2,7 @@ import React, { useRef } from 'react'
import throttle from 'lodash.throttle'
import { uuidToId } from 'notion-utils'
import Progress from './Progress'
-import JumpToTopButton from './JumpToTopButton'
+
/**
* 目录导航组件
* @param toc
@@ -85,7 +85,6 @@ const Catalog = ({ toc }) => {
})}
-
}
diff --git a/themes/medium/components/JumpToTopButton.js b/themes/medium/components/JumpToTopButton.js
index d714f0d5..2d83338c 100644
--- a/themes/medium/components/JumpToTopButton.js
+++ b/themes/medium/components/JumpToTopButton.js
@@ -11,10 +11,10 @@ import CONFIG_MEDIUM from '../config_medium'
* @constructor
*/
const JumpToTopButton = ({ showPercent = false, percent, className }) => {
+ const { locale } = useGlobal()
if (!CONFIG_MEDIUM.WIDGET_TO_TOP) {
return <>>
}
- const { locale } = useGlobal()
return ( window.scrollTo({ top: 0, behavior: 'smooth' })} >
diff --git a/themes/medium/components/TocDrawer.js b/themes/medium/components/TocDrawer.js
new file mode 100644
index 00000000..366f8bc9
--- /dev/null
+++ b/themes/medium/components/TocDrawer.js
@@ -0,0 +1,35 @@
+import Catalog from './Catalog'
+import { useMediumGlobal } from '../LayoutBase'
+
+/**
+ * 悬浮抽屉目录
+ * @param toc
+ * @param post
+ * @returns {JSX.Element}
+ * @constructor
+ */
+const TocDrawer = ({ post, cRef }) => {
+ const { tocVisible, changeTocVisible } = useMediumGlobal()
+ const switchVisible = () => {
+ changeTocVisible(!tocVisible)
+ }
+ return <>
+
+ {/* 侧边菜单 */}
+
+ {post && <>
+
+
+
+ >}
+
+
+ {/* 背景蒙版 */}
+
+ >
+}
+export default TocDrawer