From aefca7171e095732287d89a8ac66905e5f100198 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Fri, 12 Apr 2024 12:44:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E8=AF=AD=E8=A8=80=E9=85=8D=E7=BD=AE,s?= =?UTF-8?q?tarter=E4=B8=BB=E9=A2=98=E5=BE=AE=E8=B0=83=E3=80=81=E5=85=BC?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/config.js | 49 ++-- lib/notion/getNotionConfig.js | 30 +-- pages/[prefix]/[slug]/[...suffix].js | 7 +- pages/[prefix]/[slug]/index.js | 7 +- pages/[prefix]/index.js | 7 +- pages/_document.js | 67 +++-- themes/starter/components/Footer.js | 315 ++++++++++++---------- themes/starter/components/Team.js | 139 +++++----- themes/starter/components/Testimonials.js | 180 +++++++------ themes/starter/index.js | 296 +++++++++++--------- 10 files changed, 597 insertions(+), 500 deletions(-) diff --git a/lib/config.js b/lib/config.js index 546597c2..ee56f91d 100644 --- a/lib/config.js +++ b/lib/config.js @@ -52,7 +52,7 @@ export const siteConfig = (key, defaultVal = null, extendConfig = null) => { } } - // 其次 有传入的配置参考,则尝试读取 + // 其次 有传入的extendConfig,则尝试读取 if (!val && extendConfig) { val = extendConfig[key] } @@ -64,24 +64,37 @@ export const siteConfig = (key, defaultVal = null, extendConfig = null) => { if (!val) { return defaultVal - } else { - if (typeof val === 'string') { - if (val === 'true' || val === 'false') { - return JSON.parse(val) - } - if (/^\d+$/.test(val)) { - // 如果是数字,使用parseFloat或者parseInt将字符串转换为数字 - return parseInt(val) - } - return val - } else { - try { - return JSON.parse(val) - } catch (error) { - // 如果值是一个字符串但不是有效的 JSON 格式,直接返回字符串 - return val - } + } + + // 从Notion_CONFIG读取的配置通常都是字符串,适当转义 + if (typeof val === 'string') { + // 解析布尔 + if (val === 'true' || val === 'false') { + return JSON.parse(val) } + + // 解析数字,parseInt将字符串转换为数字 + if (/^\d+$/.test(val)) { + return parseInt(val) + } + // 转移 [] , {} 这种json串为json对象 + try { + const parsedJson = JSON.parse(val) + // 检查解析后的结果是否是对象或数组 + if (typeof parsedJson === 'object' && parsedJson !== null) { + return parsedJson + } + } catch (error) { + // JSON 解析失败,返回原始字符串值 + return val + } + } + + try { + return JSON.parse(val) + } catch (error) { + // 如果值是一个字符串但不是有效的 JSON 格式,直接返回字符串 + return val } } diff --git a/lib/notion/getNotionConfig.js b/lib/notion/getNotionConfig.js index 9985d977..889005f2 100644 --- a/lib/notion/getNotionConfig.js +++ b/lib/notion/getNotionConfig.js @@ -7,6 +7,7 @@ * */ import { getDateValue, getTextContent } from 'notion-utils' +import { deepClone } from '../utils' import getAllPageIds from './getAllPageIds' import { getPostBlocks } from './getPostBlocks' @@ -162,9 +163,12 @@ export async function getConfigMapFromConfigPage(allPages) { } // 最后检查Notion_Config页面的INLINE_CONFIG,是否是一个js对象 - const inlineConfigs = parseConfig(configPage?.INLINE_CONFIG) - - return Object.assign({}, notionConfig, inlineConfigs) + const combine = Object.assign( + {}, + deepClone(notionConfig), + parseConfig(notionConfig?.INLINE_CONFIG) + ) + return combine } /** @@ -176,19 +180,13 @@ export function parseConfig(configString) { if (!configString) { return {} } + // 解析对象 try { - // 尝试解析为 JSON 对象 - const jsonConfig = JSON.parse(configString) - return jsonConfig - } catch (error) { - // 如果解析失败,则尝试使用 eval() - try { - // eslint-disable-next-line no-eval - const config = eval('(' + configString + ')') - return config - } catch (evalError) { - console.error('解析 INLINE_CONFIG 配置时出错:', evalError) - return {} - } + // eslint-disable-next-line no-eval + const config = eval('(' + configString + ')') + return config + } catch (evalError) { + console.error('解析 eval(INLINE_CONFIG) 配置时出错:', evalError) + return {} } } diff --git a/pages/[prefix]/[slug]/[...suffix].js b/pages/[prefix]/[slug]/[...suffix].js index 0d912a0b..fb958af6 100644 --- a/pages/[prefix]/[slug]/[...suffix].js +++ b/pages/[prefix]/[slug]/[...suffix].js @@ -55,13 +55,14 @@ export async function getStaticProps({ locale }) { let fullSlug = prefix + '/' + slug + '/' + suffix.join('/') - if (JSON.parse(BLOG.PSEUDO_STATIC)) { + const from = `slug-props-${fullSlug}` + const props = await getGlobalData({ from, locale }) + if (siteConfig('PSEUDO_STATIC', BLOG.PSEUDO_STATIC, props.NOTION_CONFIG)) { if (!fullSlug.endsWith('.html')) { fullSlug += '.html' } } - const from = `slug-props-${fullSlug}` - const props = await getGlobalData({ from, locale }) + // 在列表内查找文章 props.post = props?.allPages?.find(p => { return ( diff --git a/pages/[prefix]/[slug]/index.js b/pages/[prefix]/[slug]/index.js index 88c1fc42..d2c00861 100644 --- a/pages/[prefix]/[slug]/index.js +++ b/pages/[prefix]/[slug]/index.js @@ -39,13 +39,14 @@ export async function getStaticPaths() { export async function getStaticProps({ params: { prefix, slug }, locale }) { let fullSlug = prefix + '/' + slug - if (JSON.parse(BLOG.PSEUDO_STATIC)) { + const from = `slug-props-${fullSlug}` + const props = await getGlobalData({ from, locale }) + + if (siteConfig('PSEUDO_STATIC', BLOG.PSEUDO_STATIC, props.NOTION_CONFIG)) { if (!fullSlug.endsWith('.html')) { fullSlug += '.html' } } - const from = `slug-props-${fullSlug}` - const props = await getGlobalData({ from, locale }) // 在列表内查找文章 props.post = props?.allPages?.find(p => { return ( diff --git a/pages/[prefix]/index.js b/pages/[prefix]/index.js index 408a3cc3..a1eb0088 100644 --- a/pages/[prefix]/index.js +++ b/pages/[prefix]/index.js @@ -81,13 +81,14 @@ export async function getStaticPaths() { export async function getStaticProps({ params: { prefix }, locale }) { let fullSlug = prefix - if (JSON.parse(BLOG.PSEUDO_STATIC)) { + const from = `slug-props-${fullSlug}` + const props = await getGlobalData({ from, locale }) + if (siteConfig('PSEUDO_STATIC', BLOG.PSEUDO_STATIC, props.NOTION_CONFIG)) { if (!fullSlug.endsWith('.html')) { fullSlug += '.html' } } - const from = `slug-props-${fullSlug}` - const props = await getGlobalData({ from, locale }) + // 在列表内查找文章 props.post = props?.allPages?.find(p => { return ( diff --git a/pages/_document.js b/pages/_document.js index 9c8beadb..a61e2b96 100644 --- a/pages/_document.js +++ b/pages/_document.js @@ -1,6 +1,6 @@ // eslint-disable-next-line @next/next/no-document-import-in-page -import Document, { Html, Head, Main, NextScript } from 'next/document' import BLOG from '@/blog.config' +import Document, { Head, Html, Main, NextScript } from 'next/document' class MyDocument extends Document { static async getInitialProps(ctx) { @@ -10,29 +10,52 @@ class MyDocument extends Document { render() { return ( - - - - {/* 预加载字体 */} - {BLOG.FONT_AWESOME && <> - - - } + + + + {/* 预加载字体 */} + {BLOG.FONT_AWESOME && ( + <> + + + + )} - {BLOG.FONT_URL?.map((fontUrl, index) => { - if (fontUrl.endsWith('.css') || fontUrl.includes('googleapis.com/css')) { - return - } else { - return - } - })} - + {BLOG.FONT_URL?.map((fontUrl, index) => { + if ( + fontUrl.endsWith('.css') || + fontUrl.includes('googleapis.com/css') + ) { + return + } else { + return ( + + ) + } + })} + - -
- - - + +
+ + + ) } } diff --git a/themes/starter/components/Footer.js b/themes/starter/components/Footer.js index 46fcee62..7bd6eafd 100644 --- a/themes/starter/components/Footer.js +++ b/themes/starter/components/Footer.js @@ -1,164 +1,187 @@ import { siteConfig } from '@/lib/config' +import { checkContainHttp, sliceUrlFromHttp } from '@/lib/utils' +import SocialButton from '@/themes/fukasawa/components/SocialButton' import CONFIG from '../config' import { Logo } from './Logo' -import SocialButton from '@/themes/fukasawa/components/SocialButton' import { SVGFooterCircleBG } from './svg/SVGFooterCircleBG' -import { checkContainHttp, sliceUrlFromHttp } from '@/lib/utils' /* eslint-disable @next/next/no-img-element */ -export const Footer = (props) => { +export const Footer = props => { const latestPosts = props?.latestPosts ? props?.latestPosts.slice(0, 2) : [] - - return <> - {/* */} - - {/* */} + {/* Footer 背景 */} +
+ + + + + + + + + + + +
+ + {/* */} + ) } diff --git a/themes/starter/components/Team.js b/themes/starter/components/Team.js index 5d24e18e..dab80a43 100644 --- a/themes/starter/components/Team.js +++ b/themes/starter/components/Team.js @@ -2,94 +2,85 @@ import { siteConfig } from '@/lib/config' import CONFIG from '../config' import { SVGAvatarBG } from './svg/SVGAvatarBG' -import { SVGFacebook } from './svg/SVGFacebook' -import { SVGTwitter } from './svg/SVGTwitter' -import { SVGInstagram } from './svg/SVGInstagram' export const Team = () => { - return <> - {/* */} -
-
-
-
-
- - {siteConfig('STARTER_TEAM_TITLE', null, CONFIG)} - -

- {siteConfig('STARTER_TEAM_TEXT_1', null, CONFIG)} -

-

-

+ return ( + <> + {/* */} +
+
+
+
+
+ + {siteConfig('STARTER_TEAM_TITLE', null, CONFIG)} + +

+ {siteConfig('STARTER_TEAM_TEXT_1', null, CONFIG)} +

+

+
-
- {/* 团队成员排列矩阵 */} -
+ {/* 团队成员排列矩阵 */} +
{CONFIG.STARTER_TEAM_ITEMS.map((item, index) => { - return
+ return (
- {/* 头像 */} -
- team image - - - - -
+ key={index} + className='w-full px-4 sm:w-1/2 lg:w-1/4 xl:w-1/4'> +
+ {/* 头像 */} +
+ team image + + + + +
- {/* 文字介绍 */} -
+ {/* 文字介绍 */} +
+

+ {item.STARTER_TEAM_ITEM_NICKNAME} +

-

- {item.STARTER_TEAM_ITEM_NICKNAME} -

+

+ {item.STARTER_TEAM_ITEM_DESCRIPTION} +

-

- {item.STARTER_TEAM_ITEM_DESCRIPTION} -

- - {/* 社交链接 */} -
- - - - - - - - - + {/* 社交链接 */} + {/* */}
-
+ ) })} - +
-
-
- {/* */} +
+ {/* */} + ) } diff --git a/themes/starter/components/Testimonials.js b/themes/starter/components/Testimonials.js index 6fdd98b6..27d1506e 100644 --- a/themes/starter/components/Testimonials.js +++ b/themes/starter/components/Testimonials.js @@ -1,19 +1,25 @@ /* eslint-disable react/no-unescaped-entities */ /* eslint-disable @next/next/no-img-element */ -import { siteConfig } from '@/lib/config'; -import { loadExternalResource } from '@/lib/utils'; -import { useEffect } from 'react'; -import CONFIG from '../config'; -import { SVGLeftArrow } from './svg/SVGLeftArrow'; -import { SVGRightArrow } from './svg/SVGRightArrow'; +import { siteConfig } from '@/lib/config' +import { loadExternalResource } from '@/lib/utils' +import { useEffect } from 'react' +import CONFIG from '../config' +import { SVGLeftArrow } from './svg/SVGLeftArrow' +import { SVGRightArrow } from './svg/SVGRightArrow' /** * 一些外部js */ const loadExternal = async () => { - await loadExternalResource('https://cdnjs.cloudflare.com/ajax/libs/Swiper/11.0.5/swiper-bundle.css', 'css'); - await loadExternalResource('https://cdnjs.cloudflare.com/ajax/libs/Swiper/11.0.5/swiper-bundle.min.js', 'js'); + await loadExternalResource( + 'https://cdnjs.cloudflare.com/ajax/libs/Swiper/11.0.5/swiper-bundle.css', + 'css' + ) + await loadExternalResource( + 'https://cdnjs.cloudflare.com/ajax/libs/Swiper/11.0.5/swiper-bundle.min.js', + 'js' + ) const Swiper = window.Swiper if (!Swiper) { @@ -45,101 +51,109 @@ const loadExternal = async () => { spaceBetween: 30 } } - }); -}; + }) +} export const Testimonials = () => { useEffect(() => { loadExternal() }, []) // 用户评分 - const ratings = [1, 2, 3, 4, 5]; - return <> - {/* */} -
-
-
-
-
- - {siteConfig('STARTER_TESTIMONIALS_TITLE', null, CONFIG)} - -

- {siteConfig('STARTER_TESTIMONIALS_TEXT_1', null, CONFIG)} -

-

- {siteConfig('STARTER_TESTIMONIALS_TEXT_2', null, CONFIG)} -

+ const ratings = [1, 2, 3, 4, 5] + const STARTER_TESTIMONIALS_ITEMS = siteConfig( + 'STARTER_TESTIMONIALS_ITEMS', + [], + CONFIG + ) + return ( + <> + {/* */} +
+
+
+
+
+ + {siteConfig('STARTER_TESTIMONIALS_TITLE', null, CONFIG)} + +

+ {siteConfig('STARTER_TESTIMONIALS_TEXT_1', null, CONFIG)} +

+

+ {siteConfig('STARTER_TESTIMONIALS_TEXT_2', null, CONFIG)} +

+
-
-
-
-
- - {/* 用户评价卡牌 */} - {CONFIG.STARTER_TESTIMONIALS_ITEMS.map((item, index) => { - return
-
-
- {ratings.map((rating, index) => ( - star icon - ))} +
+
+
+ {/* 用户评价卡牌 */} + {STARTER_TESTIMONIALS_ITEMS.map((item, index) => { + return ( + + ) + })} +
+ + {/* 切换按钮 */} +
+
+ +
+
+
- })} - -
- - {/* 切换按钮 */} -
-
- -
-
-
-
-
-
- {/* */} +
+ {/* */} + ) } diff --git a/themes/starter/index.js b/themes/starter/index.js index 7b7275ed..195b7d0f 100644 --- a/themes/starter/index.js +++ b/themes/starter/index.js @@ -9,34 +9,35 @@ * 2. 内容大部分是在此文件中写死,notion数据从props参数中传进来 * 3. 您可在此网站找到更多喜欢的组件 https://www.tailwind-kit.com/ */ -import { useRouter } from 'next/router' -import { isBrowser } from '@/lib/utils' -import { siteConfig } from '@/lib/config' -import CONFIG from './config' -import NotionPage from '@/components/NotionPage' import Loading from '@/components/Loading' +import NotionPage from '@/components/NotionPage' +import { siteConfig } from '@/lib/config' +import { isBrowser } from '@/lib/utils' +import { useRouter } from 'next/router' import { useEffect } from 'react' -import { Style } from './style' -import { NavBar } from './components/NavBar' -import { Hero } from './components/Hero' -import { Features } from './components/Features' import { About } from './components/About' -import { Pricing } from './components/Pricing' -import { Testimonials } from './components/Testimonials' -import { FAQ } from './components/FAQ' -import { Team } from './components/Team' -import { Blog } from './components/Blog' -import { Contact } from './components/Contact' -import { Brand } from './components/Brand' -import { Footer } from './components/Footer' import { BackToTopButton } from './components/BackToTopButton' +import { Blog } from './components/Blog' +import { Brand } from './components/Brand' +import { Contact } from './components/Contact' +import { FAQ } from './components/FAQ' +import { Features } from './components/Features' +import { Footer } from './components/Footer' +import { Hero } from './components/Hero' +import { NavBar } from './components/NavBar' +import { Pricing } from './components/Pricing' +import { Team } from './components/Team' +import { Testimonials } from './components/Testimonials' +import CONFIG from './config' +import { Style } from './style' // import { MadeWithButton } from './components/MadeWithButton' -import { SVG404 } from './components/svg/SVG404' +import BLOG from '@/blog.config' +import { loadWowJS } from '@/lib/plugins/wow' +import Link from 'next/link' import { Banner } from './components/Banner' import { SignInForm } from './components/SignInForm' import { SignUpForm } from './components/SignUpForm' -import Link from 'next/link' -import { loadWowJS } from '@/lib/plugins/wow' +import { SVG404 } from './components/svg/SVG404' /** * 布局框架 @@ -46,7 +47,7 @@ import { loadWowJS } from '@/lib/plugins/wow' * @param {*} props * @returns */ -const LayoutBase = (props) => { +const LayoutBase = props => { const { children } = props // 加载wow动画 @@ -54,18 +55,22 @@ const LayoutBase = (props) => { loadWowJS() }, []) - return
-