diff --git a/pages/page/[page].js b/pages/page/[page].js index 569eb389..f78b5a7d 100644 --- a/pages/page/[page].js +++ b/pages/page/[page].js @@ -36,6 +36,7 @@ export async function getStaticProps ({ params: { page } }) { description: BLOG.description, type: 'website' } + // 处理分页 const postsToShow = allPosts.slice( BLOG.postsPerPage * (page - 1), diff --git a/themes/Fukasawa/LayoutPage.js b/themes/Fukasawa/LayoutPage.js index 0cf417fe..a3c39788 100644 --- a/themes/Fukasawa/LayoutPage.js +++ b/themes/Fukasawa/LayoutPage.js @@ -4,7 +4,7 @@ import LayoutBase from './LayoutBase' export const LayoutPage = (props) => { return - + } diff --git a/themes/Fukasawa/LayoutSlug.js b/themes/Fukasawa/LayoutSlug.js index d582caac..31b2fd49 100644 --- a/themes/Fukasawa/LayoutSlug.js +++ b/themes/Fukasawa/LayoutSlug.js @@ -1,13 +1,25 @@ +import BLOG from '@/blog.config' import 'prismjs' import 'prismjs/components/prism-bash' import 'prismjs/components/prism-javascript' import 'prismjs/components/prism-markup' import 'prismjs/components/prism-python' import 'prismjs/components/prism-typescript' +import ArticleDetail from './components/ArticleDetail' import LayoutBase from './LayoutBase' export const LayoutSlug = (props) => { - return - 首页 - + const { post } = props + const meta = { + title: `${post.title} | ${BLOG.title}`, + description: post.summary, + type: 'article', + tags: post.tags + } + + return ( + + + + ) } diff --git a/themes/Fukasawa/components/ArticleArount.js b/themes/Fukasawa/components/ArticleArount.js new file mode 100644 index 00000000..ccf37621 --- /dev/null +++ b/themes/Fukasawa/components/ArticleArount.js @@ -0,0 +1,26 @@ +import Link from 'next/link' +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { faAngleDoubleLeft, faAngleDoubleRight } from '@fortawesome/free-solid-svg-icons' + +/** + * 上一篇,下一篇文章 + * @param {prev,next} param0 + * @returns + */ +export default function ArticleAround ({ prev, next }) { + if (!prev || !next) { + return <> + } + return
+ + + {prev.title} + + + + {next.title} + + + +
+} diff --git a/themes/Fukasawa/components/ArticleDetail.js b/themes/Fukasawa/components/ArticleDetail.js new file mode 100644 index 00000000..2ee39780 --- /dev/null +++ b/themes/Fukasawa/components/ArticleDetail.js @@ -0,0 +1,155 @@ +import Comment from '@/components/Comment' +import formatDate from '@/lib/formatDate' +import { useGlobal } from '@/lib/global' +import { faEye, faFolderOpen } from '@fortawesome/free-solid-svg-icons' +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import mediumZoom from 'medium-zoom' +import Link from 'next/link' +import 'prismjs' +import 'prismjs/components/prism-bash' +import 'prismjs/components/prism-javascript' +import 'prismjs/components/prism-markup' +import 'prismjs/components/prism-python' +import 'prismjs/components/prism-typescript' +import { useEffect, useRef } from 'react' +import { Code, Collection, CollectionRow, Equation, NotionRenderer } from 'react-notion-x' +import ArticleAround from './ArticleArount' + +/** + * + * @param {*} param0 + * @returns + */ +export default function ArticleDetail ({ post, recommendPosts, prev, next }) { + const { locale } = useGlobal() + const date = formatDate(post?.date?.start_date || post.createdTime, locale.LOCALE) + + const zoom = typeof window !== 'undefined' && mediumZoom({ + container: '.notion-viewport', + background: 'rgba(0, 0, 0, 0.2)', + margin: getMediumZoomMargin() + }) + const zoomRef = useRef(zoom ? zoom.clone() : null) + + useEffect(() => { + // 将所有container下的所有图片添加medium-zoom + const container = document.getElementById('container') + const imgList = container.getElementsByTagName('img') + if (imgList && zoomRef.current) { + for (let i = 0; i < imgList.length; i++) { + (zoomRef.current).attach(imgList[i]) + } + } + }) + + return (
+
+ +
+ {post.type && !post.type.includes('Page') && post?.page_cover && ( +
+ {post.title} +
+ )} + + {/* 文章Title */} +
+ {post.title} +
+ +
+
+ + + + {post.category} + + + | + + {post.type[0] !== 'Page' && (<> + + + {date} + + + | + )} + +
+ +   + + | +
+
+ +
+ +
+ + {/* Notion文章主体 */} +
+ {post.blockMap && ( + + )} +
+ +
+ {/* 文章内嵌广告 */} + +
+ +
+ + + + {/* 评论互动 */} +
+
发表评论
+ +
+
) +} + +const mapPageUrl = id => { + return 'https://www.notion.so/' + id.replace(/-/g, '') +} + +function getMediumZoomMargin () { + const width = window.innerWidth + + if (width < 500) { + return 8 + } else if (width < 800) { + return 20 + } else if (width < 1280) { + return 30 + } else if (width < 1600) { + return 40 + } else if (width < 1920) { + return 48 + } else { + return 72 + } +} diff --git a/themes/Fukasawa/components/BlogListPage.js b/themes/Fukasawa/components/BlogListPage.js index fa7a23d3..776092c7 100644 --- a/themes/Fukasawa/components/BlogListPage.js +++ b/themes/Fukasawa/components/BlogListPage.js @@ -1,7 +1,7 @@ -import BlogCard from './BlogCard' -import PaginationNumber from './PaginationNumber' import BLOG from '@/blog.config' +import BlogCard from './BlogCard' import BlogPostListEmpty from './BlogListEmpty' +import PaginationSimple from './PaginationSimple' /** * 文章列表分页表格 @@ -13,21 +13,21 @@ import BlogPostListEmpty from './BlogListEmpty' */ const BlogListPage = ({ page = 1, posts = [], postCount }) => { const totalPage = Math.ceil(postCount / BLOG.postsPerPage) - + const showNext = page < totalPage if (!posts || posts.length === 0) { return } else { return (
{/* 文章列表 */} -
+
{posts.map(post => ( -
+
))}
- +
) } diff --git a/themes/Fukasawa/components/Card.js b/themes/Fukasawa/components/Card.js index d24c046e..890aadf9 100644 --- a/themes/Fukasawa/components/Card.js +++ b/themes/Fukasawa/components/Card.js @@ -1,7 +1,7 @@ const Card = ({ children, headerSlot, className }) => { return
<>{headerSlot} -
+
{children}
diff --git a/themes/Fukasawa/components/GroupCategory.js b/themes/Fukasawa/components/GroupCategory.js index 42bc28cb..8e17fd5e 100644 --- a/themes/Fukasawa/components/GroupCategory.js +++ b/themes/Fukasawa/components/GroupCategory.js @@ -4,6 +4,10 @@ import Link from 'next/link' import React from 'react' function GroupCategory ({ currentCategory, categories }) { + if (!categories) { + return <> + } + return <>
{Object.keys(categories).map(category => { diff --git a/themes/Fukasawa/components/PaginationNumber.js b/themes/Fukasawa/components/PaginationNumber.js deleted file mode 100644 index 36de638b..00000000 --- a/themes/Fukasawa/components/PaginationNumber.js +++ /dev/null @@ -1,94 +0,0 @@ -import BLOG from '@/blog.config' -import Link from 'next/link' -import { useRouter } from 'next/router' -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import { faAngleLeft, faAngleRight } from '@fortawesome/free-solid-svg-icons' - -/** - * 数字翻页插件 - * @param page 当前页码 - * @param showNext 是否有下一页 - * @returns {JSX.Element} - * @constructor - */ -const PaginationNumber = ({ page, totalPage }) => { - const router = useRouter() - const currentPage = +page - const showNext = page !== totalPage - const pages = generatePages(page, currentPage, totalPage) - - return ( -
- - {/* 上一页 */} - - - - - {pages} - - {/* 下一页 */} - - - -
- ) -} - -function getPageElement (page, currentPage) { - return - - {page} - - -} -function generatePages (page, currentPage, totalPage) { - const pages = [] - const groupCount = 7 // 最多显示页签数 - if (totalPage <= groupCount) { - for (let i = 1; i <= totalPage; i++) { - pages.push(getPageElement(i, page)) - } - } else { - pages.push(getPageElement(1, page)) - const dynamicGroupCount = groupCount - 2 - let startPage = currentPage - 2 - if (startPage <= 1) { - startPage = 2 - } - if (startPage + dynamicGroupCount > totalPage) { - startPage = totalPage - dynamicGroupCount - } - if (startPage > 2) { - pages.push(
...
) - } - - for (let i = 0; i < dynamicGroupCount; i++) { - if (startPage + i < totalPage) { - pages.push(getPageElement(startPage + i, page)) - } - } - - if (startPage + dynamicGroupCount < totalPage) { - pages.push(
...
) - } - - pages.push(getPageElement(totalPage, page)) - } - return pages -} -export default PaginationNumber diff --git a/themes/Fukasawa/components/PaginationSimple.js b/themes/Fukasawa/components/PaginationSimple.js new file mode 100644 index 00000000..8d45021b --- /dev/null +++ b/themes/Fukasawa/components/PaginationSimple.js @@ -0,0 +1,42 @@ +import BLOG from '@/blog.config' +import Link from 'next/link' +import { useRouter } from 'next/router' +import { useGlobal } from '@/lib/global' + +/** + * 简易翻页插件 + * @param page 当前页码 + * @param showNext 是否有下一页 + * @returns {JSX.Element} + * @constructor + */ +const PaginationSimple = ({ page, showNext }) => { + const { locale } = useGlobal() + const router = useRouter() + const currentPage = +page + return ( +
+ + + + + + +
+ ) +} + +export default PaginationSimple diff --git a/themes/index.js b/themes/index.js index de2f713d..2a223d56 100644 --- a/themes/index.js +++ b/themes/index.js @@ -1,5 +1,5 @@ /** - * 直接将./NEXT 替换成对应的主题路径 + * 修改 from 后面的路径,实现主题切换 */ // export * from './NEXT' // 切换主题