From eb251d95142bf20fc5ab62119a366af444347385 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Thu, 3 Mar 2022 21:28:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E9=A1=B5=E9=9D=A2=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.config.js | 5 +++-- lib/global.js | 5 ++++- pages/404.js | 6 ++++-- pages/[slug].js | 7 ++++--- pages/archive/index.js | 11 ++++++----- pages/article/[slug].js | 7 ++++--- pages/category/[category].js | 5 +++-- pages/category/index.js | 5 +++-- pages/index.js | 8 +++----- pages/page/[page].js | 11 +++++------ pages/search/[keyword].js | 25 +++++++++++++------------ pages/search/index.js | 6 ++++-- pages/tag/[tag].js | 5 +++-- pages/tag/index.js | 5 +++-- themes/index.js | 6 +++--- 15 files changed, 65 insertions(+), 52 deletions(-) diff --git a/blog.config.js b/blog.config.js index 91996bca..c06a9f26 100644 --- a/blog.config.js +++ b/blog.config.js @@ -8,12 +8,13 @@ const BLOG = { KEYWORDS: 'Notion, 博客', // 网站关键词 英文逗号隔开 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_BUTTON: true, // 是否显示调试按钮,可以用来调试不同的主题和样式配置 THEME: process.env.NEXT_PUBLIC_THEME || 'Next', // 主题, 支持 ['Next','Hexo',"Fukasawa','Medium'] LANG: 'zh-CN', // e.g 'zh-CN','en-US' see /lib/lang.js for more. SINCE: 2021, // e.g if leave this empty, current year will be used. BEI_AN: process.env.NEXT_PUBLIC_BEI_AN || '', // 备案号 闽ICP备XXXXXXX - APPEARANCE: 'auto', // ['light', 'dark', 'auto'], + 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 BACKGROUND_LIGHT: '#eeeeee', // use hex value, don't forget '#' e.g #fffefc @@ -21,7 +22,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_LIST_PREVIEW: false, // 是否在列表加载文章预览 POST_PREVIEW_LINES: 12, // 预览博客行数 POSTS_PER_PAGE: 6, // post counts per page POSTS_SORT_BY: 'notion', // 排序方式 'date'按时间,'notion'由notion控制 diff --git a/lib/global.js b/lib/global.js index 7a2acb84..432a423f 100644 --- a/lib/global.js +++ b/lib/global.js @@ -3,6 +3,7 @@ import { useContext, createContext, useState } from 'react' import Router from 'next/router' import { initDarkMode } from './theme' import BLOG from '@/blog.config' +import { ThemeMap } from '@/themes' const GlobalContext = createContext() let hasInit = false @@ -17,6 +18,8 @@ export function GlobalContextProvider ({ children }) { const [isDarkMode, updateDarkMode] = useState(false) const [onLoading, changeLoadingState] = useState(false) const [theme, setTheme] = useState(BLOG.THEME) + const ThemeComponents = ThemeMap[theme] + Router.events.on('routeChangeStart', (...args) => { changeLoadingState(true) }) @@ -35,7 +38,7 @@ export function GlobalContextProvider ({ children }) { }, 100) return ( - + {children} ) diff --git a/pages/404.js b/pages/404.js index 64cc2dc7..b14f859b 100644 --- a/pages/404.js +++ b/pages/404.js @@ -1,4 +1,4 @@ -import { Layout404 } from '@/themes' +import { useGlobal } from '@/lib/global' /** * 自定义404界面 @@ -7,5 +7,7 @@ import { Layout404 } from '@/themes' */ export default function Custom404 (props) { - return + const { ThemeComponents } = useGlobal() + + return } diff --git a/pages/[slug].js b/pages/[slug].js index 4d1a13d9..eda1bc51 100644 --- a/pages/[slug].js +++ b/pages/[slug].js @@ -1,8 +1,8 @@ import BLOG from '@/blog.config' import { getPostBlocks } from '@/lib/notion' import { getGlobalNotionData } from '@/lib/notion/getNotionData' -import { LayoutSlug } from '@/themes' -import Custom404 from '@/pages/404' +import { useGlobal } from '@/lib/global' +import Custom404 from './404' /** * 根据notion的slug访问页面,针对类型为Page的页面 @@ -10,10 +10,11 @@ import Custom404 from '@/pages/404' * @returns */ const Slug = (props) => { + const { ThemeComponents } = useGlobal() if (!props.post) { return } - return + return } export async function getStaticPaths () { diff --git a/pages/archive/index.js b/pages/archive/index.js index 4dffb49d..6d974951 100644 --- a/pages/archive/index.js +++ b/pages/archive/index.js @@ -1,6 +1,11 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData' import React from 'react' -import { LayoutArchive } from '@/themes' +import { useGlobal } from '@/lib/global' + +const ArchiveIndex = (props) => { + const { ThemeComponents } = useGlobal() + return +} export async function getStaticProps () { const { allPosts, categories, tags, postCount, customNav } = @@ -18,8 +23,4 @@ export async function getStaticProps () { } } -const ArchiveIndex = (props) => { - return -} - export default ArchiveIndex diff --git a/pages/article/[slug].js b/pages/article/[slug].js index d79e0cc7..29a03539 100644 --- a/pages/article/[slug].js +++ b/pages/article/[slug].js @@ -1,8 +1,8 @@ import BLOG from '@/blog.config' import { getPostBlocks } from '@/lib/notion' import { getGlobalNotionData } from '@/lib/notion/getNotionData' -import { LayoutSlug } from '@/themes' -import Custom404 from '@/pages/404' +import { useGlobal } from '@/lib/global' +import Custom404 from '../404' /** * 根据notion的slug访问页面 @@ -10,10 +10,11 @@ import Custom404 from '@/pages/404' * @returns */ const Slug = (props) => { + const { ThemeComponents } = useGlobal() if (!props.post) { return } - return + return } export async function getStaticPaths () { diff --git a/pages/category/[category].js b/pages/category/[category].js index 681a23c6..3362d419 100644 --- a/pages/category/[category].js +++ b/pages/category/[category].js @@ -1,9 +1,10 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData' import React from 'react' -import { LayoutCategory } from '@/themes' +import { useGlobal } from '@/lib/global' export default function Category (props) { - return + const { ThemeComponents } = useGlobal() + return } export async function getStaticProps ({ params }) { diff --git a/pages/category/index.js b/pages/category/index.js index 7361a706..22232a7d 100644 --- a/pages/category/index.js +++ b/pages/category/index.js @@ -1,9 +1,10 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData' import React from 'react' -import { LayoutCategoryIndex } from '@/themes' +import { useGlobal } from '@/lib/global' export default function Category (props) { - return + const { ThemeComponents } = useGlobal() + return } export async function getStaticProps () { diff --git a/pages/index.js b/pages/index.js index b97fad52..5cebee4c 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,13 +1,11 @@ import BLOG from '@/blog.config' import { getPostBlocks } from '@/lib/notion' import { getGlobalNotionData } from '@/lib/notion/getNotionData' -import { LayoutIndex, THEME_CONFIG, ThemeMap } from '@/themes' import { useGlobal } from '@/lib/global' const Index = (props) => { - const { theme } = useGlobal() - console.log('模板', ThemeMap[theme].LayoutIndex) - return + const { ThemeComponents } = useGlobal() + return } export async function getStaticProps () { @@ -29,7 +27,7 @@ export async function getStaticProps () { BLOG.POSTS_PER_PAGE * (page - 1), BLOG.POSTS_PER_PAGE * page ) - if (THEME_CONFIG.POST_LIST_PREVIEW || BLOG.POST_LIST_PREVIEW) { + if (BLOG.POST_LIST_PREVIEW) { for (const i in postsToShow) { const post = postsToShow[i] const blockMap = await getPostBlocks(post.id, 'slug', BLOG.POST_PREVIEW_LINES) diff --git a/pages/page/[page].js b/pages/page/[page].js index 211a2f92..6a07589c 100644 --- a/pages/page/[page].js +++ b/pages/page/[page].js @@ -1,14 +1,14 @@ import BLOG from '@/blog.config' import { getPostBlocks } from '@/lib/notion' import { getGlobalNotionData } from '@/lib/notion/getNotionData' -import { LayoutPage, THEME_CONFIG } from '@/themes' -import Custom404 from '@/pages/404' +import { useGlobal } from '@/lib/global' const Page = (props) => { + const { ThemeComponents } = useGlobal() if (!props?.meta) { - return + return } - return + return } export async function getStaticPaths () { @@ -43,8 +43,7 @@ export async function getStaticProps ({ params: { page } }) { BLOG.POSTS_PER_PAGE * (page - 1), BLOG.POSTS_PER_PAGE * page ) - // 加载预览 - if (THEME_CONFIG.POST_LIST_PREVIEW || BLOG.POST_LIST_PREVIEW) { + if (BLOG.POST_LIST_PREVIEW) { for (const i in postsToShow) { const post = postsToShow[i] const blockMap = await getPostBlocks(post.id, 'slug', BLOG.POST_PREVIEW_LINES) diff --git a/pages/search/[keyword].js b/pages/search/[keyword].js index 4bc6166e..109768db 100644 --- a/pages/search/[keyword].js +++ b/pages/search/[keyword].js @@ -1,9 +1,21 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData' -import { LayoutSearch } from '@/themes' import BLOG from '@/blog.config' import { useGlobal } from '@/lib/global' import { getDataFromCache } from '@/lib/cache/cache_manager' +const Index = (props) => { + const { keyword } = props + const { locale } = useGlobal() + const meta = { + title: `${keyword || ''} | ${locale.NAV.SEARCH} | ${BLOG.TITLE} `, + description: BLOG.DESCRIPTION, + type: 'website' + } + + const { ThemeComponents } = useGlobal() + return +} + /** * 服务端搜索 * @param {*} param0 @@ -33,17 +45,6 @@ export async function getServerSideProps ({ params: { keyword } }) { } } -const Index = (props) => { - const { keyword } = props - const { locale } = useGlobal() - const meta = { - title: `${keyword || ''} | ${locale.NAV.SEARCH} | ${BLOG.TITLE} `, - description: BLOG.DESCRIPTION, - type: 'website' - } - return -} - /** * 将对象的指定字段拼接到字符串 * @param sourceTextArray diff --git a/pages/search/index.js b/pages/search/index.js index fb1ffc89..f0d266f3 100644 --- a/pages/search/index.js +++ b/pages/search/index.js @@ -1,5 +1,4 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData' -import { LayoutSearch } from '@/themes' import BLOG from '@/blog.config' import { useGlobal } from '@/lib/global' import { useRouter } from 'next/router' @@ -51,7 +50,10 @@ const Search = (props) => { description: BLOG.DESCRIPTION, type: 'website' } - return + + const { ThemeComponents } = useGlobal() + + return } function getSearchKey () { diff --git a/pages/tag/[tag].js b/pages/tag/[tag].js index 169352f6..90a5a9d2 100644 --- a/pages/tag/[tag].js +++ b/pages/tag/[tag].js @@ -1,8 +1,9 @@ +import { useGlobal } from '@/lib/global' import { getGlobalNotionData } from '@/lib/notion/getNotionData' -import { LayoutTag } from '@/themes' const Tag = (props) => { - return + const { ThemeComponents } = useGlobal() + return } export async function getStaticProps ({ params }) { diff --git a/pages/tag/index.js b/pages/tag/index.js index cdf8a401..90d0b9ec 100644 --- a/pages/tag/index.js +++ b/pages/tag/index.js @@ -1,9 +1,10 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData' import React from 'react' -import { LayoutTagIndex } from '@/themes' +import { useGlobal } from '@/lib/global' const TagIndex = (props) => { - return + const { ThemeComponents } = useGlobal() + return } export async function getStaticProps () { diff --git a/themes/index.js b/themes/index.js index 0a55c5a0..84cd91f1 100644 --- a/themes/index.js +++ b/themes/index.js @@ -3,15 +3,15 @@ */ import * as Next from './Next' -import * as Empty from './Empty' import * as Fukasawa from './Fukasawa' import * as Hexo from './Hexo' import * as Medium from './Medium' +import * as Empty from './Empty' export * from './Medium' export const ThemeMap = { Next, - Empty, Fukasawa, Hexo, - Medium + Medium, + Empty }