From ebdaf4273fdbce95b105867a95c1eea4e5778644 Mon Sep 17 00:00:00 2001 From: txs Date: Mon, 4 Apr 2022 08:13:18 +0800 Subject: [PATCH] Add facebook Open Graph Url and image. Fix PATH env conflict with Vercel environment --- blog.config.js | 63 ++++--- components/CommonHead.js | 74 ++++---- lib/rss.js | 37 ++-- pages/[slug].js | 13 +- pages/archive/index.js | 5 +- pages/article/[slug].js | 18 +- pages/category/[category].js | 17 +- pages/category/index.js | 12 +- pages/index.js | 17 +- pages/page/[page].js | 15 +- pages/search/[keyword].js | 29 ++- pages/search/index.js | 26 ++- pages/tag/[tag].js | 25 ++- pages/tag/index.js | 3 +- themes/example/LayoutArchive.js | 5 +- themes/example/LayoutIndex.js | 66 ++++--- themes/example/LayoutPage.js | 65 ++++--- themes/fukasawa/components/BlogCard.js | 59 ++++--- themes/fukasawa/components/BlogPostArchive.js | 42 +++-- .../fukasawa/components/PaginationSimple.js | 36 ++-- themes/hexo/components/ArticleRecommend.js | 42 +++-- themes/hexo/components/BlogPostArchive.js | 42 +++-- themes/hexo/components/BlogPostCard.js | 137 +++++++++------ themes/hexo/components/LatestPostsGroup.js | 4 +- themes/hexo/components/PaginationNumber.js | 59 +++++-- themes/medium/LayoutArchive.js | 5 +- themes/medium/components/BlogPostCard.js | 80 +++++---- themes/medium/components/PaginationSimple.js | 36 ++-- themes/next/components/BlogPostArchive.js | 42 +++-- themes/next/components/BlogPostCard.js | 166 +++++++++++------- themes/next/components/LatestPostsGroup.js | 37 ++-- themes/next/components/PaginationNumber.js | 59 +++++-- themes/next/components/PaginationSimple.js | 34 +++- 33 files changed, 901 insertions(+), 469 deletions(-) diff --git a/blog.config.js b/blog.config.js index 027be3f3..aec8fd3c 100644 --- a/blog.config.js +++ b/blog.config.js @@ -5,7 +5,8 @@ const BLOG = { LINK: 'https://tangly1024.com', // 网站地址 AVATAR: '/avatar.png', // 个人头像 默认取public目录下的avatar.png KEYWORDS: 'Notion, 博客', // 网站关键词 英文逗号隔开 - NOTION_PAGE_ID: process.env.NOTION_PAGE_ID || '02ab3b8678004aa69e9e415905ef32a5', // Important page_id!!!Duplicate Template from https://www.notion.so/tanghh/02ab3b8678004aa69e9e415905ef32a5 + NOTION_PAGE_ID: + process.env.NOTION_PAGE_ID || '02ab3b8678004aa69e9e415905ef32a5', // Important page_id!!!Duplicate Template from https://www.notion.so/tanghh/02ab3b8678004aa69e9e415905ef32a5 NOTION_ACCESS_TOKEN: process.env.NOTION_ACCESS_TOKEN || '', // Useful if you prefer not to make your database public DEBUG: process.env.NEXT_PUBLIC_DEBUG || false, // 是否显示调试按钮 @@ -17,10 +18,11 @@ const BLOG = { BEI_AN: process.env.NEXT_PUBLIC_BEI_AN || '', // 备案号 闽ICP备XXXXXXX APPEARANCE: 'light', // ['light', 'dark', 'auto'], // light 日间模式 , dark夜间模式, auto根据时间和主题自动夜间模式 FONT: 'font-serif tracking-wider subpixel-antialiased', // 文章字体 ['font-sans', 'font-serif', 'font-mono'] @see https://www.tailwindcss.cn/docs/font-family - FONT_AWESOME_PATH: 'https://cdn.bootcdn.net/ajax/libs/font-awesome/5.15.4/css/all.min.css', // 图标库CDN ,国内推荐BootCDN,国外推荐 CloudFlare https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css + FONT_AWESOME_PATH: + 'https://cdn.bootcdn.net/ajax/libs/font-awesome/5.15.4/css/all.min.css', // 图标库CDN ,国内推荐BootCDN,国外推荐 CloudFlare https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css BACKGROUND_LIGHT: '#eeeeee', // use hex value, don't forget '#' e.g #fffefc BACKGROUND_DARK: '#000000', // use hex value, don't forget '#' - PATH: '', // leave this empty unless you want to deploy in a folder + SUB_PATH: '', // leave this empty unless you want to deploy in a folder POST_LIST_STYLE: 'page', // ['page','scroll] 文章列表样式:页码分页、单页滚动加载 POST_LIST_PREVIEW: process.env.NEXT_PUBLIC_POST_PREVIEW || 'false', // 是否在列表加载文章预览 @@ -41,7 +43,8 @@ const BLOG = { // 悬浮挂件 WIDGET_PET: process.env.NEXT_PUBLIC_WIDGET_PET || true, // 是否显示宠物挂件 - WIDGET_PET_LINK: 'https://cdn.jsdelivr.net/npm/live2d-widget-model-wanko@1.0.5/assets/wanko.model.json', // 挂件模型地址 @see https://github.com/xiazeyu/live2d-widget-models + WIDGET_PET_LINK: + 'https://cdn.jsdelivr.net/npm/live2d-widget-model-wanko@1.0.5/assets/wanko.model.json', // 挂件模型地址 @see https://github.com/xiazeyu/live2d-widget-models WIDGET_PET_SWITCH_THEME: true, // 点击宠物挂件切换博客主题 // 评论互动 可同时开启多个支持 GISCUS CUSDIS UTTERRANCES GITALK @@ -49,27 +52,40 @@ const BLOG = { // giscus @see https://giscus.app/ COMMENT_GISCUS_REPO: process.env.NEXT_PUBLIC_COMMENT_GISCUS_REPO || '', // 你的Github仓库名 e.g 'tangly1024/NotionNext' COMMENT_GISCUS_REPO_ID: process.env.NEXT_PUBLIC_COMMENT_GISCUS_REPO_ID || '', // 你的Github Repo ID e.g ( 設定完 giscus 即可看到 ) - COMMENT_GISCUS_CATEGORY_ID: process.env.NEXT_PUBLIC_COMMENT_GISCUS_CATEGORY_ID || '', // 你的Github Discussions 內的 Category ID ( 設定完 giscus 即可看到 ) - COMMENT_GISCUS_MAPPING: process.env.NEXT_PUBLIC_COMMENT_GISCUS_MAPPING || 'pathname', // 你的Github Discussions 使用哪種方式來標定文章, 預設 'pathname' - COMMENT_GISCUS_REACTIONS_ENABLED: process.env.NEXT_PUBLIC_COMMENT_GISCUS_REACTIONS_ENABLED || '1', // 你的 Giscus 是否開啟文章表情符號 '1' 開啟 "0" 關閉 預設開啟 - COMMENT_GISCUS_EMIT_METADATA: process.env.NEXT_PUBLIC_COMMENT_GISCUS_EMIT_METADATA || '0', // 你的 Giscus 是否提取 Metadata '1' 開啟 '0' 關閉 預設關閉 - COMMENT_GISCUS_INPUT_POSITION: process.env.NEXT_PUBLIC_COMMENT_GISCUS_INPUT_POSITION || 'bottom', // 你的 Giscus 發表留言位置 'bottom' 尾部 'top' 頂部, 預設 'bottom' + COMMENT_GISCUS_CATEGORY_ID: + process.env.NEXT_PUBLIC_COMMENT_GISCUS_CATEGORY_ID || '', // 你的Github Discussions 內的 Category ID ( 設定完 giscus 即可看到 ) + COMMENT_GISCUS_MAPPING: + process.env.NEXT_PUBLIC_COMMENT_GISCUS_MAPPING || 'pathname', // 你的Github Discussions 使用哪種方式來標定文章, 預設 'pathname' + COMMENT_GISCUS_REACTIONS_ENABLED: + process.env.NEXT_PUBLIC_COMMENT_GISCUS_REACTIONS_ENABLED || '1', // 你的 Giscus 是否開啟文章表情符號 '1' 開啟 "0" 關閉 預設開啟 + COMMENT_GISCUS_EMIT_METADATA: + process.env.NEXT_PUBLIC_COMMENT_GISCUS_EMIT_METADATA || '0', // 你的 Giscus 是否提取 Metadata '1' 開啟 '0' 關閉 預設關閉 + COMMENT_GISCUS_INPUT_POSITION: + process.env.NEXT_PUBLIC_COMMENT_GISCUS_INPUT_POSITION || 'bottom', // 你的 Giscus 發表留言位置 'bottom' 尾部 'top' 頂部, 預設 'bottom' COMMENT_GISCUS_LANG: process.env.NEXT_PUBLIC_COMMENT_GISCUS_LANG || 'zh-CN', // 你的 Giscus 語言 e.g 'en', 'zh-TW', 'zh-CN', 預設 'en' - COMMENT_GISCUS_LOADING: process.env.NEXT_PUBLIC_COMMENT_GISCUS_LOADING || 'lazy', // 你的 Giscus 載入是否漸進式載入, 預設 'lazy' - COMMENT_GISCUS_CROSSORIGIN: process.env.NEXT_PUBLIC_COMMENT_GISCUS_CROSSORIGIN || 'anonymous', // 你的 Giscus 可以跨網域, 預設 'anonymous' + COMMENT_GISCUS_LOADING: + process.env.NEXT_PUBLIC_COMMENT_GISCUS_LOADING || 'lazy', // 你的 Giscus 載入是否漸進式載入, 預設 'lazy' + COMMENT_GISCUS_CROSSORIGIN: + process.env.NEXT_PUBLIC_COMMENT_GISCUS_CROSSORIGIN || 'anonymous', // 你的 Giscus 可以跨網域, 預設 'anonymous' COMMENT_CUSDIS_APP_ID: process.env.NEXT_PUBLIC_COMMENT_CUSDIS_APP_ID || '', // data-app-id 36位 see https://cusdis.com/ - COMMENT_CUSDIS_HOST: process.env.NEXT_PUBLIC_COMMENT_CUSDIS_HOST || 'https://cusdis.com', // data-host, change this if you're using self-hosted version - COMMENT_CUSDIS_SCRIPT_SRC: process.env.NEXT_PUBLIC_COMMENT_CUSDIS_SCRIPT_SRC || 'https://cusdis.com/js/cusdis.es.js', // change this if you're using self-hosted version + COMMENT_CUSDIS_HOST: + process.env.NEXT_PUBLIC_COMMENT_CUSDIS_HOST || 'https://cusdis.com', // data-host, change this if you're using self-hosted version + COMMENT_CUSDIS_SCRIPT_SRC: + process.env.NEXT_PUBLIC_COMMENT_CUSDIS_SCRIPT_SRC || + 'https://cusdis.com/js/cusdis.es.js', // change this if you're using self-hosted version - COMMENT_UTTERRANCES_REPO: process.env.NEXT_PUBLIC_COMMENT_UTTERRANCES_REPO || '', // 你的代码仓库名, 例如我是 'tangly1024/NotionNext'; 更多文档参考 https://utteranc.es/ + COMMENT_UTTERRANCES_REPO: + process.env.NEXT_PUBLIC_COMMENT_UTTERRANCES_REPO || '', // 你的代码仓库名, 例如我是 'tangly1024/NotionNext'; 更多文档参考 https://utteranc.es/ // gitalk评论插件 更多参考 https://gitalk.github.io/ COMMENT_GITALK_REPO: process.env.NEXT_PUBLIC_COMMENT_GITALK_REPO || '', // 你的Github仓库名,例如 'NotionNext' COMMENT_GITALK_OWNER: process.env.NEXT_PUBLIC_COMMENT_GITALK_OWNER || '', // 你的用户名 e.g tangly1024 COMMENT_GITALK_ADMIN: process.env.NEXT_PUBLIC_COMMENT_GITALK_ADMIN || '', // 管理员用户名、一般是自己 e.g 'tangly1024' - COMMENT_GITALK_CLIENT_ID: process.env.NEXT_PUBLIC_COMMENT_GITALK_CLIENT_ID || '', // e.g 20位ID , 在gitalk后台获取 - COMMENT_GITALK_CLIENT_SECRET: process.env.NEXT_PUBLIC_COMMENT_GITALK_CLIENT_SECRET || '', // e.g 40位ID, 在gitalk后台获取 + COMMENT_GITALK_CLIENT_ID: + process.env.NEXT_PUBLIC_COMMENT_GITALK_CLIENT_ID || '', // e.g 20位ID , 在gitalk后台获取 + COMMENT_GITALK_CLIENT_SECRET: + process.env.NEXT_PUBLIC_COMMENT_GITALK_CLIENT_SECRET || '', // e.g 40位ID, 在gitalk后台获取 COMMENT_GITALK_DISTRACTION_FREE_MODE: false, // 类似facebook的无干扰模式 COMMENT_GITTER_ROOM: process.env.NEXT_PUBLIC_COMMENT_GITTER_ROOM || '', // gitter聊天室 see https://gitter.im/ 不需要则留空 @@ -82,17 +98,22 @@ const BLOG = { ANALYTICS_CNZZ_ID: process.env.NEXT_PUBLIC_ANALYTICS_CNZZ_ID || '', // 只需要填写站长统计的id, [cnzz_id] -> https://s9.cnzz.com/z_stat.php?id=[cnzz_id]&web_id=[cnzz_id] ANALYTICS_GOOGLE_ID: process.env.NEXT_PUBLIC_ANALYTICS_GOOGLE_ID || '', // 谷歌Analytics的id e.g: G-XXXXXXXXXX - ANALYTICS_ACKEE_TRACKER: process.env.NEXT_PUBLIC_ANALYTICS_ACKEE_TRACKER || '', // e.g 'https://ackee.tangly1024.net/tracker.js' - ANALYTICS_ACKEE_DATA_SERVER: process.env.NEXT_PUBLIC_ANALYTICS_ACKEE_DATA_SERVER || '', // e.g https://ackee.tangly1024.net , don't end with a slash - ANALYTICS_ACKEE_DOMAIN_ID: process.env.NEXT_PUBLIC_ANALYTICS_ACKEE_DOMAIN_ID || '', // e.g '0e2257a8-54d4-4847-91a1-0311ea48cc7b' + ANALYTICS_ACKEE_TRACKER: + process.env.NEXT_PUBLIC_ANALYTICS_ACKEE_TRACKER || '', // e.g 'https://ackee.tangly1024.net/tracker.js' + ANALYTICS_ACKEE_DATA_SERVER: + process.env.NEXT_PUBLIC_ANALYTICS_ACKEE_DATA_SERVER || '', // e.g https://ackee.tangly1024.net , don't end with a slash + ANALYTICS_ACKEE_DOMAIN_ID: + process.env.NEXT_PUBLIC_ANALYTICS_ACKEE_DOMAIN_ID || '', // e.g '0e2257a8-54d4-4847-91a1-0311ea48cc7b' - SEO_GOOGLE_SITE_VERIFICATION: process.env.NEXT_PUBLIC_SEO_GOOGLE_SITE_VERIFICATION || '', // Remove the value or replace it with your own google site verification code + SEO_GOOGLE_SITE_VERIFICATION: + process.env.NEXT_PUBLIC_SEO_GOOGLE_SITE_VERIFICATION || '', // Remove the value or replace it with your own google site verification code ADSENSE_GOOGLE_ID: process.env.NEXT_PUBLIC_ADSENSE_GOOGLE_ID || '', // 谷歌广告ID e.g ca-pub-xxxxxxxxxxxxxxxx // 无关紧要的配置 TITLE: process.env.NEXT_PUBLIC_TITLE || 'NotionNext BLOG', // 站点标题 ,被notion中的页面标题覆盖 - DESCRIPTION: process.env.NEXT_PUBLIC_DESCRIPTION || '这是一个由NotionNext生成的站点', // 站点描述,被notion中的页面描述覆盖 + DESCRIPTION: + process.env.NEXT_PUBLIC_DESCRIPTION || '这是一个由NotionNext生成的站点', // 站点描述,被notion中的页面描述覆盖 isProd: process.env.VERCEL_ENV === 'production', // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables) isProd: process.env.VERCEL_ENV === 'production' // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables) VERSION: '2.9.1' // 版本号 diff --git a/components/CommonHead.js b/components/CommonHead.js index c8bc8a8e..aad15497 100644 --- a/components/CommonHead.js +++ b/components/CommonHead.js @@ -2,47 +2,59 @@ import BLOG from '@/blog.config' import Head from 'next/head' const CommonHead = ({ meta, children }) => { - let url = BLOG?.PATH?.length ? `${BLOG.LINK}/${BLOG.PATH}` : BLOG.LINK + let url = BLOG?.PATH?.length ? `${BLOG.LINK}/${BLOG.SUB_PATH}` : BLOG.LINK + let image if (meta) { url = `${url}/${meta.slug}` + image = meta.image || '' } const title = meta?.title || BLOG.TITLE const description = meta?.description || BLOG.DESCRIPTION const type = meta?.type || 'website' const keywords = meta?.tags || BLOG.KEYWORDS - return - {title} - - - - - {BLOG.SEO_GOOGLE_SITE_VERIFICATION && ( - - )} - - - - - - - - - - - {JSON.parse(BLOG.ANALYTICS_BUSUANZI_ENABLE) && } - {meta?.type === 'article' && ( - <> + return ( + + {title} + + + + + {BLOG.SEO_GOOGLE_SITE_VERIFICATION && ( - - - )} - {children} - + )} + + + + + + + + + + + + {JSON.parse(BLOG.ANALYTICS_BUSUANZI_ENABLE) && ( + + )} + {meta?.type === 'article' && ( + <> + + + + )} + {children} + + ) } export default CommonHead diff --git a/lib/rss.js b/lib/rss.js index 045ca082..a2afe0d6 100644 --- a/lib/rss.js +++ b/lib/rss.js @@ -1,7 +1,13 @@ import { Feed } from 'feed' import BLOG from '@/blog.config' import ReactDOMServer from 'react-dom/server' -import { NotionRenderer, Equation, Code, Collection, CollectionRow } from 'react-notion-x' +import { + NotionRenderer, + Equation, + Code, + Collection, + CollectionRow +} from 'react-notion-x' import { getPostBlocks } from './notion' const mapPageUrl = id => 'https://www.notion.so/' + id.replace(/-/g, '') @@ -13,28 +19,31 @@ const createFeedContent = async post => { } const blockMap = await getPostBlocks(post.id, 'rss-content') if (blockMap) { - const content = ReactDOMServer.renderToString() - const regexExp = /
.*?<\/svg>
.*?<\/div><\/div>
.*?<\/div><\/div><\/div><\/div>/g + const content = ReactDOMServer.renderToString( + + ) + const regexExp = + /
.*?<\/svg>
.*?<\/div><\/div>
.*?<\/div><\/div><\/div><\/div>/g return content.replace(regexExp, '') } return post.summary } -export async function generateRss (posts) { +export async function generateRss(posts) { const year = new Date().getFullYear() const feed = new Feed({ title: BLOG.TITLE, description: BLOG.DESCRIPTION, - link: `${BLOG.LINK}/${BLOG.PATH}`, + link: `${BLOG.LINK}/${BLOG.SUB_PATH}`, language: BLOG.LANG, favicon: `${BLOG.LINK}/favicon.png`, copyright: `All rights reserved ${year}, ${BLOG.AUTHOR}`, diff --git a/pages/[slug].js b/pages/[slug].js index 8b9f9149..99f49fed 100644 --- a/pages/[slug].js +++ b/pages/[slug].js @@ -15,7 +15,7 @@ const Slug = props => { const ThemeComponents = ThemeMap[theme] const { post } = props if (!post) { - return + return } // 文章锁🔐 @@ -43,15 +43,17 @@ const Slug = props => { title: `${post.title} | ${siteInfo.title}`, description: post.summary, type: 'article', + image: post.page_cover, + slug: post.slug, tags: post.tags } props = { ...props, meta, lock, setLock, validPassword } - return + return } -export async function getStaticPaths () { +export async function getStaticPaths() { if (!BLOG.isProd) { return { paths: [], @@ -61,7 +63,8 @@ export async function getStaticPaths () { const from = 'slug-paths' const { allPosts } = await getGlobalNotionData({ from, pageType: ['Page'] }) - const filterPosts = allPosts?.filter(e => e?.slug?.indexOf('http') !== 0) || [] + const filterPosts = + allPosts?.filter(e => e?.slug?.indexOf('http') !== 0) || [] return { paths: filterPosts.map(row => ({ params: { slug: row.slug } })), @@ -69,7 +72,7 @@ export async function getStaticPaths () { } } -export async function getStaticProps ({ params: { slug } }) { +export async function getStaticProps({ params: { slug } }) { const from = `slug-props-${slug}` const props = await getGlobalNotionData({ from, pageType: ['Page'] }) const { allPosts } = props diff --git a/pages/archive/index.js b/pages/archive/index.js index 88f3d619..5241697d 100644 --- a/pages/archive/index.js +++ b/pages/archive/index.js @@ -10,13 +10,14 @@ const ArchiveIndex = props => { const meta = { title: `${locale.NAV.ARCHIVE} | ${siteInfo.title}`, description: siteInfo.description, + slug: 'archive', type: 'website' } - return + return } -export async function getStaticProps () { +export async function getStaticProps() { const props = await getGlobalNotionData({ from: 'archive-index' }) props.posts = props.allPosts return { diff --git a/pages/article/[slug].js b/pages/article/[slug].js index 9c0f8d97..9abf4b83 100644 --- a/pages/article/[slug].js +++ b/pages/article/[slug].js @@ -61,13 +61,17 @@ const Slug = props => { title: `${props.post.title} | ${siteInfo.title}`, description: props.post.summary, type: 'article', + slug: 'article/' + props.post.slug, + image: props.post.page_cover, tags: props.post.tags } - return + return ( + + ) } -export async function getStaticPaths () { +export async function getStaticPaths() { if (!BLOG.isProd) { return { paths: [], @@ -83,7 +87,7 @@ export async function getStaticPaths () { } } -export async function getStaticProps ({ params: { slug } }) { +export async function getStaticProps({ params: { slug } }) { const from = `slug-props-${slug}` const props = await getGlobalNotionData({ from, pageType: ['Post'] }) const allPosts = props.allPosts @@ -96,7 +100,11 @@ export async function getStaticProps ({ params: { slug } }) { const index = allPosts.indexOf(props.post) props.prev = allPosts.slice(index - 1, index)[0] ?? allPosts.slice(-1)[0] props.next = allPosts.slice(index + 1, index + 2)[0] ?? allPosts[0] - props.recommendPosts = getRecommendPost(props.post, allPosts, BLOG.POST_RECOMMEND_COUNT) + props.recommendPosts = getRecommendPost( + props.post, + allPosts, + BLOG.POST_RECOMMEND_COUNT + ) return { props, revalidate: 1 @@ -110,7 +118,7 @@ export async function getStaticProps ({ params: { slug } }) { * @param {*} count * @returns */ -function getRecommendPost (post, allPosts, count = 6) { +function getRecommendPost(post, allPosts, count = 6) { let recommendPosts = [] const postIds = [] const currentTags = post.tags || [] diff --git a/pages/category/[category].js b/pages/category/[category].js index 0505767e..80281a01 100644 --- a/pages/category/[category].js +++ b/pages/category/[category].js @@ -3,23 +3,26 @@ import React from 'react' import { useGlobal } from '@/lib/global' import * as ThemeMap from '@/themes' -export default function Category (props) { +export default function Category(props) { const { theme } = useGlobal() const ThemeComponents = ThemeMap[theme] const { siteInfo, posts } = props const { locale } = useGlobal() if (!posts) { - return + return } const meta = { - title: `${props.category} | ${locale.COMMON.CATEGORY} | ${siteInfo?.title || ''}`, + title: `${props.category} | ${locale.COMMON.CATEGORY} | ${ + siteInfo?.title || '' + }`, description: siteInfo?.description, + slug: 'category/' + props.category, type: 'website' } return } -export async function getStaticProps ({ params: { category } }) { +export async function getStaticProps({ params: { category } }) { const from = 'category-props' let props = await getGlobalNotionData({ from }) const posts = props.allPosts.filter( @@ -33,11 +36,13 @@ export async function getStaticProps ({ params: { category } }) { } } -export async function getStaticPaths () { +export async function getStaticPaths() { const from = 'category-paths' const { categories } = await getGlobalNotionData({ from }) return { - paths: Object.keys(categories).map(category => ({ params: { category: categories[category]?.name } })), + paths: Object.keys(categories).map(category => ({ + params: { category: categories[category]?.name } + })), fallback: true } } diff --git a/pages/category/index.js b/pages/category/index.js index 8890ddeb..1545408b 100644 --- a/pages/category/index.js +++ b/pages/category/index.js @@ -3,7 +3,7 @@ import React from 'react' import { useGlobal } from '@/lib/global' import * as ThemeMap from '@/themes' -export default function Category (props) { +export default function Category(props) { const { theme } = useGlobal() const ThemeComponents = ThemeMap[theme] const { locale } = useGlobal() @@ -11,13 +11,17 @@ export default function Category (props) { const meta = { title: `${locale.COMMON.CATEGORY} | ${siteInfo.title}`, description: siteInfo.description, + slug: 'category', type: 'website' } - return + return } -export async function getStaticProps () { - const props = await getGlobalNotionData({ from: 'category-index-props', categoryCount: 0 }) +export async function getStaticProps() { + const props = await getGlobalNotionData({ + from: 'category-index-props', + categoryCount: 0 + }) return { props, revalidate: 1 diff --git a/pages/index.js b/pages/index.js index 2e314239..9b8c8511 100644 --- a/pages/index.js +++ b/pages/index.js @@ -3,19 +3,21 @@ import { getPostBlocks } from '@/lib/notion' import { getGlobalNotionData } from '@/lib/notion/getNotionData' import * as ThemeMap from '@/themes' import { useGlobal } from '@/lib/global' -const Index = (props) => { +const Index = props => { const { theme } = useGlobal() const ThemeComponents = ThemeMap[theme] - return + return } -export async function getStaticProps () { +export async function getStaticProps() { const from = 'index' const props = await getGlobalNotionData({ from, pageType: ['Post'] }) const { allPosts, siteInfo } = props const meta = { title: `${siteInfo.title} | ${siteInfo.description}`, description: siteInfo.description, + image: siteInfo.pageCover, + slug: '', type: 'website' } @@ -35,7 +37,11 @@ export async function getStaticProps () { if (post.password && post.password !== '') { continue } - const blockMap = await getPostBlocks(post.id, 'slug', BLOG.POST_PREVIEW_LINES) + const blockMap = await getPostBlocks( + post.id, + 'slug', + BLOG.POST_PREVIEW_LINES + ) if (blockMap) { post.blockMap = blockMap } @@ -46,7 +52,8 @@ export async function getStaticProps () { return { props: { - meta, ...props + meta, + ...props }, revalidate: 1 } diff --git a/pages/page/[page].js b/pages/page/[page].js index 4561b8c6..1de94693 100644 --- a/pages/page/[page].js +++ b/pages/page/[page].js @@ -14,23 +14,26 @@ const Page = props => { const meta = { title: `${props.page} | Page | ${siteInfo.title}`, description: siteInfo.description, + slug: 'page/' + props.page, type: 'website' } return } -export async function getStaticPaths () { +export async function getStaticPaths() { const from = 'page-paths' const { postCount } = await getGlobalNotionData({ from }) const totalPages = Math.ceil(postCount / BLOG.POSTS_PER_PAGE) return { // remove first page, we 're not gonna handle that. - paths: Array.from({ length: totalPages - 1 }, (_, i) => ({ params: { page: '' + (i + 2) } })), + paths: Array.from({ length: totalPages - 1 }, (_, i) => ({ + params: { page: '' + (i + 2) } + })), fallback: true } } -export async function getStaticProps ({ params: { page } }) { +export async function getStaticProps({ params: { page } }) { const from = `page-${page}` const props = await getGlobalNotionData({ from }) props.page = page @@ -45,7 +48,11 @@ export async function getStaticProps ({ params: { page } }) { if (post.password && post.password !== '') { continue } - const blockMap = await getPostBlocks(post.id, 'slug', BLOG.POST_PREVIEW_LINES) + const blockMap = await getPostBlocks( + post.id, + 'slug', + BLOG.POST_PREVIEW_LINES + ) if (blockMap) { post.blockMap = blockMap } diff --git a/pages/search/[keyword].js b/pages/search/[keyword].js index 734bf5b4..1308726e 100644 --- a/pages/search/[keyword].js +++ b/pages/search/[keyword].js @@ -7,13 +7,22 @@ const Index = props => { const { keyword, siteInfo } = props const { locale } = useGlobal() const meta = { - title: `${keyword || ''} | ${locale.NAV.SEARCH} | ${siteInfo.title}`, + title: `${keyword || ''}${keyword ? ' | ' : ''}${locale.NAV.SEARCH} | ${ + siteInfo.title + }`, description: siteInfo.title, + slug: 'search/' + (keyword || ''), type: 'website' } const { theme } = useGlobal() const ThemeComponents = ThemeMap[theme] - return + return ( + + ) } /** @@ -21,8 +30,11 @@ const Index = props => { * @param {*} param0 * @returns */ -export async function getServerSideProps ({ params: { keyword } }) { - const props = await getGlobalNotionData({ from: 'search-props', pageType: ['Post'] }) +export async function getServerSideProps({ params: { keyword } }) { + const props = await getGlobalNotionData({ + from: 'search-props', + pageType: ['Post'] + }) props.posts = await filterByMemCache(props.allPosts, keyword) props.keyword = keyword return { @@ -37,7 +49,7 @@ export async function getServerSideProps ({ params: { keyword } }) { * @param key * @returns {*} */ -function appendText (sourceTextArray, targetObj, key) { +function appendText(sourceTextArray, targetObj, key) { if (!targetObj) { return sourceTextArray } @@ -54,7 +66,7 @@ function appendText (sourceTextArray, targetObj, key) { * @param {*} textArray * @returns */ -function getTextContent (textArray) { +function getTextContent(textArray) { if (typeof textArray === 'object' && isIterable(textArray)) { let result = '' for (const textObj of textArray) { @@ -71,7 +83,8 @@ function getTextContent (textArray) { * @param {*} obj * @returns */ -const isIterable = obj => obj != null && typeof obj[Symbol.iterator] === 'function' +const isIterable = obj => + obj != null && typeof obj[Symbol.iterator] === 'function' /** * 在内存缓存中进行全文索引 @@ -79,7 +92,7 @@ const isIterable = obj => obj != null && typeof obj[Symbol.iterator] === 'functi * @param keyword 关键词 * @returns */ -async function filterByMemCache (allPosts, keyword) { +async function filterByMemCache(allPosts, keyword) { const filterPosts = [] for (const post of allPosts) { const cacheKey = 'page_block_' + post.id diff --git a/pages/search/index.js b/pages/search/index.js index ab64aed0..222d03d0 100644 --- a/pages/search/index.js +++ b/pages/search/index.js @@ -12,7 +12,8 @@ const Search = props => { filteredPosts = posts.filter(post => { const tagContent = post.tags ? post.tags.join(' ') : '' const categoryContent = post.category ? post.category.join(' ') : '' - const searchContent = post.title + post.summary + tagContent + categoryContent + const searchContent = + post.title + post.summary + tagContent + categoryContent return searchContent.toLowerCase().includes(searchKey.toLowerCase()) }) } else { @@ -21,22 +22,35 @@ const Search = props => { const { locale } = useGlobal() const meta = { - title: `${searchKey || ''} | ${locale.NAV.SEARCH} | ${siteInfo.title}`, + title: `${searchKey || ''}${searchKey ? ' | ' : ''}${locale.NAV.SEARCH} | ${ + siteInfo.title + }`, description: siteInfo.description, + slug: 'search', type: 'website' } const { theme } = useGlobal() const ThemeComponents = ThemeMap[theme] - return + return ( + + ) } /** * 浏览器前端搜索 */ -export async function getStaticProps () { - const props = await getGlobalNotionData({ from: 'search-props', pageType: ['Post'] }) +export async function getStaticProps() { + const props = await getGlobalNotionData({ + from: 'search-props', + pageType: ['Post'] + }) props.posts = props.allPosts return { props, @@ -44,7 +58,7 @@ export async function getStaticProps () { } } -function getSearchKey () { +function getSearchKey() { const router = useRouter() if (router.query && router.query.s) { return router.query.s diff --git a/pages/tag/[tag].js b/pages/tag/[tag].js index ab87f0da..b5f36c0a 100644 --- a/pages/tag/[tag].js +++ b/pages/tag/[tag].js @@ -9,21 +9,28 @@ const Tag = props => { const { tag, siteInfo, posts } = props if (!posts) { - return + return } const meta = { title: `${tag} | ${locale.COMMON.TAGS} | ${siteInfo?.title}`, description: siteInfo?.description, + slug: 'tag/' + tag, type: 'website' } - return + return } -export async function getStaticProps ({ params: { tag } }) { - const props = await getGlobalNotionData({ from: 'tag-props', includePage: false, tagsCount: 0 }) +export async function getStaticProps({ params: { tag } }) { + const props = await getGlobalNotionData({ + from: 'tag-props', + includePage: false, + tagsCount: 0 + }) const { allPosts } = props - props.posts = allPosts.filter(post => post && post.tags && post.tags.includes(tag)) + props.posts = allPosts.filter( + post => post && post.tags && post.tags.includes(tag) + ) props.tag = tag return { props, @@ -36,7 +43,7 @@ export async function getStaticProps ({ params: { tag } }) { * @returns * @param tags */ -function getTagNames (tags) { +function getTagNames(tags) { const tagNames = [] tags.forEach(tag => { tagNames.push(tag.name) @@ -44,13 +51,15 @@ function getTagNames (tags) { return tagNames } -export async function getStaticPaths () { +export async function getStaticPaths() { const from = 'tag-static-path' const { tags } = await getGlobalNotionData({ from, tagsCount: 0 }) const tagNames = getTagNames(tags) return { - paths: Object.keys(tagNames).map(index => ({ params: { tag: tagNames[index] } })), + paths: Object.keys(tagNames).map(index => ({ + params: { tag: tagNames[index] } + })), fallback: true } } diff --git a/pages/tag/index.js b/pages/tag/index.js index a4ab47a7..50c9ff8c 100644 --- a/pages/tag/index.js +++ b/pages/tag/index.js @@ -11,12 +11,13 @@ const TagIndex = props => { const meta = { title: `${locale.COMMON.TAGS} | ${siteInfo.title}`, description: siteInfo.description, + slug: 'tag', type: 'website' } return } -export async function getStaticProps () { +export async function getStaticProps() { const from = 'tag-index-props' const props = await getGlobalNotionData({ from, tagsCount: 0 }) return { diff --git a/themes/example/LayoutArchive.js b/themes/example/LayoutArchive.js index 0ad74453..9edb9c24 100644 --- a/themes/example/LayoutArchive.js +++ b/themes/example/LayoutArchive.js @@ -44,7 +44,10 @@ export const LayoutArchive = props => { {post.date.start_date} {' '}   - + {post.title} diff --git a/themes/example/LayoutIndex.js b/themes/example/LayoutIndex.js index 95e63bce..11da972e 100644 --- a/themes/example/LayoutIndex.js +++ b/themes/example/LayoutIndex.js @@ -12,41 +12,63 @@ export const LayoutIndex = props => { const totalPage = Math.ceil(postCount / BLOG.POSTS_PER_PAGE) const page = 1 - const showNext = page < totalPage && posts.length === BLOG.POSTS_PER_PAGE && posts.length < postCount + const showNext = + page < totalPage && + posts.length === BLOG.POSTS_PER_PAGE && + posts.length < postCount const currentPage = +page return ( {posts.map(p => ( - ) } diff --git a/themes/example/LayoutPage.js b/themes/example/LayoutPage.js index 2f5f795a..d8bb93ba 100644 --- a/themes/example/LayoutPage.js +++ b/themes/example/LayoutPage.js @@ -4,7 +4,7 @@ import Link from 'next/link' import { useRouter } from 'next/router' import LayoutBase from './LayoutBase' -export const LayoutPage = (props) => { +export const LayoutPage = props => { const { page } = props const { posts, postCount } = props @@ -12,41 +12,60 @@ export const LayoutPage = (props) => { const router = useRouter() const totalPage = Math.ceil(postCount / BLOG.POSTS_PER_PAGE) - const showNext = page < totalPage && posts.length === BLOG.POSTS_PER_PAGE && posts.length < postCount + const showNext = + page < totalPage && + posts.length === BLOG.POSTS_PER_PAGE && + posts.length < postCount const currentPage = +page return ( {posts.map(p => ( - ) } diff --git a/themes/fukasawa/components/BlogCard.js b/themes/fukasawa/components/BlogCard.js index 05f8b3c2..507bac40 100644 --- a/themes/fukasawa/components/BlogCard.js +++ b/themes/fukasawa/components/BlogCard.js @@ -7,33 +7,44 @@ import Card from './Card' const BlogCard = ({ post, showSummary }) => { const showPreview = CONFIG_FUKA.POST_LIST_PREVIEW && post.blockMap return ( - -
+ +
+
+ + + {post.title} + + -
- - - {post.title} - - - - {(!showPreview || showSummary) &&

- {post.summary} -

} -
- - {CONFIG_FUKA.POST_LIST_COVER && post?.page_cover && ( - -
- {/* eslint-disable-next-line @next/next/no-img-element */} - {post.title} - {/* {post.title} */} + {(!showPreview || showSummary) && ( +

+ {post.summary} +

+ )}
- - )} -
- + {CONFIG_FUKA.POST_LIST_COVER && post?.page_cover && ( + +
+ {/* eslint-disable-next-line @next/next/no-img-element */} + {post.title} + {/* {post.title} */} +
+ + )} +
+
) } diff --git a/themes/fukasawa/components/BlogPostArchive.js b/themes/fukasawa/components/BlogPostArchive.js index 02b3a1bc..90bc400a 100644 --- a/themes/fukasawa/components/BlogPostArchive.js +++ b/themes/fukasawa/components/BlogPostArchive.js @@ -12,20 +12,34 @@ const BlogArchiveItem = ({ posts = [], archiveTitle }) => { if (!posts || posts.length === 0) { return <> } else { - return
-
{archiveTitle}
-
    - {posts.map(post => ( -
  • -
    {post.date.start_date}   - - {post.title} - -
    -
  • - ))} -
-
+ return ( +
+
+ {archiveTitle} +
+
    + {posts.map(post => ( +
  • +
    + {post.date.start_date}{' '} +   + + + {post.title} + + +
    +
  • + ))} +
+
+ ) } } diff --git a/themes/fukasawa/components/PaginationSimple.js b/themes/fukasawa/components/PaginationSimple.js index 71a0c431..11eb837d 100644 --- a/themes/fukasawa/components/PaginationSimple.js +++ b/themes/fukasawa/components/PaginationSimple.js @@ -15,22 +15,38 @@ const PaginationSimple = ({ page, showNext }) => { const router = useRouter() const currentPage = +page return ( -
- +
+ - + diff --git a/themes/hexo/components/ArticleRecommend.js b/themes/hexo/components/ArticleRecommend.js index 8719be05..c1273c8a 100644 --- a/themes/hexo/components/ArticleRecommend.js +++ b/themes/hexo/components/ArticleRecommend.js @@ -8,8 +8,12 @@ import { useGlobal } from '@/lib/global' * @param {prev,next} param0 * @returns */ -export default function ArticleRecommend ({ recommendPosts, siteInfo }) { - if (!CONFIG_HEXO.ARTICLE_RECOMMEND || !recommendPosts || recommendPosts.length === 0) { +export default function ArticleRecommend({ recommendPosts, siteInfo }) { + if ( + !CONFIG_HEXO.ARTICLE_RECOMMEND || + !recommendPosts || + recommendPosts.length === 0 + ) { return <> } const { locale } = useGlobal() @@ -28,21 +32,31 @@ export default function ArticleRecommend ({ recommendPosts, siteInfo }) { : `url("${siteInfo?.pageCover}")` return ( - - - -
+ -
-
-
{post.date?.start_date}
-
{post.title}
+
+
+
+
+ + {post.date?.start_date} +
+
{post.title}
+
-
-
+ ) })} diff --git a/themes/hexo/components/BlogPostArchive.js b/themes/hexo/components/BlogPostArchive.js index 610e575a..f7d06014 100644 --- a/themes/hexo/components/BlogPostArchive.js +++ b/themes/hexo/components/BlogPostArchive.js @@ -12,20 +12,34 @@ const BlogPostArchive = ({ posts = [], archiveTitle }) => { if (!posts || posts.length === 0) { return <> } else { - return
-
{archiveTitle}
-
    - {posts.map(post => ( -
  • -
    {post.date.start_date}   - - {post.title} - -
    -
  • - ))} -
-
+ return ( +
+
+ {archiveTitle} +
+
    + {posts.map(post => ( +
  • +
    + {post.date.start_date}{' '} +   + + + {post.title} + + +
    +
  • + ))} +
+
+ ) } } diff --git a/themes/hexo/components/BlogPostCard.js b/themes/hexo/components/BlogPostCard.js index 89580723..cb4fa647 100644 --- a/themes/hexo/components/BlogPostCard.js +++ b/themes/hexo/components/BlogPostCard.js @@ -1,73 +1,106 @@ import BLOG from '@/blog.config' import Link from 'next/link' import React from 'react' -import { Code, Collection, CollectionRow, Equation, NotionRenderer } from 'react-notion-x' +import { + Code, + Collection, + CollectionRow, + Equation, + NotionRenderer +} from 'react-notion-x' import TagItemMini from './TagItemMini' import CONFIG_HEXO from '../config_hexo' const BlogPostCard = ({ post, showSummary }) => { const showPreview = CONFIG_HEXO.POST_LIST_PREVIEW && post.blockMap return ( -
-
- -
- - - {post.title} - - - -
- - {post.date.start_date} +
+
+ - {(!showPreview || showSummary) &&

- {post.summary} -

} - - {showPreview &&
- -
} - -
- - - {post.category} +
+ + + + {post.date.start_date} -
-
{post.tagItems.map(tag => ())}
+
+ + {(!showPreview || showSummary) && ( +

+ {post.summary} +

+ )} + + {showPreview && ( +
+
+ )} + +
+ + + + {post.category} + + +
+
+ {' '} + {post.tagItems.map(tag => ( + + ))} +
+
+
+ {CONFIG_HEXO.POST_LIST_COVER && !showPreview && post?.page_cover && ( + +
+ {/* eslint-disable-next-line @next/next/no-img-element */} + {post.title} + {/* {post.title} */} +
+ + )}
- - {CONFIG_HEXO.POST_LIST_COVER && !showPreview && post?.page_cover && ( - -
- {/* eslint-disable-next-line @next/next/no-img-element */} - {post.title} - {/* {post.title} */} -
- - )}
- -
- ) } diff --git a/themes/hexo/components/LatestPostsGroup.js b/themes/hexo/components/LatestPostsGroup.js index d3a4c51d..6b82afd5 100644 --- a/themes/hexo/components/LatestPostsGroup.js +++ b/themes/hexo/components/LatestPostsGroup.js @@ -26,7 +26,7 @@ const LatestPostsGroup = ({ posts, siteInfo }) => {
{posts.map(post => { - const selected = currentPath === `${BLOG.PATH}/article/${post.slug}` + const selected = currentPath === `${BLOG.SUB_PATH}/article/${post.slug}` const headerImage = post?.page_cover ? `url("${post.page_cover}")` : `url("${siteInfo?.pageCover}")` @@ -35,7 +35,7 @@ const LatestPostsGroup = ({ posts, siteInfo }) => { diff --git a/themes/hexo/components/PaginationNumber.js b/themes/hexo/components/PaginationNumber.js index 8af89e17..48192d47 100644 --- a/themes/hexo/components/PaginationNumber.js +++ b/themes/hexo/components/PaginationNumber.js @@ -16,46 +16,69 @@ const PaginationNumber = ({ page, totalPage }) => { const pages = generatePages(page, currentPage, totalPage) return ( -
- +
{/* 上一页 */} + href={{ + pathname: + currentPage - 1 === 1 + ? `${BLOG.SUB_PATH || '/'}` + : `/page/${currentPage - 1}`, + query: router.query.s ? { s: router.query.s } : {} + }} + passHref + > {pages} {/* 下一页 */} - +
) } -function getPageElement (page, currentPage) { - return -
- {page} +function getPageElement(page, currentPage) { + return ( + + + {page} + ) } -function generatePages (page, currentPage, totalPage) { +function generatePages(page, currentPage, totalPage) { const pages = [] const groupCount = 7 // 最多显示页签数 if (totalPage <= groupCount) { diff --git a/themes/medium/LayoutArchive.js b/themes/medium/LayoutArchive.js index 0ad74453..9edb9c24 100644 --- a/themes/medium/LayoutArchive.js +++ b/themes/medium/LayoutArchive.js @@ -44,7 +44,10 @@ export const LayoutArchive = props => { {post.date.start_date} {' '}   - + {post.title} diff --git a/themes/medium/components/BlogPostCard.js b/themes/medium/components/BlogPostCard.js index d0566e75..0af31a13 100644 --- a/themes/medium/components/BlogPostCard.js +++ b/themes/medium/components/BlogPostCard.js @@ -11,32 +11,48 @@ const BlogPostCard = ({ post, showSummary }) => { const showPreview = CONFIG_MEDIUM.POST_LIST_PREVIEW && post.blockMap const { locale } = useGlobal() return ( -
+
+
+ + + {post.title} + + -
- - - {post.title} - - +
+
{post.date.start_date}
+ {CONFIG_MEDIUM.POST_LIST_CATEGORY && ( + + )} + {CONFIG_MEDIUM.POST_LIST_TAG && + post?.tagItems?.map(tag => ( + + ))} +
-
-
{post.date.start_date}
- { CONFIG_MEDIUM.POST_LIST_CATEGORY && } - { CONFIG_MEDIUM.POST_LIST_TAG && post?.tagItems?.map(tag => )} -
+
-
- -
- - {(!showPreview || showSummary) &&

+ {(!showPreview || showSummary) && ( +

{post.summary} -

} +

+ )} - {showPreview &&
+ {showPreview && ( +
{ collection: Collection }} /> - +
+
+ )}
- +
) } diff --git a/themes/medium/components/PaginationSimple.js b/themes/medium/components/PaginationSimple.js index fcf06ba2..080a899f 100644 --- a/themes/medium/components/PaginationSimple.js +++ b/themes/medium/components/PaginationSimple.js @@ -16,22 +16,38 @@ const PaginationSimple = ({ page, totalPage }) => { const currentPage = +page const showNext = currentPage < totalPage return ( -
- +
+ - + diff --git a/themes/next/components/BlogPostArchive.js b/themes/next/components/BlogPostArchive.js index 5c3bc169..0ef8ee86 100644 --- a/themes/next/components/BlogPostArchive.js +++ b/themes/next/components/BlogPostArchive.js @@ -12,20 +12,34 @@ const BlogPostArchive = ({ posts = [], archiveTitle }) => { if (!posts || posts.length === 0) { return <> } else { - return
-
{archiveTitle}
-
    - {posts.map(post => ( -
  • -
    {post.date.start_date}   - - {post.title} - -
    -
  • - ))} -
-
+ return ( +
+
+ {archiveTitle} +
+
    + {posts.map(post => ( +
  • +
    + {post.date.start_date}{' '} +   + + + {post.title} + + +
    +
  • + ))} +
+
+ ) } } diff --git a/themes/next/components/BlogPostCard.js b/themes/next/components/BlogPostCard.js index e5f8ad72..d51baf68 100644 --- a/themes/next/components/BlogPostCard.js +++ b/themes/next/components/BlogPostCard.js @@ -3,7 +3,13 @@ import { useGlobal } from '@/lib/global' import Image from 'next/image' import Link from 'next/link' import React from 'react' -import { Code, Collection, CollectionRow, Equation, NotionRenderer } from 'react-notion-x' +import { + Code, + Collection, + CollectionRow, + Equation, + NotionRenderer +} from 'react-notion-x' import Card from './Card' import TagItemMini from './TagItemMini' import CONFIG_NEXT from '../config_next' @@ -12,77 +18,115 @@ const BlogPostCard = ({ post, showSummary }) => { const { locale } = useGlobal() const showPreview = CONFIG_NEXT.POST_LIST_PREVIEW && post.blockMap return ( - -
- -
- - - {post.title} - - - -
-
- { post.category && (<> - - - {post.category} + +
+
+ + + {post.title} - | - ) } - - {post.date.start_date} - + +
+
+ {post.category && ( + <> + + + + {post.category} + + + | + + )} + + + {post.date.start_date} + + +
+
+
+ {' '} + {post.tagItems.map(tag => ( + + ))} +
+
-
-
{post.tagItems.map(tag => ())}
-
-
- {(!showPreview || showSummary) && !post.results &&

- {post.summary} -

} + {(!showPreview || showSummary) && !post.results && ( +

+ {post.summary} +

+ )} - {/* 搜索结果 */} - {post.results &&

- {post.results.map(r => {r})} -

} + {/* 搜索结果 */} + {post.results && ( +

+ {post.results.map(r => ( + {r} + ))} +

+ )} - {showPreview && post?.blockMap &&
- -
} + {showPreview && post?.blockMap && ( +
+ +
+ )} - + + {CONFIG_NEXT.POST_LIST_COVER && post?.page_cover && ( + +
+ {post.title} +
-
+ )}
- - {CONFIG_NEXT.POST_LIST_COVER && post?.page_cover && ( - -
- {post.title} -
- - )} -
- ) } diff --git a/themes/next/components/LatestPostsGroup.js b/themes/next/components/LatestPostsGroup.js index 914c73f9..54374834 100644 --- a/themes/next/components/LatestPostsGroup.js +++ b/themes/next/components/LatestPostsGroup.js @@ -17,24 +17,41 @@ const LatestPostsGroup = ({ posts }) => { const currentPath = useRouter().asPath const { locale } = useGlobal() - return <> -
-
{locale.COMMON.LATEST_POSTS}
+ return ( + <> +
+
+ + {locale.COMMON.LATEST_POSTS} +
{posts.map(post => { - const selected = currentPath === `${BLOG.PATH}/article/${post.slug}` + const selected = currentPath === `${BLOG.SUB_PATH}/article/${post.slug}` return ( - - -
- -
{post.title}
+ +
+
+ +
{post.title}
) })} + ) } export default LatestPostsGroup diff --git a/themes/next/components/PaginationNumber.js b/themes/next/components/PaginationNumber.js index d77c6d0c..b74bc550 100644 --- a/themes/next/components/PaginationNumber.js +++ b/themes/next/components/PaginationNumber.js @@ -16,45 +16,68 @@ const PaginationNumber = ({ page, totalPage }) => { const pages = generatePages(page, currentPage, totalPage) return ( -
- +
{/* 上一页 */} + href={{ + pathname: + currentPage - 1 === 1 + ? `${BLOG.SUB_PATH || '/'}` + : `/page/${currentPage - 1}`, + query: router.query.s ? { s: router.query.s } : {} + }} + passHref + > {pages} {/* 下一页 */} - +
) } -function getPageElement (page, currentPage) { - return - - {page} +function getPageElement(page, currentPage) { + return ( + + + {page} + ) } -function generatePages (page, currentPage, totalPage) { +function generatePages(page, currentPage, totalPage) { const pages = [] const groupCount = 7 // 最多显示页签数 if (totalPage <= groupCount) { diff --git a/themes/next/components/PaginationSimple.js b/themes/next/components/PaginationSimple.js index 37ac4fd1..38956407 100644 --- a/themes/next/components/PaginationSimple.js +++ b/themes/next/components/PaginationSimple.js @@ -15,22 +15,38 @@ const PaginationSimple = ({ page, showNext }) => { const router = useRouter() const currentPage = +page return ( -
+
+ href={{ + pathname: + currentPage - 1 === 1 + ? `${BLOG.SUB_PATH || '/'}` + : `/page/${currentPage - 1}`, + query: router.query.s ? { s: router.query.s } : {} + }} + passHref + > - +