+
+ {/* 模态框 */}
-
handleSearch(e.target.value)}
- className="bg-gray-50 dark:bg-gray-600 outline-blue-500 w-full px-4 my-2 py-1 mb-4 border rounded-md" />
+
handleInputChange(e)}
+ className="text-black dark:text-gray-200 bg-gray-50 dark:bg-gray-600 outline-blue-500 w-full px-4 my-2 py-1 mb-4 border rounded-md" />
{/* 标签组 */}
-
-
+
+
-
Algolia 提供搜索服务
+
+ {totalHit > 0 &&
共搜索到 {totalHit} 条结果,用时 {useTime} 毫秒
}
+ Algolia 提供搜索服务
{/* 遮罩 */}
@@ -90,3 +141,59 @@ export default function AlgoliaSearchModal({ cRef }) {
)
}
+
+/**
+ * 标签组
+ */
+function TagGroups(props) {
+ const { tagOptions } = useGlobal()
+ // 获取tagOptions数组前十个
+ const firstTenTags = tagOptions?.slice(0, 10)
+
+ return
+}
+
+/**
+ * 分页
+ * @param {*} param0
+ */
+function Pagination(props) {
+ const { totalPage, page, switchPage } = props
+ if (totalPage <= 0) {
+ return <>>
+ }
+ const pagesElement = []
+
+ for (let i = 0; i < totalPage; i++) {
+ const selected = page === i
+ pagesElement.push(getPageElement(i, selected, switchPage))
+ }
+ return
+ {pagesElement.map(p => p)}
+
+}
+
+/**
+ * 获取分页按钮
+ * @param {*} i
+ * @param {*} selected
+ */
+function getPageElement(i, selected, switchPage) {
+ return
switchPage(i)} className={`${selected ? 'font-bold text-white bg-blue-600 rounded' : 'hover:text-blue-600 hover:font-bold'} text-center cursor-pointer w-6 h-6 `}>
+ {i + 1}
+
+}
diff --git a/components/CommonHead.js b/components/CommonHead.js
index 32b71fad..24bfae69 100644
--- a/components/CommonHead.js
+++ b/components/CommonHead.js
@@ -58,7 +58,7 @@ const CommonHead = ({ meta, children }) => {
<>
diff --git a/components/DebugPanel.js b/components/DebugPanel.js
index 053962b3..026b5ee0 100644
--- a/components/DebugPanel.js
+++ b/components/DebugPanel.js
@@ -32,7 +32,6 @@ const DebugPanel = () => {
}
function handleUpdateDebugTheme(newTheme) {
- console.log('切换主题', newTheme)
const query = { ...router.query, theme: newTheme }
router.push({ pathname: router.pathname, query })
}
diff --git a/components/Gitalk.js b/components/Gitalk.js
index 166eb8c7..4df0c65d 100644
--- a/components/Gitalk.js
+++ b/components/Gitalk.js
@@ -16,10 +16,8 @@ const Gitalk = ({ frontMatter }) => {
// distractionFreeMode: JSON.parse(BLOG.COMMENT_GITALK_DISTRACTION_FREE_MODE)
// }} />
const loadGitalk = async() => {
- const css = await loadExternalResource(BLOG.COMMENT_GITALK_CSS_CDN_URL, 'css')
- const js = await loadExternalResource(BLOG.COMMENT_GITALK_JS_CDN_URL, 'js')
-
- console.log('gitalk 加载成功', css, js)
+ await loadExternalResource(BLOG.COMMENT_GITALK_CSS_CDN_URL, 'css')
+ await loadExternalResource(BLOG.COMMENT_GITALK_JS_CDN_URL, 'js')
const Gitalk = window.Gitalk
const gitalk = new Gitalk({
diff --git a/components/GoogleAdsense.js b/components/GoogleAdsense.js
index 9cdaa406..22fca879 100644
--- a/components/GoogleAdsense.js
+++ b/components/GoogleAdsense.js
@@ -17,7 +17,6 @@ export default function GoogleAdsense() {
setTimeout(() => {
const ads = document.getElementsByClassName('adsbygoogle')
const adsbygoogle = window.adsbygoogle
- console.log('google-ads', adsbygoogle)
if (ads.length > 0) {
for (let i = 0; i <= ads.length; i++) {
try {
diff --git a/components/Mark.js b/components/Mark.js
index 1defca32..ec2a7901 100644
--- a/components/Mark.js
+++ b/components/Mark.js
@@ -9,10 +9,7 @@ export default async function replaceSearchResult({ doms, search, target }) {
}
try {
- const url = await loadExternalResource('https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js', 'js')
- console.log('markjs 加载成功', url, window.Mark)
- console.log('------', doms)
-
+ await loadExternalResource('https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js', 'js')
const Mark = window.Mark
if (doms instanceof HTMLCollection) {
for (const container of doms) {
diff --git a/components/PrismMac.js b/components/PrismMac.js
index b37ba503..172c6ceb 100644
--- a/components/PrismMac.js
+++ b/components/PrismMac.js
@@ -140,8 +140,8 @@ const renderMermaid = async() => {
}
if (needLoad) {
loadExternalResource(BLOG.MERMAID_CDN, 'js').then(url => {
- // console.log('mermaid加载成功', url, mermaid)
const mermaid = window.mermaid
+ console.log('mermaid加载成功', url, mermaid)
mermaid.contentLoaded()
})
}
@@ -216,7 +216,6 @@ const fixCodeLineStyle = () => {
setTimeout(() => {
const preCodes = document.querySelectorAll('pre.notion-code')
for (const preCode of preCodes) {
- // console.log('code', preCode)
Prism.plugins.lineNumbers.resize(preCode)
}
}, 10)
diff --git a/components/TwikooCommentCounter.js b/components/TwikooCommentCounter.js
index b3b54ca3..87c16aaf 100644
--- a/components/TwikooCommentCounter.js
+++ b/components/TwikooCommentCounter.js
@@ -27,7 +27,6 @@ const TwikooCommentCounter = (props) => {
urls: posts?.map(post => post.slug), // 不包含协议、域名、参数的文章路径列表,必传参数
includeReply: true // 评论数是否包括回复,默认:false
}).then(function (res) {
- // console.log('查询', res)
commentsData = res
updateCommentCount()
}).catch(function (err) {
diff --git a/components/ValineComponent.js b/components/ValineComponent.js
index 359cff6d..3a7464b3 100644
--- a/components/ValineComponent.js
+++ b/components/ValineComponent.js
@@ -5,8 +5,8 @@ import { useEffect } from 'react'
const ValineComponent = ({ path }) => {
const loadValine = async () => {
try {
- const url = await loadExternalResource(BLOG.COMMENT_VALINE_CDN, 'js')
- console.log('valine 加载成功', url)
+ await loadExternalResource(BLOG.COMMENT_VALINE_CDN, 'js')
+ // console.log('valine 加载成功', url)
const Valine = window.Valine
// eslint-disable-next-line no-unused-vars
const valine = new Valine({
@@ -21,7 +21,6 @@ const ValineComponent = ({ path }) => {
serverURLs: BLOG.COMMENT_VALINE_SERVER_URLS,
visitor: true
})
- console.log('初始化valine成功')
} catch (error) {
console.error('twikoo 加载失败', error)
}
diff --git a/lib/algolia.js b/lib/algolia.js
index b7439438..d2d9cb37 100644
--- a/lib/algolia.js
+++ b/lib/algolia.js
@@ -17,26 +17,88 @@ const generateAlgoliaSearch = async({ allPages, force = false }) => {
/**
* 上传数据
+ * 根据上次修改文章日期和上次更新索引数据判断是否需要更新algolia索引
*/
-const uploadDataToAlgolia = (post) => {
+const uploadDataToAlgolia = async(post) => {
// Connect and authenticate with your Algolia app
const client = algoliasearch(BLOG.ALGOLIA_APP_ID, BLOG.ALGOLIA_ADMIN_APP_KEY)
// Create a new index and add a record
const index = client.initIndex(BLOG.ALGOLIA_INDEX)
- const record = {
- objectID: post.id,
- title: post.title,
- category: post.category,
- tags: post.tags,
- pageCover: post.pageCover,
- slug: post.slug,
- summary: post.summary,
- content: getPageContentText(post, post.blockMap)
+
+ if (!post) {
+ return
}
- index.saveObject(record).wait().then(r => {
- console.log('Algolia索引', r, record)
- })
+
+ // 检查是否有索引
+ let existed
+ let needUpdateIndex = false
+ try {
+ existed = await index.getObject(post.id)
+ } catch (error) {
+ // 通常是不存在索引
+ }
+
+ if (!existed || !existed?.lastEditedDate || !existed?.lastIndexDate) {
+ needUpdateIndex = true
+ } else {
+ const lastEditedDate = new Date(existed.lastEditedDate)
+ const lastIndexDate = new Date(existed.lastIndexDate)
+ if (lastEditedDate.getTime() > lastIndexDate.getTime()) {
+ needUpdateIndex = true
+ }
+ }
+
+ // 如果需要更新搜索
+ if (needUpdateIndex) {
+ const record = {
+ objectID: post.id,
+ title: post.title,
+ category: post.category,
+ tags: post.tags,
+ pageCover: post.pageCover,
+ slug: post.slug,
+ summary: post.summary,
+ lastEditedDate: post.lastEditedDate, // 更新文章时间
+ lastIndexDate: new Date(), // 更新索引时间
+ content: truncate(getPageContentText(post, post.blockMap), 9000) // 索引9000个字节,因为api限制总请求内容上限1万个字节
+ }
+ // console.log('更新Algolia索引', record)
+ index.saveObject(record).wait().then(r => {
+ console.log('Algolia索引更新', r)
+ }).catch(err => {
+ console.log('Algolia异常', err)
+ })
+ }
+}
+
+/**
+ * 限制内容字节数
+ * @param {*} str
+ * @param {*} maxBytes
+ * @returns
+ */
+function truncate(str, maxBytes) {
+ let count = 0
+ let result = ''
+ for (let i = 0; i < str.length; i++) {
+ const code = str.charCodeAt(i)
+ if (code <= 0x7f) {
+ count += 1
+ } else if (code <= 0x7ff) {
+ count += 2
+ } else if (code <= 0xffff) {
+ count += 3
+ } else {
+ count += 4
+ }
+ if (count <= maxBytes) {
+ result += str[i]
+ } else {
+ break
+ }
+ }
+ return result
}
export { uploadDataToAlgolia, generateAlgoliaSearch }
diff --git a/lib/global.js b/lib/global.js
index 9cafd304..04d0176e 100644
--- a/lib/global.js
+++ b/lib/global.js
@@ -14,7 +14,8 @@ const GlobalContext = createContext()
* @returns {JSX.Element}
* @constructor
*/
-export function GlobalContextProvider({ children }) {
+export function GlobalContextProvider(props) {
+ const { children, siteInfo, categoryOptions, tagOptions } = props
const router = useRouter()
const [lang, updateLang] = useState(BLOG.LANG) // 默认语言
const [locale, updateLocale] = useState(generateLocaleDict(BLOG.LANG)) // 默认语言
@@ -24,7 +25,7 @@ export function GlobalContextProvider({ children }) {
useEffect(() => {
initLocale(lang, locale, updateLang, updateLocale)
- initDarkMode(isDarkMode, updateDarkMode)
+ initDarkMode(updateDarkMode)
initTheme()
}, [])
@@ -75,7 +76,10 @@ export function GlobalContextProvider({ children }) {
updateDarkMode,
theme,
setTheme,
- switchTheme
+ switchTheme,
+ siteInfo,
+ categoryOptions,
+ tagOptions
}}>
{children}
diff --git a/lib/notion/getAllCategories.js b/lib/notion/getAllCategories.js
index 7cfd4588..97c8ab3a 100644
--- a/lib/notion/getAllCategories.js
+++ b/lib/notion/getAllCategories.js
@@ -14,7 +14,7 @@ import { isIterable } from '../utils'
* @returns {Promise<{}|*[]>}
*/
export function getAllCategories({ allPages, categoryOptions, sliceCount = 0 }) {
- const allPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
+ const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
if (!allPosts || !categoryOptions) {
return []
}
diff --git a/lib/notion/getAllPageIds.js b/lib/notion/getAllPageIds.js
index e8f6dd8f..4bb12fe0 100644
--- a/lib/notion/getAllPageIds.js
+++ b/lib/notion/getAllPageIds.js
@@ -4,7 +4,15 @@ export default function getAllPageIds (collectionQuery, collectionId, collection
return []
}
let pageIds = []
- if (collectionQuery && Object.values(collectionQuery).length > 0) {
+ // 优先按照第一个视图排序
+ if (viewIds && viewIds.length > 0) {
+ const ids = collectionView[viewIds[0]].value.page_sort
+ // console.log('PageIds: 从viewId获取', viewIds)
+ for (const id of ids) {
+ pageIds.push(id)
+ }
+ // 否则按照数据库原始排序
+ } else if (collectionQuery && Object.values(collectionQuery).length > 0) {
const pageSet = new Set()
Object.values(collectionQuery[collectionId]).forEach(view => {
view?.blockIds?.forEach(id => pageSet.add(id)) // group视图
@@ -12,12 +20,6 @@ export default function getAllPageIds (collectionQuery, collectionId, collection
})
pageIds = [...pageSet]
// console.log('PageIds: 从collectionQuery获取', collectionQuery, pageIds.length)
- } else if (viewIds && viewIds.length > 0) {
- const ids = collectionView[viewIds[0]].value.page_sort
- // console.log('PageIds: 从viewId获取', viewIds)
- for (const id of ids) {
- pageIds.push(id)
- }
}
return pageIds
}
diff --git a/lib/notion/getAllTags.js b/lib/notion/getAllTags.js
index 968b8ca3..dfc92ac7 100644
--- a/lib/notion/getAllTags.js
+++ b/lib/notion/getAllTags.js
@@ -8,7 +8,7 @@ import { isIterable } from '../utils'
* @returns {Promise<{}|*[]>}
*/
export function getAllTags({ allPages, sliceCount = 0, tagOptions }) {
- const allPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
+ const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
if (!allPosts || !tagOptions) {
return []
diff --git a/lib/notion/getNotion.js b/lib/notion/getNotion.js
index f73100c2..3da84ee8 100644
--- a/lib/notion/getNotion.js
+++ b/lib/notion/getNotion.js
@@ -25,7 +25,7 @@ export async function getNotion(pageId) {
title: postInfo?.properties?.title?.[0],
status: 'Published',
createdTime: formatDate(new Date(postInfo.created_time).toString(), BLOG.LANG),
- lastEditedTime: formatDate(new Date(postInfo?.last_edited_time).toString(), BLOG.LANG),
+ lastEditedDay: formatDate(new Date(postInfo?.last_edited_time).toString(), BLOG.LANG),
fullWidth: false,
page_cover: getPageCover(postInfo),
date: { start_date: formatDate(new Date(postInfo?.last_edited_time).toString(), BLOG.LANG) },
diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js
index 393e3c63..20f47be3 100644
--- a/lib/notion/getNotionData.js
+++ b/lib/notion/getNotionData.js
@@ -25,7 +25,8 @@ export async function getGlobalData({
from
}) {
// 从notion获取
- const db = deepClone(await getNotionPageData({ pageId, from }))
+ const data = await getNotionPageData({ pageId, from })
+ const db = deepClone(data)
// 不返回的敏感数据
delete db.block
delete db.schema
@@ -48,8 +49,8 @@ function getLatestPosts({ allPages, from, latestPostCount }) {
const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
const latestPosts = Object.create(allPosts).sort((a, b) => {
- const dateA = new Date(a?.lastEditedTime || a?.publishDate)
- const dateB = new Date(b?.lastEditedTime || b?.publishDate)
+ const dateA = new Date(a?.lastEditedDay || a?.publishDate)
+ const dateB = new Date(b?.lastEditedDay || b?.publishDate)
return dateB - dateA
})
return latestPosts.slice(0, latestPostCount)
@@ -173,31 +174,17 @@ function getSiteInfo({ collection, block }) {
}
/**
- * 获取导航pages
- * 转为gitbook这类文档主题设计,精减的标题和内容
+ * 获取导航用的精减文章列表
+ * gitbook主题用到,只保留文章的标题分类标签分类信息,精减掉摘要密码日期等数据
* 导航页面的条件,必须是Posts
* @param {*} param0
*/
export function getNavPages({ allPages }) {
- const allNavPages = allPages.filter(post => {
+ const allNavPages = allPages?.filter(post => {
return post && post?.slug && (!post?.slug?.startsWith('http')) && post?.type === 'Post' && post?.status === 'Published'
})
- const result = allNavPages.map(item => ({ id: item.id, title: item.title || '', category: item.category || null, tags: item.tags || null, summary: item.summary || null, slug: item.slug }))
- const groupedArray = result.reduce((groups, item) => {
- const categoryName = item?.category ? item?.category : '' // 将category转换为字符串
- const lastGroup = groups[groups.length - 1] // 获取最后一个分组
-
- if (!lastGroup || lastGroup?.category !== categoryName) { // 如果当前元素的category与上一个元素不同,则创建新分组
- groups.push({ category: categoryName, items: [] })
- }
-
- groups[groups.length - 1].items.push(item) // 将元素加入对应的分组
-
- return groups
- }, [])
-
- return groupedArray
+ return allNavPages.map(item => ({ id: item.id, title: item.title || '', pageCoverThumbnail: item.pageCoverThumbnail || '', category: item.category || null, tags: item.tags || null, summary: item.summary || null, slug: item.slug, lastEditedDate: item.lastEditedDate }))
}
/**
@@ -217,7 +204,7 @@ const EmptyData = (pageId) => {
const empty = {
notice: null,
siteInfo: getSiteInfo({}),
- allPages: [{ id: 1, title: `无法获取Notion数据,请检查Notion_ID: \n 当前 ${pageId}`, summary: '访问文档获取帮助→ https://tangly1024.com/article/vercel-deploy-notion-next', status: 'Published', type: 'Post', slug: '13a171332816461db29d50e9f575b00d', date: { start_date: '2023-04-24', lastEditedTime: '2023-04-24', tagItems: [] } }],
+ allPages: [{ id: 1, title: `无法获取Notion数据,请检查Notion_ID: \n 当前 ${pageId}`, summary: '访问文档获取帮助→ https://tangly1024.com/article/vercel-deploy-notion-next', status: 'Published', type: 'Post', slug: '13a171332816461db29d50e9f575b00d', date: { start_date: '2023-04-24', lastEditedDay: '2023-04-24', tagItems: [] } }],
allNavPages: [],
collection: [],
collectionQuery: {},
diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js
index dea5c2b1..b9bdbe4d 100644
--- a/lib/notion/getPageProperties.js
+++ b/lib/notion/getPageProperties.js
@@ -78,8 +78,9 @@ export default async function getPageProperties(id, block, schema, authToken, ta
mapProperties(properties)
properties.publishDate = new Date(properties?.date?.start_date || value.created_time).getTime()
- properties.publishTime = formatDate(properties.publishDate, BLOG.LANG)
- properties.lastEditedTime = formatDate(new Date(value?.last_edited_time), BLOG.LANG)
+ properties.publishDay = formatDate(properties.publishDate, BLOG.LANG)
+ properties.lastEditedDate = new Date(value?.last_edited_time)
+ properties.lastEditedDay = formatDate(new Date(value?.last_edited_time), BLOG.LANG)
properties.fullWidth = value.format?.page_full_width ?? false
properties.pageIcon = mapImgUrl(block[id].value?.format?.page_icon, block[id].value) ?? ''
properties.pageCover = mapImgUrl(block[id].value?.format?.page_cover, block[id].value) ?? ''
@@ -141,14 +142,14 @@ function generateCustomizeUrl(postProperties) {
let fullPrefix = ''
const allSlugPatterns = BLOG.POST_URL_PREFIX.split('/')
allSlugPatterns.forEach((pattern, idx) => {
- if (pattern === '%year%' && postProperties?.publishTime) {
- const formatPostCreatedDate = new Date(postProperties?.publishTime)
+ if (pattern === '%year%' && postProperties?.publishDay) {
+ const formatPostCreatedDate = new Date(postProperties?.publishDay)
fullPrefix += formatPostCreatedDate.getUTCFullYear()
- } else if (pattern === '%month%' && postProperties?.publishTime) {
- const formatPostCreatedDate = new Date(postProperties?.publishTime)
+ } else if (pattern === '%month%' && postProperties?.publishDay) {
+ const formatPostCreatedDate = new Date(postProperties?.publishDay)
fullPrefix += String(formatPostCreatedDate.getUTCMonth() + 1).padStart(2, 0)
- } else if (pattern === '%day%' && postProperties?.publishTime) {
- const formatPostCreatedDate = new Date(postProperties?.publishTime)
+ } else if (pattern === '%day%' && postProperties?.publishDay) {
+ const formatPostCreatedDate = new Date(postProperties?.publishDay)
fullPrefix += String(formatPostCreatedDate.getUTCDate()).padStart(2, 0)
} else if (pattern === '%slug%') {
fullPrefix += (postProperties.slug ?? postProperties.id)
diff --git a/lib/rss.js b/lib/rss.js
index d40b940b..fff81f7c 100644
--- a/lib/rss.js
+++ b/lib/rss.js
@@ -46,7 +46,7 @@ export async function generateRss(posts) {
link: `${BLOG.LINK}/${post.slug}`,
description: post.summary,
content: await createFeedContent(post),
- date: new Date(post?.publishTime)
+ date: new Date(post?.publishDay)
})
}
diff --git a/lib/sitemap.xml.js b/lib/sitemap.xml.js
index 6c8bd040..c520c0ff 100644
--- a/lib/sitemap.xml.js
+++ b/lib/sitemap.xml.js
@@ -26,7 +26,7 @@ export async function generateSitemapXml({ allPages }) {
const slugWithoutLeadingSlash = post?.slug?.startsWith('/') ? post?.slug?.slice(1) : post.slug
urls.push({
loc: `${BLOG.LINK}/${slugWithoutLeadingSlash}`,
- lastmod: new Date(post?.publishTime).toISOString().split('T')[0],
+ lastmod: new Date(post?.publishDay).toISOString().split('T')[0],
changefreq: 'daily'
})
})
diff --git a/lib/utils.js b/lib/utils.js
index d5ba09b5..e13b192f 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -117,7 +117,13 @@ export function deepClone(obj) {
if (obj && typeof obj === 'object') {
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
- newObj[key] = (obj && typeof obj[key] === 'object') ? deepClone(obj[key]) : 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])
+ } else {
+ newObj[key] = obj[key]
+ }
}
}
}
diff --git a/package.json b/package.json
index b9f1bb5c..c1baace5 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "notion-next",
- "version": "4.0.6",
+ "version": "4.0.8",
"homepage": "https://github.com/tangly1024/NotionNext.git",
"license": "MIT",
"repository": {
diff --git a/pages/[prefix]/[slug].js b/pages/[prefix]/[slug].js
index cf249228..2beae09c 100644
--- a/pages/[prefix]/[slug].js
+++ b/pages/[prefix]/[slug].js
@@ -4,6 +4,7 @@ import { getGlobalData } from '@/lib/notion/getNotionData'
import { idToUuid } from 'notion-utils'
import { getNotion } from '@/lib/notion/getNotion'
import Slug, { getRecommendPost } from '.'
+import { uploadDataToAlgolia } from '@/lib/algolia'
/**
* 根据notion的slug访问页面
@@ -25,7 +26,7 @@ export async function getStaticPaths() {
const from = 'slug-paths'
const { allPages } = await getGlobalData({ from })
return {
- paths: allPages?.filter(row => row.slug.indexOf('/') > 0).map(row => ({ params: { prefix: row.slug.split('/')[0], slug: row.slug.split('/')[1] } })),
+ paths: allPages?.filter(row => row.slug.indexOf('/') > 0 && row.type.indexOf('Menu') < 0).map(row => ({ params: { prefix: row.slug.split('/')[0], slug: row.slug.split('/')[1] } })),
fallback: true
}
}
@@ -63,9 +64,13 @@ export async function getStaticProps({ params: { prefix, slug } }) {
if (!props?.posts?.blockMap) {
props.post.blockMap = await getPostBlocks(props.post.id, from)
}
+ // 生成全文索引 && JSON.parse(BLOG.ALGOLIA_RECREATE_DATA)
+ if (BLOG.ALGOLIA_APP_ID) {
+ uploadDataToAlgolia(props?.post)
+ }
// 推荐关联文章处理
- const allPosts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
+ const allPosts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
if (allPosts && allPosts.length > 0) {
const index = allPosts.indexOf(props.post)
props.prev = allPosts.slice(index - 1, index)[0] ?? allPosts.slice(-1)[0]
diff --git a/pages/[prefix]/index.js b/pages/[prefix]/index.js
index 8c10b063..5f6ac5c8 100644
--- a/pages/[prefix]/index.js
+++ b/pages/[prefix]/index.js
@@ -90,7 +90,7 @@ export async function getStaticPaths() {
const from = 'slug-paths'
const { allPages } = await getGlobalData({ from })
return {
- paths: allPages?.filter(row => row.slug.indexOf('/') < 0).map(row => ({ params: { prefix: row.slug } })),
+ paths: allPages?.filter(row => row.slug.indexOf('/') < 0 && row.type.indexOf('Menu') < 0).map(row => ({ params: { prefix: row.slug } })),
fallback: true
}
}
@@ -129,12 +129,13 @@ export async function getStaticProps({ params: { prefix } }) {
props.post.blockMap = await getPostBlocks(props.post.id, from)
}
- if (BLOG.ALGOLIA_APP_ID && BLOG.ALGOLIA_APP_KEY) {
+ // 生成全文索引 && process.env.npm_lifecycle_event === 'build' && JSON.parse(BLOG.ALGOLIA_RECREATE_DATA)
+ if (BLOG.ALGOLIA_APP_ID) {
uploadDataToAlgolia(props?.post)
}
// 推荐关联文章处理
- const allPosts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
+ const allPosts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
if (allPosts && allPosts.length > 0) {
const index = allPosts.indexOf(props.post)
props.prev = allPosts.slice(index - 1, index)[0] ?? allPosts.slice(-1)[0]
diff --git a/pages/_app.js b/pages/_app.js
index a6a11399..ed0c8f76 100644
--- a/pages/_app.js
+++ b/pages/_app.js
@@ -17,7 +17,6 @@ import dynamic from 'next/dynamic'
// 自定义样式css和js引入
import ExternalScript from '@/components/ExternalScript'
-
// 各种扩展插件 动画等
const ExternalPlugins = dynamic(() => import('@/components/ExternalPlugins'))
@@ -27,7 +26,7 @@ const MyApp = ({ Component, pageProps }) => {
}, [])
return (
-
+
diff --git a/pages/archive/index.js b/pages/archive/index.js
index 917fee76..1ef1f216 100644
--- a/pages/archive/index.js
+++ b/pages/archive/index.js
@@ -44,7 +44,7 @@ const ArchiveIndex = props => {
export async function getStaticProps() {
const props = await getGlobalData({ from: 'archive-index' })
// 处理分页
- props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
+ props.posts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
delete props.allPages
const postsSortByDate = Object.create(props.posts)
diff --git a/pages/category/[category]/index.js b/pages/category/[category]/index.js
index 55300733..03cd4fbd 100644
--- a/pages/category/[category]/index.js
+++ b/pages/category/[category]/index.js
@@ -37,7 +37,7 @@ export async function getStaticProps({ params: { category } }) {
let props = await getGlobalData({ from })
// 过滤状态
- props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
+ props.posts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
// 处理过滤
props.posts = props.posts.filter(post => post && post.category && post.category.includes(category))
// 处理文章页数
diff --git a/pages/category/[category]/page/[page].js b/pages/category/[category]/page/[page].js
index 2f860c25..9174e117 100644
--- a/pages/category/[category]/page/[page].js
+++ b/pages/category/[category]/page/[page].js
@@ -37,7 +37,7 @@ export async function getStaticProps({ params: { category, page } }) {
let props = await getGlobalData({ from })
// 过滤状态类型
- props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.category && post.category.includes(category))
+ props.posts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.category && post.category.includes(category))
// 处理文章页数
props.postCount = props.posts.length
// 处理分页
@@ -61,7 +61,7 @@ export async function getStaticPaths() {
categoryOptions?.forEach(category => {
// 过滤状态类型
- const categoryPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.category && post.category.includes(category.name))
+ const categoryPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.category && post.category.includes(category.name))
// 处理文章页数
const postCount = categoryPosts.length
const totalPages = Math.ceil(postCount / BLOG.POSTS_PER_PAGE)
diff --git a/pages/index.js b/pages/index.js
index 404fab19..328ece1e 100644
--- a/pages/index.js
+++ b/pages/index.js
@@ -3,17 +3,14 @@ import { getPostBlocks } from '@/lib/notion'
import { getGlobalData } from '@/lib/notion/getNotionData'
import { generateRss } from '@/lib/rss'
import { generateRobotsTxt } from '@/lib/robots.txt'
-
import { useRouter } from 'next/router'
import { getLayoutByTheme } from '@/themes/theme'
-import { generateAlgoliaSearch } from '@/lib/algolia'
/**
* 首页布局
* @param {*} props
* @returns
*/
-
const Index = props => {
// 根据页面路径加载不同Layout文件
const Layout = getLayoutByTheme(useRouter())
@@ -29,7 +26,7 @@ export async function getStaticProps() {
const props = await getGlobalData({ from })
const { siteInfo } = props
- props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
+ props.posts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
const meta = {
title: `${siteInfo?.title} | ${siteInfo?.description}`,
@@ -64,9 +61,6 @@ export async function getStaticProps() {
}
// 生成全文索引 - 仅在 yarn build 时执行 && process.env.npm_lifecycle_event === 'build'
- if (BLOG.ALGOLIA_APP_ID && JSON.parse(BLOG.ALGOLIA_RECREATE_DATA)) {
- generateAlgoliaSearch({ allPages: props.allPages })
- }
delete props.allPages
diff --git a/pages/page/[page].js b/pages/page/[page].js
index 74b7f25b..02b847a8 100644
--- a/pages/page/[page].js
+++ b/pages/page/[page].js
@@ -45,7 +45,7 @@ export async function getStaticProps({ params: { page } }) {
const from = `page-${page}`
const props = await getGlobalData({ from })
const { allPages } = props
- const allPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
+ const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
// 处理分页
props.posts = allPosts.slice(BLOG.POSTS_PER_PAGE * (page - 1), BLOG.POSTS_PER_PAGE * page)
props.page = page
diff --git a/pages/search/[keyword]/index.js b/pages/search/[keyword]/index.js
index 93fa6826..042bbf85 100644
--- a/pages/search/[keyword]/index.js
+++ b/pages/search/[keyword]/index.js
@@ -36,7 +36,7 @@ export async function getStaticProps({ params: { keyword } }) {
pageType: ['Post']
})
const { allPages } = props
- const allPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
+ const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
props.posts = await filterByMemCache(allPosts, keyword)
props.postCount = props.posts.length
// 处理分页
diff --git a/pages/search/[keyword]/page/[page].js b/pages/search/[keyword]/page/[page].js
index 11a682f7..20240f19 100644
--- a/pages/search/[keyword]/page/[page].js
+++ b/pages/search/[keyword]/page/[page].js
@@ -36,7 +36,7 @@ export async function getStaticProps({ params: { keyword, page } }) {
pageType: ['Post']
})
const { allPages } = props
- const allPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
+ const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
props.posts = await filterByMemCache(allPosts, keyword)
props.postCount = props.posts.length
// 处理分页
diff --git a/pages/search/index.js b/pages/search/index.js
index ba09db8e..22061cbd 100644
--- a/pages/search/index.js
+++ b/pages/search/index.js
@@ -55,7 +55,7 @@ export async function getStaticProps() {
pageType: ['Post']
})
const { allPages } = props
- props.posts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
+ props.posts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
return {
props,
revalidate: parseInt(BLOG.NEXT_REVALIDATE_SECOND)
diff --git a/pages/sitemap.xml.js b/pages/sitemap.xml.js
index 58011385..58c9a846 100644
--- a/pages/sitemap.xml.js
+++ b/pages/sitemap.xml.js
@@ -42,7 +42,7 @@ export const getServerSideProps = async (ctx) => {
const slugWithoutLeadingSlash = post?.slug.startsWith('/') ? post?.slug?.slice(1) : post.slug
return {
loc: `${BLOG.LINK}/${slugWithoutLeadingSlash}`,
- lastmod: new Date(post?.publishTime).toISOString().split('T')[0],
+ lastmod: new Date(post?.publishDay).toISOString().split('T')[0],
changefreq: 'daily',
priority: '0.7'
}
diff --git a/pages/tag/[tag]/index.js b/pages/tag/[tag]/index.js
index db2aaed8..bd9f7529 100644
--- a/pages/tag/[tag]/index.js
+++ b/pages/tag/[tag]/index.js
@@ -33,7 +33,7 @@ export async function getStaticProps({ params: { tag } }) {
const props = await getGlobalData({ from })
// 过滤状态
- props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post?.tags && post?.tags.includes(tag))
+ props.posts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post?.tags && post?.tags.includes(tag))
// 处理文章页数
props.postCount = props.posts.length
diff --git a/pages/tag/[tag]/page/[page].js b/pages/tag/[tag]/page/[page].js
index bf383870..2eaef518 100644
--- a/pages/tag/[tag]/page/[page].js
+++ b/pages/tag/[tag]/page/[page].js
@@ -27,7 +27,7 @@ export async function getStaticProps({ params: { tag, page } }) {
const from = 'tag-page-props'
const props = await getGlobalData({ from })
// 过滤状态、标签
- props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post?.tags && post?.tags.includes(tag))
+ props.posts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post?.tags && post?.tags.includes(tag))
// 处理文章数
props.postCount = props.posts.length
// 处理分页
@@ -48,7 +48,7 @@ export async function getStaticPaths() {
const paths = []
tagOptions?.forEach(tag => {
// 过滤状态类型
- const tagPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post?.tags && post?.tags.includes(tag.name))
+ const tagPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post?.tags && post?.tags.includes(tag.name))
// 处理文章页数
const postCount = tagPosts.length
const totalPages = Math.ceil(postCount / BLOG.POSTS_PER_PAGE)
diff --git a/themes/example/components/ArticleInfo.js b/themes/example/components/ArticleInfo.js
index cd29e978..825fc774 100644
--- a/themes/example/components/ArticleInfo.js
+++ b/themes/example/components/ArticleInfo.js
@@ -29,12 +29,12 @@ export const ArticleInfo = (props) => {
passHref
className="pl-1 mr-2 cursor-pointer hover:text-gray-700 dark:hover:text-gray-200 border-b dark:border-gray-500 border-dashed">
- {post?.publishTime}
+ {post?.publishDay}
|
- {locale.COMMON.LAST_EDITED_TIME}: {post?.lastEditedTime}
+ {locale.COMMON.LAST_EDITED_TIME}: {post?.lastEditedDay}
|
diff --git a/themes/example/components/BlogListGroupByDate.js b/themes/example/components/BlogListGroupByDate.js
index 7759eaca..ac5f9cbd 100644
--- a/themes/example/components/BlogListGroupByDate.js
+++ b/themes/example/components/BlogListGroupByDate.js
@@ -19,9 +19,9 @@ export default function BlogListGroupByDate({ archiveTitle, archivePosts }) {
key={post.id}
className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500"
>
-
+
- {post?.publishTime}
+ {post?.publishDay}
{' '}
diff --git a/themes/example/index.js b/themes/example/index.js
index d14bc570..0772f7fd 100644
--- a/themes/example/index.js
+++ b/themes/example/index.js
@@ -2,7 +2,6 @@
import BLOG from '@/blog.config'
import CONFIG from './config'
-import CommonHead from '@/components/CommonHead'
import { useEffect } from 'react'
import { Header } from './components/Header'
import { Nav } from './components/Nav'
@@ -27,6 +26,7 @@ import TagItem from './components/TagItem'
import { useRouter } from 'next/router'
import { Transition } from '@headlessui/react'
import { Style } from './style'
+import CommonHead from '@/components/CommonHead'
/**
* 基础布局框架
@@ -36,7 +36,7 @@ import { Style } from './style'
* @constructor
*/
const LayoutBase = props => {
- const { children, meta, slotTop } = props
+ const { children, slotTop, meta } = props
const { onLoading } = useGlobal()
// 增加一个状态以触发 Transition 组件的动画
@@ -49,8 +49,10 @@ const LayoutBase = props => {
return (
- {/* 网页SEO信息 */}
-
+
+ {/* SEO信息 */}
+
+
{/* 页头 */}
diff --git a/themes/fukasawa/components/ArticleDetail.js b/themes/fukasawa/components/ArticleDetail.js
index 2e2cce59..9e47a925 100644
--- a/themes/fukasawa/components/ArticleDetail.js
+++ b/themes/fukasawa/components/ArticleDetail.js
@@ -59,12 +59,12 @@ export default function ArticleDetail(props) {
passHref
className="pl-1 mr-2 cursor-pointer hover:text-gray-700 dark:hover:text-gray-200 border-b dark:border-gray-500 border-dashed">
- {post?.publishTime}
+ {post?.publishDay}
|
- {locale.COMMON.LAST_EDITED_TIME}: {post.lastEditedTime}
+ {locale.COMMON.LAST_EDITED_TIME}: {post.lastEditedDay}
>)}
diff --git a/themes/fukasawa/components/BlogPostArchive.js b/themes/fukasawa/components/BlogPostArchive.js
index ba68f8cf..08557ae3 100644
--- a/themes/fukasawa/components/BlogPostArchive.js
+++ b/themes/fukasawa/components/BlogPostArchive.js
@@ -26,7 +26,7 @@ const BlogArchiveItem = ({ posts = [], archiveTitle }) => {
key={post.id}
className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500"
>
-
+
{post.date?.start_date}{' '}
import('@/components/Live2D'))
@@ -66,7 +66,8 @@ const LayoutBase = (props) => {
-
+ {/* SEO信息 */}
+
diff --git a/themes/gitbook/components/NavPostList.js b/themes/gitbook/components/NavPostList.js
index 1dff3722..9ffc0cf9 100644
--- a/themes/gitbook/components/NavPostList.js
+++ b/themes/gitbook/components/NavPostList.js
@@ -10,12 +10,24 @@ import NavPostItem from './NavPostItem'
* @constructor
*/
const NavPostList = (props) => {
- const { filteredPostGroups } = props
+ const { filteredNavPages } = props
const router = useRouter()
let selectedSth = false
+ const groupedArray = filteredNavPages?.reduce((groups, item) => {
+ const categoryName = item?.category ? item?.category : '' // 将category转换为字符串
+ const lastGroup = groups[groups.length - 1] // 获取最后一个分组
+
+ if (!lastGroup || lastGroup?.category !== categoryName) { // 如果当前元素的category与上一个元素不同,则创建新分组
+ groups.push({ category: categoryName, items: [] })
+ }
+
+ groups[groups.length - 1].items.push(item) // 将元素加入对应的分组
+
+ return groups
+ }, [])
// 处理是否选中
- filteredPostGroups?.map((group) => {
+ groupedArray?.map((group) => {
let groupSelected = false
for (const post of group?.items) {
if (router.asPath.split('?')[0] === '/' + post.slug) {
@@ -28,16 +40,16 @@ const NavPostList = (props) => {
})
// 如果都没有选中默认打开第一个
- if (!selectedSth && filteredPostGroups && filteredPostGroups?.length > 0) {
- filteredPostGroups[0].selected = true
+ if (!selectedSth && groupedArray && groupedArray?.length > 0) {
+ groupedArray[0].selected = true
}
- if (!filteredPostGroups || filteredPostGroups.length === 0) {
+ if (!groupedArray || groupedArray.length === 0) {
return
} else {
return
{/* 文章列表 */}
- {filteredPostGroups?.map((group, index) => )}
+ {groupedArray?.map((group, index) => )}
}
}
diff --git a/themes/gitbook/components/PageNavDrawer.js b/themes/gitbook/components/PageNavDrawer.js
index 17448c94..14846699 100644
--- a/themes/gitbook/components/PageNavDrawer.js
+++ b/themes/gitbook/components/PageNavDrawer.js
@@ -10,7 +10,8 @@ import NavPostList from './NavPostList'
*/
const PageNavDrawer = (props) => {
const { pageNavVisible, changePageNavVisible } = useGitBookGlobal()
- const { filteredPostGroups } = props
+ const { filteredNavPages } = props
+
const switchVisible = () => {
changePageNavVisible(!pageNavVisible)
}
@@ -23,7 +24,7 @@ const PageNavDrawer = (props) => {
' overflow-y-hidden shadow-card w-72 duration-200 fixed left-1 top-16 rounded py-2 bg-white dark:bg-gray-600'}>
{/* 所有文章列表 */}
-
+
diff --git a/themes/gitbook/components/SearchInput.js b/themes/gitbook/components/SearchInput.js
index 43062eb2..bad985da 100644
--- a/themes/gitbook/components/SearchInput.js
+++ b/themes/gitbook/components/SearchInput.js
@@ -5,7 +5,7 @@ let lock = false
const SearchInput = ({ currentSearch, cRef, className }) => {
const searchInputRef = useRef()
- const { setFilterPosts, allNavPages } = useGitBookGlobal()
+ const { setFilteredNavPages, allNavPages } = useGitBookGlobal()
useImperativeHandle(cRef, () => {
return {
@@ -17,31 +17,44 @@ const SearchInput = ({ currentSearch, cRef, className }) => {
const handleSearch = () => {
let keyword = searchInputRef.current.value
- const filterPosts = []
if (keyword) {
keyword = keyword.trim()
} else {
- setFilterPosts(allNavPages)
+ setFilteredNavPages(allNavPages)
}
const filterAllNavPages = deepClone(allNavPages)
- for (const filterGroup of filterAllNavPages) {
- for (let i = filterGroup.items.length - 1; i >= 0; i--) {
- const post = filterGroup.items[i]
- const articleInfo = post.title + ''
- const hit = articleInfo.toLowerCase().indexOf(keyword.toLowerCase()) > -1
- if (!hit) {
- // 删除
- filterGroup.items.splice(i, 1)
- }
- }
- if (filterGroup.items && filterGroup.items.length > 0) {
- filterPosts.push(filterGroup)
+ // for (const filterGroup of filterAllNavPages) {
+ // for (let i = filterGroup.items.length - 1; i >= 0; i--) {
+ // const post = filterGroup.items[i]
+ // const articleInfo = post.title + ''
+ // const hit = articleInfo.toLowerCase().indexOf(keyword.toLowerCase()) > -1
+ // if (!hit) {
+ // // 删除
+ // filterGroup.items.splice(i, 1)
+ // }
+ // }
+ // if (filterGroup.items && filterGroup.items.length > 0) {
+ // filterPosts.push(filterGroup)
+ // }
+ // }
+ for (let i = filterAllNavPages.length - 1; i >= 0; i--) {
+ const post = filterAllNavPages[i]
+ const articleInfo = post.title + ''
+ const hit = articleInfo.toLowerCase().indexOf(keyword.toLowerCase()) > -1
+ if (!hit) {
+ // 删除
+ filterAllNavPages.splice(i, 1)
}
}
// 更新完
- setFilterPosts(filterPosts)
+ setFilteredNavPages(filterAllNavPages)
}
+
+ /**
+ * 回车键
+ * @param {*} e
+ */
const handleKeyUp = (e) => {
if (e.keyCode === 13) { // 回车
handleSearch(searchInputRef.current.value)
@@ -49,6 +62,10 @@ const SearchInput = ({ currentSearch, cRef, className }) => {
cleanSearch()
}
}
+
+ /**
+ * 清理搜索
+ */
const cleanSearch = () => {
searchInputRef.current.value = ''
handleSearch()
diff --git a/themes/gitbook/index.js b/themes/gitbook/index.js
index 2b034195..e5fcaeac 100644
--- a/themes/gitbook/index.js
+++ b/themes/gitbook/index.js
@@ -4,7 +4,6 @@ import CONFIG from './config'
import { useRouter } from 'next/router'
import { useEffect, useState, createContext, useContext } from 'react'
import { isBrowser } from '@/lib/utils'
-import CommonHead from '@/components/CommonHead'
import Footer from './components/Footer'
import InfoCard from './components/InfoCard'
import RevolverMaps from './components/RevolverMaps'
@@ -31,6 +30,7 @@ import NotionPage from '@/components/NotionPage'
import { ArticleLock } from './components/ArticleLock'
import { Transition } from '@headlessui/react'
import { Style } from './style'
+import CommonHead from '@/components/CommonHead'
// 主题全局变量
const ThemeGlobalGitbook = createContext()
@@ -43,22 +43,23 @@ export const useGitBookGlobal = () => useContext(ThemeGlobalGitbook)
* @constructor
*/
const LayoutBase = (props) => {
- const { children, meta, post, allNavPages, slotLeft, slotRight, slotTop } = props
+ const { children, post, allNavPages, slotLeft, slotRight, slotTop, meta } = props
const { onLoading } = useGlobal()
const router = useRouter()
const [tocVisible, changeTocVisible] = useState(false)
const [pageNavVisible, changePageNavVisible] = useState(false)
- const [filteredPostGroups, setFilteredPostGroups] = useState(allNavPages)
+ const [filteredNavPages, setFilteredNavPages] = useState(allNavPages)
const showTocButton = post?.toc?.length > 1
useEffect(() => {
- setFilteredPostGroups(allNavPages)
+ console.log('更新导航', allNavPages)
+ setFilteredNavPages(allNavPages)
}, [post])
return (
-
-
+
+
@@ -72,8 +73,10 @@ const LayoutBase = (props) => {
{slotLeft}
- {/* 所有文章列表 */}
-
+
+ {/* 所有文章列表 */}
+
+
@@ -146,7 +149,7 @@ const LayoutBase = (props) => {
}
{/* 移动端导航抽屉 */}
-
+
{/* 移动端底部导航栏 */}
{/* */}
diff --git a/themes/heo/components/ArticleAdjacent.js b/themes/heo/components/ArticleAdjacent.js
index 030a5dd7..07535cac 100644
--- a/themes/heo/components/ArticleAdjacent.js
+++ b/themes/heo/components/ArticleAdjacent.js
@@ -70,7 +70,7 @@ export default function ArticleAdjacent({ prev, next }) {
{/* 桌面端 */}
-
+
{
return (
-
+
{/* 左侧banner组 */}
@@ -116,22 +116,22 @@ function TagsGroupBar() {
*/
function GroupMenu() {
return (
-
+
-
+
{CONFIG.HERO_CATEGORY_1?.title}
-
+
-
+
{CONFIG.HERO_CATEGORY_2?.title}
-
+
@@ -154,16 +154,20 @@ function GroupMenu() {
* 置顶文章区域
*/
function TopGroup(props) {
- const { latestPosts, siteInfo } = props
+ const { latestPosts, allNavPages, siteInfo } = props
const todayCardRef = useRef()
function handleMouseLeave() {
todayCardRef.current.coverUp()
}
+
+ // 获取置顶推荐文章
+ const topPosts = getTopPosts({ latestPosts, allNavPages })
+
return (
- {/* 置顶最新文章 */}
+ {/* 置顶推荐文章 */}
- {latestPosts?.map((p, index) => {
+ {topPosts?.map((p, index) => {
return
@@ -181,6 +185,42 @@ function TopGroup(props) {
)
}
+/**
+ * 获取推荐置顶文章
+ */
+function getTopPosts({ latestPosts, allNavPages }) {
+ // 默认展示最近更新
+ if (!CONFIG.HERO_RECOMMEND_POST_TAG || CONFIG.HERO_RECOMMEND_POST_TAG === '') {
+ return latestPosts
+ }
+
+ // 显示包含‘推荐’标签的文章
+ let sortPosts = []
+
+ // 排序方式
+ if (JSON.parse(CONFIG.HERO_RECOMMEND_POST_SORT_BY_UPDATE_TIME)) {
+ sortPosts = Object.create(allNavPages).sort((a, b) => {
+ const dateA = new Date(a?.lastEditedDate)
+ const dateB = new Date(b?.lastEditedDate)
+ return dateB - dateA
+ })
+ } else {
+ sortPosts = Object.create(allNavPages)
+ }
+
+ const topPosts = []
+ for (const post of sortPosts) {
+ if (topPosts.length === 6) {
+ break
+ }
+ // 查找标签
+ if (post?.tags?.indexOf(CONFIG.HERO_RECOMMEND_POST_TAG) >= 0) {
+ topPosts.push(post)
+ }
+ }
+ return topPosts
+}
+
/**
* 英雄区右侧,今日卡牌
* @returns
diff --git a/themes/heo/components/LatestPostsGroupMini.js b/themes/heo/components/LatestPostsGroupMini.js
index bcf4d80a..1f0575f6 100644
--- a/themes/heo/components/LatestPostsGroupMini.js
+++ b/themes/heo/components/LatestPostsGroupMini.js
@@ -52,7 +52,7 @@ export default function LatestPostsGroupMini ({ latestPosts, siteInfo }) {
>
{post.title}
-
{post.lastEditedTime}
+
{post.lastEditedDay}
diff --git a/themes/heo/components/NavBar.js b/themes/heo/components/NavBar.js
index af69384a..cd1c205b 100644
--- a/themes/heo/components/NavBar.js
+++ b/themes/heo/components/NavBar.js
@@ -143,9 +143,9 @@ const NavBar = props => {
{/* 右侧固定 */}
-
+
-
+
{!JSON.parse(BLOG.THEME_SWITCH) &&
}
diff --git a/themes/heo/components/PostHeader.js b/themes/heo/components/PostHeader.js
index 5a707477..c7f47b5c 100644
--- a/themes/heo/components/PostHeader.js
+++ b/themes/heo/components/PostHeader.js
@@ -79,13 +79,13 @@ export default function PostHeader({ post, siteInfo }) {
href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}
passHref
className="pl-1 mr-2 cursor-pointer hover:underline">
-
{post?.publishTime}
+
{post?.publishDay}
>
)}
- {post.lastEditedTime}
+ {post.lastEditedDay}
diff --git a/themes/heo/components/SearchButton.js b/themes/heo/components/SearchButton.js
index e23907a4..e9e253db 100644
--- a/themes/heo/components/SearchButton.js
+++ b/themes/heo/components/SearchButton.js
@@ -8,7 +8,7 @@ import { useRef } from 'react'
* 搜索按钮
* @returns
*/
-export default function SearchButton() {
+export default function SearchButton(props) {
const { locale } = useGlobal()
const router = useRouter()
const searchModal = useRef(null)
@@ -25,6 +25,6 @@ export default function SearchButton() {
-
+
>
}
diff --git a/themes/heo/config.js b/themes/heo/config.js
index 86ed342e..f62be177 100644
--- a/themes/heo/config.js
+++ b/themes/heo/config.js
@@ -22,6 +22,10 @@ const CONFIG = {
HERO_CATEGORY_2: { title: '热门文章', url: '/tag/热门文章' },
HERO_CATEGORY_3: { title: '实用教程', url: '/tag/实用教程' },
+ // 英雄区右侧推荐文章标签, 例如 [推荐] , 最多六篇文章; 若留空白'',则推荐最近更新文章
+ HERO_RECOMMEND_POST_TAG: '推荐',
+ HERO_RECOMMEND_POST_SORT_BY_UPDATE_TIME: false, // 推荐文章排序,为`true`时将强制按最后修改时间倒序
+
// 右侧个人资料卡牌欢迎语,点击可自动切换
INFOCARD_GREETINGS: [
'你好!我是',
diff --git a/themes/heo/index.js b/themes/heo/index.js
index 60b955b8..3ea96256 100644
--- a/themes/heo/index.js
+++ b/themes/heo/index.js
@@ -39,12 +39,12 @@ import LazyImage from '@/components/LazyImage'
* @constructor
*/
const LayoutBase = props => {
- const { children, headerSlot, slotTop, slotRight, meta, siteInfo, className } = props
+ const { children, headerSlot, slotTop, slotRight, siteInfo, className, meta } = props
return (
- {/* 网页SEO */}
-
+ {/* SEO信息 */}
+
{/* 顶部嵌入 导航栏,首页放hero,文章页放文章详情 */}
@@ -93,7 +93,7 @@ const LayoutIndex = (props) => {
const slotRight =
return
-
+
{/* 文章分类条 */}
{BLOG.POST_LIST_STYLE === 'page' ?
:
}
@@ -115,7 +115,7 @@ const LayoutPostList = (props) => {
return
-
+
{/* 文章分类条 */}
{BLOG.POST_LIST_STYLE === 'page' ?
:
}
@@ -155,7 +155,7 @@ const LayoutSearch = props => {
}, [])
return (
-
+
{!currentSearch
?
:
{BLOG.POST_LIST_STYLE === 'page' ? : }
}
@@ -348,7 +348,7 @@ const LayoutCategoryIndex = props => {
return (
-
+
{locale.COMMON.CATEGORY}
@@ -386,7 +386,7 @@ const LayoutTagIndex = props => {
return (
-
+
{locale.COMMON.TAGS}
diff --git a/themes/hexo/components/BlogPostArchive.js b/themes/hexo/components/BlogPostArchive.js
index 08feff4c..ea3c6cd2 100644
--- a/themes/hexo/components/BlogPostArchive.js
+++ b/themes/hexo/components/BlogPostArchive.js
@@ -26,7 +26,7 @@ const BlogPostArchive = ({ posts = [], archiveTitle }) => {
key={post.id}
className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-indigo-500 dark:hover:border-indigo-300 dark:border-indigo-400 transform duration-500"
>
-
+
{post.date?.start_date}{' '}
- {post?.publishTime || post.lastEditedTime}
+ {post?.publishDay || post.lastEditedDay}
diff --git a/themes/hexo/components/Hero.js b/themes/hexo/components/Hero.js
index c07a401e..ad28362f 100644
--- a/themes/hexo/components/Hero.js
+++ b/themes/hexo/components/Hero.js
@@ -68,7 +68,7 @@ const Hero = props => {
{/* 滚动按钮 */}
-
{locale.COMMON.START_READING}
+
{CONFIG.SHOW_START_READING && locale.COMMON.START_READING}
diff --git a/themes/hexo/components/LatestPostsGroup.js b/themes/hexo/components/LatestPostsGroup.js
index d315367a..bc3002dd 100644
--- a/themes/hexo/components/LatestPostsGroup.js
+++ b/themes/hexo/components/LatestPostsGroup.js
@@ -52,7 +52,7 @@ const LatestPostsGroup = ({ latestPosts, siteInfo }) => {
>
{post.title}
-
{post.lastEditedTime}
+
{post.lastEditedDay}
diff --git a/themes/hexo/components/PostHeader.js b/themes/hexo/components/PostHeader.js
index 21eec51a..acafaf0f 100644
--- a/themes/hexo/components/PostHeader.js
+++ b/themes/hexo/components/PostHeader.js
@@ -47,13 +47,13 @@ export default function PostHeader({ post, siteInfo }) {
passHref
className="pl-1 mr-2 cursor-pointer hover:underline">
- {locale.COMMON.POST_TIME}: {post?.publishTime}
+ {locale.COMMON.POST_TIME}: {post?.publishDay}
>
)}
- {locale.COMMON.LAST_EDITED_TIME}: {post.lastEditedTime}
+ {locale.COMMON.LAST_EDITED_TIME}: {post.lastEditedDay}
diff --git a/themes/hexo/config.js b/themes/hexo/config.js
index b24d4fd1..262e7bfe 100644
--- a/themes/hexo/config.js
+++ b/themes/hexo/config.js
@@ -6,6 +6,8 @@ const CONFIG = {
HOME_NAV_BUTTONS: true, // 首页是否显示分类大图标按钮
// 已知未修复bug, 在移动端开启true后会加载不出图片; 暂时建议设置为false。
HOME_NAV_BACKGROUND_IMG_FIXED: false, // 首页背景图滚动时是否固定,true 则滚动时图片不懂动; false则随鼠标滚动 ;
+ // 是否显示开始阅读按钮
+ SHOW_START_READING: true,
// 菜单配置
MENU_INDEX: true, // 显示首页
diff --git a/themes/hexo/index.js b/themes/hexo/index.js
index 78f3ab69..c07e70a0 100644
--- a/themes/hexo/index.js
+++ b/themes/hexo/index.js
@@ -47,7 +47,7 @@ const LayoutBase = props => {
return (
{/* 网页SEO */}
-
+
{/* 顶部导航 */}
@@ -71,7 +71,7 @@ const LayoutBase = props => {
{/* 主区块 */}
-
+
{
passHref
className="cursor-pointer whitespace-nowrap">
- {locale.COMMON.POST_TIME}: {post?.publishTime}
+ {locale.COMMON.POST_TIME}: {post?.publishDay}
- {locale.COMMON.LAST_EDITED_TIME}: {post.lastEditedTime}
+ {locale.COMMON.LAST_EDITED_TIME}: {post.lastEditedDay}
diff --git a/themes/matery/components/BlogPostArchive.js b/themes/matery/components/BlogPostArchive.js
index 08feff4c..ea3c6cd2 100644
--- a/themes/matery/components/BlogPostArchive.js
+++ b/themes/matery/components/BlogPostArchive.js
@@ -26,7 +26,7 @@ const BlogPostArchive = ({ posts = [], archiveTitle }) => {
key={post.id}
className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-indigo-500 dark:hover:border-indigo-300 dark:border-indigo-400 transform duration-500"
>
-
+
{post.date?.start_date}{' '}
{
className="font-light hover:underline cursor-pointer text-sm leading-4 mr-3">
- {post.date?.start_date || post.lastEditedTime}
+ {post.date?.start_date || post.lastEditedDay}
diff --git a/themes/matery/components/Hero.js b/themes/matery/components/Hero.js
index 6c94cb1c..a7157b68 100644
--- a/themes/matery/components/Hero.js
+++ b/themes/matery/components/Hero.js
@@ -61,7 +61,7 @@ const Hero = props => {
{/* 滚动按钮 */}
{ window.scrollTo({ top: wrapperTop, behavior: 'smooth' }) }}
className="mt-12 border cursor-pointer w-40 text-center pt-4 pb-3 text-md text-white hover:bg-orange-600 duration-300 rounded-3xl z-40">
- {locale.COMMON.START_READING}
+ {CONFIG.SHOW_START_READING && locale.COMMON.START_READING}
diff --git a/themes/matery/config.js b/themes/matery/config.js
index a772b297..2878e51b 100644
--- a/themes/matery/config.js
+++ b/themes/matery/config.js
@@ -6,6 +6,9 @@ const CONFIG = {
HOME_NAV_BUTTONS: true, // 首页是否显示分类大图标按钮
HOME_NAV_BACKGROUND_IMG_FIXED: false, // 首页背景图滚动时是否固定,true 则滚动时图片不懂; false则随鼠标滚动
+ // 是否显示开始阅读按钮
+ SHOW_START_READING: true,
+
// 菜单配置
MENU_CATEGORY: true, // 显示分类
MENU_TAG: true, // 显示标签
diff --git a/themes/medium/components/ArticleInfo.js b/themes/medium/components/ArticleInfo.js
index 3d4abce5..0ecff45e 100644
--- a/themes/medium/components/ArticleInfo.js
+++ b/themes/medium/components/ArticleInfo.js
@@ -17,9 +17,9 @@ export default function ArticleInfo(props) {
{/* meta */}
-
{post?.publishTime}
+
{post?.publishDay}
|
-
{post?.lastEditedTime}
+
{post?.lastEditedDay}
diff --git a/themes/medium/components/BlogArchiveItem.js b/themes/medium/components/BlogArchiveItem.js
index 52b2fefb..8e9693dc 100644
--- a/themes/medium/components/BlogArchiveItem.js
+++ b/themes/medium/components/BlogArchiveItem.js
@@ -17,7 +17,7 @@ export default function BlogArchiveItem({ archiveTitle, archivePosts }) {
-
+
{post.date?.start_date}
{' '}
diff --git a/themes/medium/components/RevolverMaps.js b/themes/medium/components/RevolverMaps.js
index d839d85d..a65fc4cf 100644
--- a/themes/medium/components/RevolverMaps.js
+++ b/themes/medium/components/RevolverMaps.js
@@ -16,7 +16,7 @@ function initRevolverMaps () {
Promise.all([
loadExternalResource('https://rf.revolvermaps.com/0/0/8.js?i=5jnp1havmh9&m=0&c=ff0000&cr1=ffffff&f=arial&l=33')
]).then(() => {
- console.log('地图加载完成')
+ // console.log('地图加载完成')
})
}
}
diff --git a/themes/medium/index.js b/themes/medium/index.js
index b57b8528..01d3f904 100644
--- a/themes/medium/index.js
+++ b/themes/medium/index.js
@@ -1,6 +1,5 @@
import CONFIG from './config'
-import CommonHead from '@/components/CommonHead'
import { useState, createContext, useContext, useEffect } from 'react'
import Footer from './components/Footer'
import InfoCard from './components/InfoCard'
@@ -36,6 +35,7 @@ import { Transition } from '@headlessui/react'
import { Style } from './style'
import replaceSearchResult from '@/components/Mark'
import ArticleInfo from './components/ArticleInfo'
+import CommonHead from '@/components/CommonHead'
// 主题全局状态
const ThemeGlobalMedium = createContext()
@@ -48,7 +48,7 @@ export const useMediumGlobal = () => useContext(ThemeGlobalMedium)
* @constructor
*/
const LayoutBase = props => {
- const { children, meta, showInfoCard = true, slotRight, slotTop, siteInfo, notice } = props
+ const { children, showInfoCard = true, slotRight, slotTop, siteInfo, notice, meta } = props
const { locale } = useGlobal()
const router = useRouter()
const [tocVisible, changeTocVisible] = useState(false)
@@ -57,7 +57,7 @@ const LayoutBase = props => {
return (
{/* SEO相关 */}
-
+
{/* CSS样式 */}
diff --git a/themes/next/components/ArticleDetail.js b/themes/next/components/ArticleDetail.js
index a2d6fc48..a4f575ec 100644
--- a/themes/next/components/ArticleDetail.js
+++ b/themes/next/components/ArticleDetail.js
@@ -59,10 +59,10 @@ export default function ArticleDetail(props) {
passHref
legacyBehavior>
- {post?.publishTime}
+ {post?.publishDay}
- | {post.lastEditedTime}
+ | {post.lastEditedDay}
diff --git a/themes/next/components/BlogPostArchive.js b/themes/next/components/BlogPostArchive.js
index a6c0e796..b1f22296 100644
--- a/themes/next/components/BlogPostArchive.js
+++ b/themes/next/components/BlogPostArchive.js
@@ -26,7 +26,7 @@ const BlogPostArchive = ({ posts = [], archiveTitle }) => {
key={post.id}
className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500"
>
-
+
{post.date?.start_date}{' '}
{
- const { children, headerSlot, meta, floatSlot, rightAreaSlot, siteInfo } = props
+ const { children, headerSlot, floatSlot, rightAreaSlot, siteInfo, meta } = props
const { onLoading } = useGlobal()
const targetRef = useRef(null)
const floatButtonGroup = useRef(null)
@@ -72,7 +71,7 @@ const LayoutBase = (props) => {
return (
{/* SEO相关 */}
-
+
{/* 移动端顶部导航栏 */}
diff --git a/themes/nobelium/components/ArticleInfo.js b/themes/nobelium/components/ArticleInfo.js
index 7cc873aa..0ecb4895 100644
--- a/themes/nobelium/components/ArticleInfo.js
+++ b/themes/nobelium/components/ArticleInfo.js
@@ -32,7 +32,7 @@ export const ArticleInfo = (props) => {
/
- {post?.publishTime}
+ {post?.publishDay}
{post?.tags && (
diff --git a/themes/nobelium/components/BlogArchiveItem.js b/themes/nobelium/components/BlogArchiveItem.js
index 3b16fc3b..b8184f45 100644
--- a/themes/nobelium/components/BlogArchiveItem.js
+++ b/themes/nobelium/components/BlogArchiveItem.js
@@ -19,7 +19,7 @@ export default function BlogArchiveItem({ archiveTitle, archivePosts }) {
key={post.id}
className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500"
>
-
+
{post.date?.start_date}
{' '}
diff --git a/themes/nobelium/components/BlogPost.js b/themes/nobelium/components/BlogPost.js
index 91ad3bd4..b1080b35 100644
--- a/themes/nobelium/components/BlogPost.js
+++ b/themes/nobelium/components/BlogPost.js
@@ -12,7 +12,7 @@ const BlogPost = ({ post }) => {
{post.title}
diff --git a/themes/nobelium/index.js b/themes/nobelium/index.js
index d9410924..d9a930e0 100644
--- a/themes/nobelium/index.js
+++ b/themes/nobelium/index.js
@@ -1,6 +1,5 @@
import BLOG from '@/blog.config'
import CONFIG from './config'
-import CommonHead from '@/components/CommonHead'
import React, { useEffect, useState } from 'react'
import Nav from './components/Nav'
import { Footer } from './components/Footer'
@@ -24,6 +23,7 @@ import BlogListBar from './components/BlogListBar'
import { Transition } from '@headlessui/react'
import { Style } from './style'
import replaceSearchResult from '@/components/Mark'
+import CommonHead from '@/components/CommonHead'
/**
* 基础布局 采用左右两侧布局,移动端使用顶部导航栏
@@ -32,7 +32,7 @@ import replaceSearchResult from '@/components/Mark'
* @constructor
*/
const LayoutBase = props => {
- const { children, meta, post, topSlot } = props
+ const { children, post, topSlot, meta } = props
const fullWidth = post?.fullWidth ?? false
const { onLoading } = useGlobal()
@@ -40,7 +40,8 @@ const LayoutBase = props => {
return (
{/* SEO相关 */}
-
+
+ {/* SEO相关 */}
{/* 顶部导航栏 */}
diff --git a/themes/plog/components/ArticleInfo.js b/themes/plog/components/ArticleInfo.js
index 7cc873aa..0ecb4895 100644
--- a/themes/plog/components/ArticleInfo.js
+++ b/themes/plog/components/ArticleInfo.js
@@ -32,7 +32,7 @@ export const ArticleInfo = (props) => {
/
- {post?.publishTime}
+ {post?.publishDay}
{post?.tags && (
diff --git a/themes/plog/components/BlogArchiveItem.js b/themes/plog/components/BlogArchiveItem.js
index 3b16fc3b..b8184f45 100644
--- a/themes/plog/components/BlogArchiveItem.js
+++ b/themes/plog/components/BlogArchiveItem.js
@@ -19,7 +19,7 @@ export default function BlogArchiveItem({ archiveTitle, archivePosts }) {
key={post.id}
className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500"
>
-
+
{post.date?.start_date}
{' '}
diff --git a/themes/plog/index.js b/themes/plog/index.js
index d5f15608..55895df4 100644
--- a/themes/plog/index.js
+++ b/themes/plog/index.js
@@ -1,6 +1,5 @@
import CONFIG from './config'
-import CommonHead from '@/components/CommonHead'
-import React, { createContext, useContext, useEffect, useState } from 'react'
+import { createContext, useContext, useEffect, useState } from 'react'
import Header from './components/Nav'
import { useGlobal } from '@/lib/global'
@@ -23,6 +22,7 @@ import { saveDarkModeToCookies } from '@/themes/theme'
import Modal from './components/Modal'
import { Style } from './style'
import replaceSearchResult from '@/components/Mark'
+import CommonHead from '@/components/CommonHead'
// 主题全局状态
const ThemeGlobalPlog = createContext()
@@ -35,7 +35,7 @@ export const usePlogGlobal = () => useContext(ThemeGlobalPlog)
* @constructor
*/
const LayoutBase = props => {
- const { children, meta, topSlot } = props
+ const { children, topSlot, meta } = props
const { onLoading, updateDarkMode } = useGlobal()
const [showModal, setShowModal] = useState(false)
const [modalContent, setModalContent] = useState(null)
@@ -60,7 +60,7 @@ const LayoutBase = props => {
{/* SEO相关 */}
-
+
{/* 移动端顶部导航栏 */}
diff --git a/themes/simple/components/ArticleInfo.js b/themes/simple/components/ArticleInfo.js
index 6f17b0df..30e1b5f4 100644
--- a/themes/simple/components/ArticleInfo.js
+++ b/themes/simple/components/ArticleInfo.js
@@ -20,7 +20,7 @@ export const ArticleInfo = (props) => {
{post?.type !== 'Page' && (<>
{BLOG.AUTHOR}
-
- {post?.publishTime}
+
- {post?.publishDay}
{post?.category &&
- {post?.category}}
{post?.tags && post?.tags?.length > 0 && post?.tags.map(t =>
/ {t})}
@@ -32,12 +32,12 @@ export const ArticleInfo = (props) => {
href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}
passHref
className="pl-1 mr-2 cursor-pointer hover:text-gray-700 dark:hover:text-gray-200 border-b dark:border-gray-500 border-dashed">
- {post?.publishTime}
+ {post?.publishDay}
|
- {locale.COMMON.LAST_EDITED_TIME}: {post?.lastEditedTime}
+ {locale.COMMON.LAST_EDITED_TIME}: {post?.lastEditedDay}
|
diff --git a/themes/simple/components/BlogArchiveItem.js b/themes/simple/components/BlogArchiveItem.js
index 3b16fc3b..b8184f45 100644
--- a/themes/simple/components/BlogArchiveItem.js
+++ b/themes/simple/components/BlogArchiveItem.js
@@ -19,7 +19,7 @@ export default function BlogArchiveItem({ archiveTitle, archivePosts }) {
key={post.id}
className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500"
>
-
+
{post.date?.start_date}
{' '}
diff --git a/themes/simple/index.js b/themes/simple/index.js
index 04a4ba51..b0c9f95c 100644
--- a/themes/simple/index.js
+++ b/themes/simple/index.js
@@ -12,7 +12,6 @@ import ArticleAround from './components/ArticleAround'
import ShareBar from '@/components/ShareBar'
import { AdSlot } from '@/components/GoogleAdsense'
import Link from 'next/link'
-import CommonHead from '@/components/CommonHead'
import { TopBar } from './components/TopBar'
import { Header } from './components/Header'
import { NavBar } from './components/NavBar'
@@ -25,6 +24,7 @@ import SearchInput from './components/SearchInput'
import { Transition } from '@headlessui/react'
import { Style } from './style'
import replaceSearchResult from '@/components/Mark'
+import CommonHead from '@/components/CommonHead'
/**
* 基础布局
@@ -33,7 +33,7 @@ import replaceSearchResult from '@/components/Mark'
* @returns
*/
const LayoutBase = props => {
- const { children, meta, slotTop } = props
+ const { children, slotTop, meta } = props
const { onLoading } = useGlobal()
if (isBrowser()) {
@@ -41,7 +41,8 @@ const LayoutBase = props => {
}
return (
-
+ {/* SEO相关 */}
+
{CONFIG.TOP_BAR && }
diff --git a/themes/theme.js b/themes/theme.js
index 468199d2..f03f3fe6 100644
--- a/themes/theme.js
+++ b/themes/theme.js
@@ -60,16 +60,25 @@ export const getLayoutNameByPath = (path) => {
* @param updateDarkMode 更改主题ChangeState函数
* @description 读取cookie中存的用户主题
*/
-export const initDarkMode = (isDarkMode, updateDarkMode) => {
+export const initDarkMode = (updateDarkMode) => {
+ // 查看用户设备浏览器是否深色模型
+ let newDarkMode = isPreferDark()
+
+ // 查看cookie中是否用户强制设置深色模式
+ const cookieDarkMode = loadDarkModeFromCookies()
+ if (cookieDarkMode) {
+ newDarkMode = JSON.parse(cookieDarkMode)
+ }
+
+ // url查询条件中是否深色模式
const queryMode = getQueryVariable('mode')
if (queryMode) {
- isDarkMode = queryMode === 'dark'
- } else if (!isDarkMode) {
- isDarkMode = isPreferDark()
+ newDarkMode = queryMode === 'dark'
}
- updateDarkMode(isDarkMode)
- saveDarkModeToCookies(isDarkMode)
- document.getElementsByTagName('html')[0].setAttribute('class', isDarkMode ? 'dark' : 'light')
+
+ updateDarkMode(newDarkMode)
+ saveDarkModeToCookies(newDarkMode)
+ document.getElementsByTagName('html')[0].setAttribute('class', newDarkMode ? 'dark' : 'light')
}
/**