From ddd38a6745a626ab2bebd930468decb350e9c899 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Tue, 25 Jan 2022 17:44:49 +0800 Subject: [PATCH] =?UTF-8?q?previewLine=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.config.js | 1 + components/CommonHead.js | 2 +- lib/notion/getAllPosts.js | 3 --- pages/index.js | 15 +++++++++------ pages/page/[page].js | 17 ++++++++++------- themes/Fukasawa/config_fuka.js | 2 ++ themes/Hexo/components/BlogPostCard.js | 4 ++-- themes/Hexo/config_hexo.js | 2 +- themes/Hexo/index.js | 2 ++ themes/NEXT/index.js | 2 ++ 10 files changed, 30 insertions(+), 20 deletions(-) diff --git a/blog.config.js b/blog.config.js index df1cd74c..a6f06c4f 100644 --- a/blog.config.js +++ b/blog.config.js @@ -19,6 +19,7 @@ const BLOG = { PATH: '', // leave this empty unless you want to deploy in a folder POST_LIST_STYLE: 'page', // ['page','scroll] 文章列表样式:页码分页、单页滚动加载 + POST_LIST_PREVIEW: false, // 是否在列表加载文章预览, 会被各主题中的同名配置覆盖,例:/themes/NEXT/config_next.js POST_PREVIEW_LINES: 12, // 预览博客行数 POSTS_PER_PAGE: 6, // post counts per page POSTS_SORT_BY: 'notion', // 排序方式 'date'按时间,'notion'由notion控制 diff --git a/components/CommonHead.js b/components/CommonHead.js index 6488dbcb..203cb402 100644 --- a/components/CommonHead.js +++ b/components/CommonHead.js @@ -2,7 +2,7 @@ import BLOG from '@/blog.config' import Head from 'next/head' const CommonHead = ({ meta }) => { - let url = BLOG.PATH.length ? `${BLOG.LINK}/${BLOG.PATH}` : BLOG.LINK + let url = BLOG?.PATH?.length ? `${BLOG.LINK}/${BLOG.PATH}` : BLOG.LINK if (meta) { url = `${url}/${meta.slug}` } diff --git a/lib/notion/getAllPosts.js b/lib/notion/getAllPosts.js index d0c68d7c..7473a4d8 100644 --- a/lib/notion/getAllPosts.js +++ b/lib/notion/getAllPosts.js @@ -26,9 +26,6 @@ export async function getAllPosts ({ notionPageData, from, includePage = false } const data = [] const pageIds = getAllPageIds(collectionQuery) - if (!pageIds || pageIds.length === 0) { - console.warn('页面ID列表为空') - } for (let i = 0; i < pageIds.length; i++) { const id = pageIds[i] const properties = (await getPageProperties(id, pageBlock, schema)) || null diff --git a/pages/index.js b/pages/index.js index de821436..c499cd6f 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,7 +1,7 @@ import BLOG from '@/blog.config' import { getPostBlocks } from '@/lib/notion' import { getGlobalNotionData } from '@/lib/notion/getNotionData' -import { LayoutIndex } from '@/themes' +import { LayoutIndex, THEME_CONFIG } from '@/themes' const Index = (props) => { return @@ -26,11 +26,14 @@ export async function getStaticProps () { BLOG.POSTS_PER_PAGE * (page - 1), BLOG.POSTS_PER_PAGE * page ) - for (const i in postsToShow) { - const post = postsToShow[i] - const blockMap = await getPostBlocks(post.id, 'slug', BLOG.POST_PREVIEW_LINES) - if (blockMap) { - post.blockMap = blockMap + if (THEME_CONFIG.POST_LIST_PREVIEW || BLOG.POST_LIST_PREVIEW) { + console.log('加载预览') + for (const i in postsToShow) { + const post = postsToShow[i] + const blockMap = await getPostBlocks(post.id, 'slug', BLOG.POST_PREVIEW_LINES) + if (blockMap) { + post.blockMap = blockMap + } } } } diff --git a/pages/page/[page].js b/pages/page/[page].js index 43d16aec..d39e49a2 100644 --- a/pages/page/[page].js +++ b/pages/page/[page].js @@ -1,7 +1,7 @@ import BLOG from '@/blog.config' import { getPostBlocks } from '@/lib/notion' import { getGlobalNotionData } from '@/lib/notion/getNotionData' -import { LayoutPage } from '@/themes' +import { LayoutPage, THEME_CONFIG } from '@/themes' import Custom404 from '@/pages/404' const Page = (props) => { @@ -42,12 +42,15 @@ export async function getStaticProps ({ params: { page } }) { BLOG.POSTS_PER_PAGE * (page - 1), BLOG.POSTS_PER_PAGE * page ) - - for (const i in postsToShow) { - const post = postsToShow[i] - const blockMap = await getPostBlocks(post.id, 'slug', BLOG.POST_PREVIEW_LINES) - if (blockMap) { - post.blockMap = blockMap + // 加载预览 + if (THEME_CONFIG.POST_LIST_PREVIEW || BLOG.POST_LIST_PREVIEW) { + console.log('加载预览') + for (const i in postsToShow) { + const post = postsToShow[i] + const blockMap = await getPostBlocks(post.id, 'slug', BLOG.POST_PREVIEW_LINES) + if (blockMap) { + post.blockMap = blockMap + } } } diff --git a/themes/Fukasawa/config_fuka.js b/themes/Fukasawa/config_fuka.js index b34851e8..0d7250ca 100644 --- a/themes/Fukasawa/config_fuka.js +++ b/themes/Fukasawa/config_fuka.js @@ -1,6 +1,7 @@ const FUKA_CONFIG = { POST_LIST_COVER: true, // 文章列表显示图片封面 + POST_LIST_PREVIEW: false, // 显示文章预览 // 菜单 MENU_ABOUT: true, // 显示关于 @@ -8,5 +9,6 @@ const FUKA_CONFIG = { MENU_TAG: true, // 显示标签 MENU_ARCHIVE: true, // 显示归档 MENU_SEARCH: true // 显示搜索 + } export default FUKA_CONFIG diff --git a/themes/Hexo/components/BlogPostCard.js b/themes/Hexo/components/BlogPostCard.js index 93a2735b..758772df 100644 --- a/themes/Hexo/components/BlogPostCard.js +++ b/themes/Hexo/components/BlogPostCard.js @@ -33,7 +33,7 @@ const BlogPostCard = ({ post, showSummary }) => { {post.summary}

} - {showPreview && post?.blockMap &&
+ {showPreview &&
{
- {CONFIG_HEXO.POST_LIST_COVER && post?.page_cover && ( + {CONFIG_HEXO.POST_LIST_COVER && !showPreview && post?.page_cover && ( {/* eslint-disable-next-line @next/next/no-img-element */} diff --git a/themes/Hexo/config_hexo.js b/themes/Hexo/config_hexo.js index ef742382..9ebb5aa3 100644 --- a/themes/Hexo/config_hexo.js +++ b/themes/Hexo/config_hexo.js @@ -12,7 +12,7 @@ const CONFIG_HEXO = { POST_LIST_COVER: true, // 文章封面 POST_LIST_SUMMARY: true, // 文章摘要 - POST_LIST_PREVIEW: false, + POST_LIST_PREVIEW: false, // 读取文章预览 NAV_TYPE: 'autoCollapse', // ['fixed','autoCollapse','normal'] 分别是固定屏幕顶部、屏幕顶部自动折叠,不固定 WIDGET_TO_TOP: true, diff --git a/themes/Hexo/index.js b/themes/Hexo/index.js index aabed077..15af8476 100644 --- a/themes/Hexo/index.js +++ b/themes/Hexo/index.js @@ -1,3 +1,4 @@ +import CONFIG_HEXO from './config_hexo' export { LayoutIndex } from './LayoutIndex' export { LayoutSearch } from './LayoutSearch' export { LayoutArchive } from './LayoutArchive' @@ -8,3 +9,4 @@ export { LayoutCategoryIndex } from './LayoutCategoryIndex' export { LayoutPage } from './LayoutPage' export { LayoutTag } from './LayoutTag' export { LayoutTagIndex } from './LayoutTagIndex' +export { CONFIG_HEXO as THEME_CONFIG } diff --git a/themes/NEXT/index.js b/themes/NEXT/index.js index aabed077..5e6ccc75 100644 --- a/themes/NEXT/index.js +++ b/themes/NEXT/index.js @@ -1,3 +1,4 @@ +import CONFIG_NEXT from './config_next' export { LayoutIndex } from './LayoutIndex' export { LayoutSearch } from './LayoutSearch' export { LayoutArchive } from './LayoutArchive' @@ -8,3 +9,4 @@ export { LayoutCategoryIndex } from './LayoutCategoryIndex' export { LayoutPage } from './LayoutPage' export { LayoutTag } from './LayoutTag' export { LayoutTagIndex } from './LayoutTagIndex' +export { CONFIG_NEXT as THEME_CONFIG }