From 5c71941393f150b42534c1b10893a6edbd3b66cb Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Fri, 11 Nov 2022 14:21:49 +0800 Subject: [PATCH] =?UTF-8?q?tag=20=E5=88=86=E9=A1=B5=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getNotionData.js | 2 +- lib/utils.js | 14 ++++++++++ target/npmlist.json | 1 + themes/hexo/LayoutTag.js | 27 +++++++++++++++++--- themes/hexo/components/BlogPostListScroll.js | 16 ++---------- 5 files changed, 41 insertions(+), 19 deletions(-) create mode 100644 target/npmlist.json diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index c74552cb..e6ee99e7 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -279,7 +279,7 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { const customNav = getCustomNav({ allPages }) const categories = getAllCategories({ allPages, categoryOptions, sliceCount: BLOG.PREVIEW_CATEGORY_COUNT }) - const tags = getAllTags({ allPages, tagOptions, sliceCount: BLOG.PREVIEW_TAG_COUNT }) + const tags = getAllTags({ allPages, tagOptions }) const latestPosts = getLatestPosts({ allPages, from, latestPostCount: 5 }) return { diff --git a/lib/utils.js b/lib/utils.js index 1119bdf9..9df42aaf 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -105,3 +105,17 @@ export const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) * @returns {boolean} */ export const isBrowser = () => typeof window !== 'undefined' + +/** + * 获取从第1页到指定页码的文章 + * @param pageIndex 第几页 + * @param list 所有文章 + * @param pageSize 每页文章数量 + * @returns {*} + */ +export const getListByPage = function (list, pageIndex, pageSize) { + return list.slice( + 0, + pageIndex * pageSize + ) +} diff --git a/target/npmlist.json b/target/npmlist.json new file mode 100644 index 00000000..ae78e34a --- /dev/null +++ b/target/npmlist.json @@ -0,0 +1 @@ +{"version":"3.5.0","name":"notion-next"} \ No newline at end of file diff --git a/themes/hexo/LayoutTag.js b/themes/hexo/LayoutTag.js index 1e827be8..41ba2e24 100644 --- a/themes/hexo/LayoutTag.js +++ b/themes/hexo/LayoutTag.js @@ -3,18 +3,37 @@ import BlogPostListScroll from './components/BlogPostListScroll' import BlogPostListPage from './components/BlogPostListPage' import LayoutBase from './LayoutBase' import TagItemMini from '../next/components/TagItemMini' +import React from 'react' +import { getListByPage, getQueryVariable } from '@/lib/utils' export const LayoutTag = (props) => { - console.log(props) - const currentTag = props.tags.find((t) => { return t.name === props.tag }) + const [page, updatePage] = React.useState(1) + + const postsPerPage = BLOG.POSTS_PER_PAGE + + const postsToShow = getListByPage(props.posts, page, postsPerPage) + + React.useEffect(() => { + const qp = getQueryVariable('page') + console.log('分页', qp) + if (qp) { + updatePage(qp) + } + }) + return -
+ {currentTag && ( +
- {BLOG.POST_LIST_STYLE === 'page' ? : } + ) + } + {BLOG.POST_LIST_STYLE === 'page' ? : } } +git config --global user.email "tlyong1992@hotmail.com" + git config --global user.name "tangly1024" \ No newline at end of file diff --git a/themes/hexo/components/BlogPostListScroll.js b/themes/hexo/components/BlogPostListScroll.js index 4c56ff8e..89a89d0d 100644 --- a/themes/hexo/components/BlogPostListScroll.js +++ b/themes/hexo/components/BlogPostListScroll.js @@ -5,6 +5,7 @@ import { useGlobal } from '@/lib/global' import throttle from 'lodash.throttle' import React, { useCallback, useEffect, useRef, useState } from 'react' import CONFIG_HEXO from '../config_hexo' +import { getListByPage } from '@/lib/utils' /** * 博客列表滚动分页 @@ -16,7 +17,7 @@ import CONFIG_HEXO from '../config_hexo' const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = CONFIG_HEXO.POST_LIST_SUMMARY }) => { const postsPerPage = BLOG.POSTS_PER_PAGE const [page, updatePage] = useState(1) - const postsToShow = getPostByPage(page, posts, postsPerPage) + const postsToShow = getListByPage(posts, page, postsPerPage) let hasMore = false if (posts) { @@ -72,17 +73,4 @@ const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = CONFIG_HE } } -/** - * 获取从第1页到指定页码的文章 - * @param page 第几页 - * @param totalPosts 所有文章 - * @param postsPerPage 每页文章数量 - * @returns {*} - */ -const getPostByPage = function (page, totalPosts, postsPerPage) { - return totalPosts.slice( - 0, - postsPerPage * page - ) -} export default BlogPostListScroll