From a90eae972bab397dc5f050b4ef7bdbcb242ea9c4 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Thu, 27 Jan 2022 17:59:03 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feature:=E9=80=9A=E7=94=A8=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/CollapseLeft.js | 38 +++++++++++++++++++++++++ components/SideBarDrawer.js | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 components/CollapseLeft.js create mode 100644 components/SideBarDrawer.js diff --git a/components/CollapseLeft.js b/components/CollapseLeft.js new file mode 100644 index 00000000000..56d86525c74 --- /dev/null +++ b/components/CollapseLeft.js @@ -0,0 +1,38 @@ +import React, { useEffect, useRef } from 'react' + +const Collapse = props => { + const collapseRef = useRef(null) + const collapseSection = element => { + const sectionWidth = element.scrollWidth + requestAnimationFrame(function () { + element.style.width = sectionWidth + 'px' + requestAnimationFrame(function () { + element.style.width = 0 + 'px' + }) + }) + } + const expandSection = element => { + const sectionWidth = element.scrollWidth + element.style.width = sectionWidth + 'px' + const clearTime = setTimeout(() => { + element.style.width = 'auto' + }, 400) + clearTimeout(clearTime) + } + useEffect(() => { + const element = collapseRef.current + if (props.isOpen) { + expandSection(element) + } else { + collapseSection(element) + } + }, [props.isOpen]) + return ( +
+ {props.children} +
+ ) +} +Collapse.defaultProps = { isOpen: false } + +export default Collapse diff --git a/components/SideBarDrawer.js b/components/SideBarDrawer.js new file mode 100644 index 00000000000..e6db94a5550 --- /dev/null +++ b/components/SideBarDrawer.js @@ -0,0 +1,55 @@ +import { useRouter } from 'next/router' +import React from 'react' + +/** + * 侧边栏抽屉面板,可以从侧面拉出 + * @returns {JSX.Element} + * @constructor + */ +const SideBarDrawer = ({ children, isOpen, onOpen, onClose, className }) => { + const router = useRouter() + React.useEffect(() => { + // 页面渲染后删除hidden属性 + // const sideBarWrapperElement = document.getElementById('sidebar-wrapper') + // sideBarWrapperElement?.classList?.remove('hidden') + + const sideBarDrawerRouteListener = () => { + switchSideDrawerVisible(false) + } + router.events.on('routeChangeComplete', sideBarDrawerRouteListener) + return () => { + router.events.off('routeChangeComplete', sideBarDrawerRouteListener) + } + }, [router.events]) + + // 点击按钮更改侧边抽屉状态 + const switchSideDrawerVisible = (showStatus) => { + if (window) { + if (showStatus) { + onOpen() + } else { + onClose() + } + const sideBarDrawer = window.document.getElementById('sidebar-drawer') + const sideBarDrawerBackground = window.document.getElementById('sidebar-drawer-background') + + if (showStatus) { + sideBarDrawer.classList.replace('-ml-80', 'ml-0') + sideBarDrawerBackground.classList.replace('hidden', 'block') + } else { + sideBarDrawer.classList.replace('ml-0', '-ml-80') + sideBarDrawerBackground.classList.replace('block', 'hidden') + } + } + } + + return } - - {/*
- - - - {post.category} - - -
-
{post.tagItems.map(tag => ())}
-
-
*/} -
From 952051a80f56ee906fde7dd7d293e88f66720859 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Fri, 28 Jan 2022 09:32:51 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=96=87=E7=AB=A0=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=E6=8E=92=E7=8F=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/Medium/LayoutBase.js | 4 ++-- themes/Medium/LayoutSlug.js | 24 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/themes/Medium/LayoutBase.js b/themes/Medium/LayoutBase.js index 866d7e64fd5..3c62dc54111 100644 --- a/themes/Medium/LayoutBase.js +++ b/themes/Medium/LayoutBase.js @@ -11,7 +11,7 @@ import LogoBar from './components/LogoBar' * @constructor */ const LayoutBase = props => { - const { children, meta } = props + const { children, meta, showInfoCard = true } = props return (
@@ -19,7 +19,7 @@ const LayoutBase = props => {
- + {showInfoCard && }
{children} diff --git a/themes/Medium/LayoutSlug.js b/themes/Medium/LayoutSlug.js index cb621b12171..cd2a349d668 100644 --- a/themes/Medium/LayoutSlug.js +++ b/themes/Medium/LayoutSlug.js @@ -9,6 +9,10 @@ import 'prismjs/components/prism-typescript' import { Code, Collection, CollectionRow, Equation, NotionRenderer } from 'react-notion-x' import LayoutBase from './LayoutBase' import Comment from '@/components/Comment' +import Image from 'next/image' +import { useGlobal } from '@/lib/global' +import formatDate from '@/lib/formatDate' +import Link from 'next/link' const mapPageUrl = id => { return 'https://www.notion.so/' + id.replace(/-/g, '') @@ -27,9 +31,25 @@ export const LayoutSlug = (props) => { post.content = Object.keys(post.blockMap.block) post.toc = getPageTableOfContents(post, post.blockMap) } + const { locale } = useGlobal() + const date = formatDate(post?.date?.start_date || post.createdTime, locale.LOCALE) - return -

{post?.title}

+ return +

{post?.title}

+ +
+ {BLOG.AUTHOR} +
{BLOG.AUTHOR}
+
{date}
+
+ {/* Notion文章主体 */}
{post.blockMap && (