diff --git a/blog.config.js b/blog.config.js index 216d925c..32e80f10 100644 --- a/blog.config.js +++ b/blog.config.js @@ -5,7 +5,7 @@ const BLOG = { process.env.NOTION_PAGE_ID || '02ab3b8678004aa69e9e415905ef32a5', PSEUDO_STATIC: process.env.NEXT_PUBLIC_PSEUDO_STATIC || false, // 伪静态路径,开启后所有文章URL都以 .html 结尾。 NEXT_REVALIDATE_SECOND: process.env.NEXT_PUBLIC_REVALIDATE_SECOND || 5, // 更新内容缓存间隔 单位(秒);即每个页面有5秒的纯静态期、此期间无论多少次访问都不会抓取notion数据;调大该值有助于节省Vercel资源、同时提升访问速率,但也会使文章更新有延迟。 - THEME: process.env.NEXT_PUBLIC_THEME || 'hexo', // 主题, 支持 ['next','hexo',"fukasawa','medium','example','matery','gitbook','simple'] @see https://preview.tangly1024.com + THEME: process.env.NEXT_PUBLIC_THEME || 'hexo', // 当前主题,在themes文件夹下可找到所有支持的主题;主题名称就是文件夹名,例如 example,fukasawa,gitbook,heo,hexo,landing,matery,medium,next,nobelium,plog,simple THEME_SWITCH: process.env.NEXT_PUBLIC_THEME_SWITCH || false, // 是否显示切换主题按钮 LANG: process.env.NEXT_PUBLIC_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. diff --git a/lib/utils.js b/lib/utils.js index 5f5d864d..c3bd155c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -124,24 +124,32 @@ export function isIterable(obj) { return obj != null && typeof obj[Symbol.iterator] === 'function' } +/** + * 深拷贝对象 + * 根据源对象类型深度复制,支持object和array + * @param {*} obj + * @returns + */ export function deepClone(obj) { - const newObj = Array.isArray(obj) ? [] : {} - if (obj && typeof obj === 'object') { + if (Array.isArray(obj)) { + // If obj is an array, create a new array and deep clone each element + return obj.map(item => deepClone(item)) + } else if (obj && typeof obj === 'object') { + const newObj = {} for (const key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { - if (obj[key] instanceof Date) { // 判断属性值是否为 Date 对象 - newObj[key] = new Date(obj[key].getTime()).toISOString() // 直接拷贝引用 - } else if (obj[key] && typeof obj[key] === 'object') { - newObj[key] = deepClone(obj[key]) + if (obj[key] instanceof Date) { + newObj[key] = new Date(obj[key].getTime()).toISOString() } else { - newObj[key] = obj[key] + newObj[key] = deepClone(obj[key]) } } } + return newObj + } else { + return obj } - return newObj } - /** * 延时 * @param {*} ms diff --git a/themes/gitbook/components/BlogArchiveItem.js b/themes/gitbook/components/BlogArchiveItem.js new file mode 100644 index 00000000..8e9693dc --- /dev/null +++ b/themes/gitbook/components/BlogArchiveItem.js @@ -0,0 +1,36 @@ +import BLOG from '@/blog.config' +import Link from 'next/link' + +/** + * 归档分组 + * @param {*} param0 + * @returns + */ +export default function BlogArchiveItem({ archiveTitle, archivePosts }) { + return ( +