From c929d6fa02a3952c2af987524f79cbe3e23acf1e Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Sat, 12 Feb 2022 17:09:00 +0800 Subject: [PATCH 1/2] Medium V2.0 --- components/Tabs.js | 6 +- themes/Medium/LayoutBase.js | 52 ++++++++++--- themes/Medium/LayoutIndex.js | 1 - themes/Medium/LayoutPage.js | 3 +- themes/Medium/LayoutSearch.js | 43 +++++------ themes/Medium/LayoutSlug.js | 34 +++++---- themes/Medium/components/BlogPostListPage.js | 23 +++++- themes/Medium/components/BottomMenuBar.js | 23 ++++++ themes/Medium/components/CategoryGroup.js | 30 ++++++++ themes/Medium/components/InfoCard.js | 12 +-- themes/Medium/components/LogoBar.js | 29 ++++---- themes/Medium/components/RevolverMaps.js | 2 +- themes/Medium/components/SearchInput.js | 77 ++++++++++++++++++++ themes/Medium/components/SocialButton.js | 2 +- themes/Medium/components/TagGroups.js | 29 ++++++++ themes/Medium/components/TagItemMini.js | 2 +- themes/Medium/components/TopNavBar.js | 9 +++ 17 files changed, 294 insertions(+), 83 deletions(-) create mode 100644 themes/Medium/components/BottomMenuBar.js create mode 100644 themes/Medium/components/CategoryGroup.js create mode 100644 themes/Medium/components/SearchInput.js create mode 100644 themes/Medium/components/TagGroups.js create mode 100644 themes/Medium/components/TopNavBar.js diff --git a/components/Tabs.js b/components/Tabs.js index 66012477..6f7497ba 100644 --- a/components/Tabs.js +++ b/components/Tabs.js @@ -5,7 +5,7 @@ import React, { useState } from 'react' * @param {*} param0 * @returns */ -const Tabs = ({ children }) => { +const Tabs = ({ className, children }) => { if (!children) { return <> } @@ -18,7 +18,7 @@ const Tabs = ({ children }) => { }) if (count === 1) { - return
+ return
{children}
} @@ -29,7 +29,7 @@ const Tabs = ({ children }) => { setCurrentTab(i) } - return
+ return
diff --git a/themes/Medium/LayoutBase.js b/themes/Medium/LayoutBase.js index cc57b3da..3cd0f7bb 100644 --- a/themes/Medium/LayoutBase.js +++ b/themes/Medium/LayoutBase.js @@ -2,16 +2,14 @@ import CommonHead from '@/components/CommonHead' import React from 'react' import Footer from './components/Footer' import InfoCard from './components/InfoCard' -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import RevolverMaps from './components/RevolverMaps' import CONFIG_MEDIUM from './config_medium' import Tabs from '@/components/Tabs' -import { faHome } from '@fortawesome/free-solid-svg-icons' import TopNavBar from './components/TopNavBar' -import Link from 'next/link' import SearchInput from './components/SearchInput' -import { useRouter } from 'next/router' import BottomMenuBar from './components/BottomMenuBar' +import { useGlobal } from '@/lib/global' +import JumpToTopButton from './components/JumpToTopButton' /** * 基础布局 采用左右两侧布局,移动端使用顶部导航栏 @@ -21,6 +19,7 @@ import BottomMenuBar from './components/BottomMenuBar' */ const LayoutBase = props => { const { children, meta, showInfoCard = true, slotRight } = props + const { locale } = useGlobal() return (
@@ -28,19 +27,11 @@ const LayoutBase = props => {
{/* 桌面端左侧菜单 */} -
-
- -
- -
- -
-
+ {/* */}
{/* 移动端顶部菜单 */} - +
{children}
@@ -49,8 +40,8 @@ const LayoutBase = props => { {/* 桌面端右侧 */}
- {slotRight &&
{slotRight}
} -
+ {slotRight} +
{showInfoCard && } {CONFIG_MEDIUM.WIDGET_REVOLVER_MAPS === 'true' && } @@ -60,8 +51,8 @@ const LayoutBase = props => {
{/* 移动端底部 */} - -
+ +
) } diff --git a/themes/Medium/LayoutSlug.js b/themes/Medium/LayoutSlug.js index 14419392..015e6d29 100644 --- a/themes/Medium/LayoutSlug.js +++ b/themes/Medium/LayoutSlug.js @@ -14,7 +14,7 @@ import { useGlobal } from '@/lib/global' import formatDate from '@/lib/formatDate' import Link from 'next/link' import mediumZoom from 'medium-zoom' -import { useEffect, useRef } from 'react' +import React, { useEffect, useRef } from 'react' import ArticleAround from './components/ArticleAround' import Catalog from './components/Catalog' @@ -56,7 +56,9 @@ export const LayoutSlug = (props) => { } }) - return }> + const slotRight = post?.toc &&
+ + return

{post?.title}

diff --git a/themes/Medium/components/BlogPostCard.js b/themes/Medium/components/BlogPostCard.js index a9e1ee5c..76ab1933 100644 --- a/themes/Medium/components/BlogPostCard.js +++ b/themes/Medium/components/BlogPostCard.js @@ -15,7 +15,7 @@ const BlogPostCard = ({ post, showSummary }) => {
- + {post.title} diff --git a/themes/Medium/components/BottomMenuBar.js b/themes/Medium/components/BottomMenuBar.js index 75c2a9e0..6e8e0c71 100644 --- a/themes/Medium/components/BottomMenuBar.js +++ b/themes/Medium/components/BottomMenuBar.js @@ -2,6 +2,7 @@ import { faHome, faSearch } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import Link from 'next/link' import React from 'react' +import JumpToTopButton from '@/themes/Medium/components/JumpToTopButton' export default function BottomMenuBar ({ className }) { return ( @@ -17,6 +18,9 @@ export default function BottomMenuBar ({ className }) {
+
+ +
) diff --git a/themes/Medium/components/Catalog.js b/themes/Medium/components/Catalog.js index d82bee28..9ae655a1 100644 --- a/themes/Medium/components/Catalog.js +++ b/themes/Medium/components/Catalog.js @@ -2,8 +2,6 @@ import React from 'react' import throttle from 'lodash.throttle' import { uuidToId } from 'notion-utils' import Progress from './Progress' -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import { faStream } from '@fortawesome/free-solid-svg-icons' // import { cs } from 'react-notion-x' /** @@ -55,7 +53,6 @@ const Catalog = ({ toc }) => { }, throttleMs)) return
-
目录
diff --git a/themes/Medium/components/JumpToTopButton.js b/themes/Medium/components/JumpToTopButton.js new file mode 100644 index 00000000..7126309c --- /dev/null +++ b/themes/Medium/components/JumpToTopButton.js @@ -0,0 +1,28 @@ +import { useGlobal } from '@/lib/global' +import { faArrowUp } from '@fortawesome/free-solid-svg-icons' +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import React from 'react' +import CONFIG_MEDIUM from '../config_medium' + +/** + * 跳转到网页顶部 + * 当屏幕下滑500像素后会出现该控件 + * @param targetRef 关联高度的目标html标签 + * @param showPercent 是否显示百分比 + * @returns {JSX.Element} + * @constructor + */ +const JumpToTopButton = ({ showPercent = false, percent }) => { + if (!CONFIG_MEDIUM.WIDGET_TO_TOP) { + return <> + } + const { locale } = useGlobal() + return (
window.scrollTo({ top: 0, behavior: 'smooth' })} > +
+ +
+ {showPercent && (
{percent}%
)} +
) +} + +export default JumpToTopButton diff --git a/themes/Medium/components/LeftMenuBar.js b/themes/Medium/components/LeftMenuBar.js new file mode 100644 index 00000000..680855c2 --- /dev/null +++ b/themes/Medium/components/LeftMenuBar.js @@ -0,0 +1,16 @@ +import Link from 'next/link' +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { faHome } from '@fortawesome/free-solid-svg-icons' +import React from 'react' + +export default function LeftMenuBar () { + return
+
+ +
+ +
+ +
+
+} diff --git a/themes/Medium/components/TopNavBar.js b/themes/Medium/components/TopNavBar.js index c73223c3..b08dc88b 100644 --- a/themes/Medium/components/TopNavBar.js +++ b/themes/Medium/components/TopNavBar.js @@ -1,7 +1,7 @@ import LogoBar from '@/themes/Medium/components/LogoBar' export default function TopNavBar ({ className }) { - return
+ return
diff --git a/themes/Medium/config_medium.js b/themes/Medium/config_medium.js index 4d13d756..e61b1982 100644 --- a/themes/Medium/config_medium.js +++ b/themes/Medium/config_medium.js @@ -11,6 +11,7 @@ const CONFIG_MEDIUM = { MENU_SEARCH: true, // 显示搜索 // Widget - WIDGET_REVOLVER_MAPS: process.env.NEXT_PUBLIC_WIDGET_REVOLVER_MAPS || 'false' // 地图插件 + WIDGET_REVOLVER_MAPS: process.env.NEXT_PUBLIC_WIDGET_REVOLVER_MAPS || 'false', // 地图插件 + WIDGET_TO_TOP: true // 跳回顶部 } export default CONFIG_MEDIUM