mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-20 23:16:49 +00:00
Merge branch 'main' into feature/user-auth-clerk
This commit is contained in:
@@ -55,8 +55,8 @@ export const siteConfig = (key, defaultVal = null, extendConfig = {}) => {
|
||||
let siteInfo = null
|
||||
|
||||
if (global) {
|
||||
val = global.NOTION_CONFIG?.[key]
|
||||
siteInfo = global.siteInfo
|
||||
val = global.NOTION_CONFIG?.[key] || global.THEME_CONFIG?.[key]
|
||||
}
|
||||
|
||||
if (!val) {
|
||||
|
||||
@@ -347,7 +347,6 @@ export function getNavPages({ allPages }) {
|
||||
return (
|
||||
post &&
|
||||
post?.slug &&
|
||||
!post?.slug?.startsWith('http') &&
|
||||
post?.type === 'Post' &&
|
||||
post?.status === 'Published'
|
||||
)
|
||||
@@ -512,6 +511,7 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
|
||||
adjustPageProperties(element, NOTION_CONFIG)
|
||||
})
|
||||
|
||||
// 站点基础信息
|
||||
const siteInfo = getSiteInfo({ collection, block, pageId })
|
||||
|
||||
// 文章计数
|
||||
@@ -525,7 +525,7 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
|
||||
return (
|
||||
post &&
|
||||
post?.slug &&
|
||||
!post?.slug?.startsWith('http') &&
|
||||
// !post?.slug?.startsWith('http') &&
|
||||
(post?.status === 'Invisible' || post?.status === 'Published')
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { APPEARANCE, LANG, NOTION_PAGE_ID, THEME } from '@/blog.config'
|
||||
import {
|
||||
THEMES,
|
||||
getThemeConfig,
|
||||
initDarkMode,
|
||||
saveDarkModeToLocalStorage
|
||||
} from '@/themes/theme'
|
||||
@@ -29,11 +30,14 @@ export function GlobalContextProvider(props) {
|
||||
tagOptions,
|
||||
NOTION_CONFIG
|
||||
} = props
|
||||
|
||||
const [lang, updateLang] = useState(NOTION_CONFIG?.LANG || LANG) // 默认语言
|
||||
const [locale, updateLocale] = useState(
|
||||
generateLocaleDict(NOTION_CONFIG?.LANG || LANG)
|
||||
) // 默认语言
|
||||
const [theme, setTheme] = useState(NOTION_CONFIG?.THEME || THEME) // 默认博客主题
|
||||
const [THEME_CONFIG, SET_THEME_CONFIG] = useState(null) // 主题配置
|
||||
|
||||
const defaultDarkMode = NOTION_CONFIG?.APPEARANCE || APPEARANCE
|
||||
const [isDarkMode, updateDarkMode] = useState(defaultDarkMode === 'dark') // 默认深色模式
|
||||
const [onLoading, setOnLoading] = useState(false) // 抓取文章数据
|
||||
@@ -54,6 +58,12 @@ export function GlobalContextProvider(props) {
|
||||
return newTheme
|
||||
}
|
||||
|
||||
// 抓取主题配置
|
||||
const updateThemeConfig = async theme => {
|
||||
const config = await getThemeConfig(theme)
|
||||
SET_THEME_CONFIG(config)
|
||||
}
|
||||
|
||||
// 切换深色模式
|
||||
const toggleDarkMode = () => {
|
||||
const newStatus = !isDarkMode
|
||||
@@ -99,6 +109,9 @@ export function GlobalContextProvider(props) {
|
||||
setOnLoading(false)
|
||||
}
|
||||
|
||||
const currentTheme = router?.query?.theme || theme
|
||||
updateThemeConfig(currentTheme)
|
||||
|
||||
router.events.on('routeChangeStart', handleStart)
|
||||
router.events.on('routeChangeError', handleStop)
|
||||
router.events.on('routeChangeComplete', handleStop)
|
||||
@@ -114,6 +127,7 @@ export function GlobalContextProvider(props) {
|
||||
value={{
|
||||
fullWidth,
|
||||
NOTION_CONFIG,
|
||||
THEME_CONFIG,
|
||||
toggleDarkMode,
|
||||
onLoading,
|
||||
setOnLoading,
|
||||
|
||||
@@ -14,11 +14,14 @@ export default {
|
||||
INDEX: 'Home',
|
||||
RSS: 'RSS',
|
||||
SEARCH: 'Search',
|
||||
NAVIGATOR: 'NAV',
|
||||
ABOUT: 'About',
|
||||
MAIL: 'E-Mail',
|
||||
ARCHIVE: 'Archive'
|
||||
},
|
||||
COMMON: {
|
||||
THEME: 'Theme',
|
||||
ARTICLE_LIST: 'Article List',
|
||||
MORE: 'More',
|
||||
NO_MORE: 'No More',
|
||||
LATEST_POSTS: 'Latest posts',
|
||||
|
||||
@@ -20,6 +20,8 @@ export default {
|
||||
ARCHIVE: '归档'
|
||||
},
|
||||
COMMON: {
|
||||
THEME: 'Theme',
|
||||
ARTICLE_LIST: '文章列表',
|
||||
MORE: '更多',
|
||||
NO_MORE: '没有更多了',
|
||||
LATEST_POSTS: '最新发布',
|
||||
@@ -63,7 +65,7 @@ export default {
|
||||
MINUTE: '分钟',
|
||||
WORD_COUNT: '字数',
|
||||
READ_TIME: '阅读时长',
|
||||
NEXT_POST:'下一篇'
|
||||
NEXT_POST: '下一篇'
|
||||
},
|
||||
PAGINATION: {
|
||||
PREV: '上页',
|
||||
|
||||
@@ -5,7 +5,39 @@ export default {
|
||||
RSS: '訂閱',
|
||||
SEARCH: '搜尋',
|
||||
ABOUT: '關於',
|
||||
MAIL: '電郵'
|
||||
MAIL: '電郵',
|
||||
NAVIGATOR: '導航',
|
||||
ARCHIVE: '封存'
|
||||
},
|
||||
COMMON: {
|
||||
ARTICLE_LIST: '文章列表',
|
||||
MORE: '更多',
|
||||
NO_MORE: '沒有更多了',
|
||||
LATEST_POSTS: '最新文章',
|
||||
TAGS: '標籤',
|
||||
NO_TAG: '無標籤',
|
||||
CATEGORY: '分類',
|
||||
SHARE: '分享',
|
||||
SCAN_QR_CODE: 'QRCode',
|
||||
URL_COPIED: '連結已複製!',
|
||||
TABLE_OF_CONTENTS: '目錄',
|
||||
RELATE_POSTS: '相關文章',
|
||||
COPYRIGHT: '著作權',
|
||||
AUTHOR: '作者',
|
||||
URL: '連結',
|
||||
ANALYTICS: '分析',
|
||||
POSTS: '篇文章',
|
||||
ARTICLE: '文章',
|
||||
VISITORS: '位訪客',
|
||||
VIEWS: '次查看',
|
||||
COPYRIGHT_NOTICE: '本文採用 CC BY-NC-SA 4.0 許可協議,轉載請註明出處。',
|
||||
RESULT_OF_SEARCH: '篇搜尋到的结果',
|
||||
ARTICLE_DETAIL: '完整文章',
|
||||
PASSWORD_ERROR: '密碼錯誤!',
|
||||
ARTICLE_LOCK_TIPS: '文章已上鎖,請輸入訪問密碼',
|
||||
SUBMIT: '提交',
|
||||
POST_TIME: '发布于',
|
||||
LAST_EDITED_TIME: '最后更新'
|
||||
},
|
||||
PAGINATION: {
|
||||
PREV: '上一頁',
|
||||
@@ -13,7 +45,7 @@ export default {
|
||||
},
|
||||
SEARCH: {
|
||||
ARTICLES: '搜尋文章',
|
||||
TAGS: '搜尋標簽'
|
||||
TAGS: '搜尋標籤'
|
||||
},
|
||||
POST: {
|
||||
BACK: '返回',
|
||||
|
||||
@@ -10,6 +10,7 @@ export default {
|
||||
ARCHIVE: '封存'
|
||||
},
|
||||
COMMON: {
|
||||
ARTICLE_LIST: '文章列表',
|
||||
MORE: '更多',
|
||||
NO_MORE: '沒有更多了',
|
||||
LATEST_POSTS: '最新文章',
|
||||
|
||||
@@ -6,10 +6,9 @@ import formatDate from '../utils/formatDate'
|
||||
import md5 from 'js-md5'
|
||||
import { siteConfig } from '../config'
|
||||
import {
|
||||
checkStartWithHttp,
|
||||
convertUrlStartWithOneSlash,
|
||||
getLastSegmentFromUrl,
|
||||
sliceUrlFromHttp
|
||||
checkStartWithHttp,
|
||||
convertUrlStartWithOneSlash,
|
||||
getLastSegmentFromUrl
|
||||
} from '../utils'
|
||||
import { extractLangPrefix } from '../utils/pageId'
|
||||
import { mapImgUrl } from './mapImage'
|
||||
@@ -188,29 +187,26 @@ export function adjustPageProperties(properties, NOTION_CONFIG) {
|
||||
properties.name = properties.title ?? ''
|
||||
}
|
||||
|
||||
// 开启伪静态路径
|
||||
if (siteConfig('PSEUDO_STATIC', false, NOTION_CONFIG)) {
|
||||
if (
|
||||
!properties?.href?.endsWith('.html') &&
|
||||
!properties?.href?.startsWith('http') &&
|
||||
properties?.href !== '' &&
|
||||
properties?.href !== '#' &&
|
||||
properties?.href !== '/'
|
||||
) {
|
||||
properties.href += '.html'
|
||||
}
|
||||
}
|
||||
|
||||
// 检查处理外链
|
||||
properties.href = checkStartWithHttp(properties?.href)
|
||||
? sliceUrlFromHttp(properties?.href)
|
||||
: convertUrlStartWithOneSlash(properties?.href)
|
||||
|
||||
// 设置链接在页内或新页面打开
|
||||
if (properties.href?.indexOf('http') === 0) {
|
||||
// http or https 开头的视为外链
|
||||
if (checkStartWithHttp(properties?.href)) {
|
||||
properties.href = properties?.slug
|
||||
properties.target = '_blank'
|
||||
} else {
|
||||
properties.target = '_self'
|
||||
// 伪静态路径右侧拼接.html
|
||||
if (siteConfig('PSEUDO_STATIC', false, NOTION_CONFIG)) {
|
||||
if (
|
||||
!properties?.href?.endsWith('.html') &&
|
||||
properties?.href !== '' &&
|
||||
properties?.href !== '#' &&
|
||||
properties?.href !== '/'
|
||||
) {
|
||||
properties.href += '.html'
|
||||
}
|
||||
}
|
||||
|
||||
// 相对路径转绝对路径:url左侧拼接 /
|
||||
properties.href = convertUrlStartWithOneSlash(properties?.href)
|
||||
}
|
||||
|
||||
// 如果跳转链接是多语言,则在新窗口打开
|
||||
@@ -239,6 +235,10 @@ export function adjustPageProperties(properties, NOTION_CONFIG) {
|
||||
* @returns
|
||||
*/
|
||||
function generateCustomizeSlug(postProperties, NOTION_CONFIG) {
|
||||
// 外链不处理
|
||||
if (checkStartWithHttp(postProperties.slug)) {
|
||||
return postProperties.slug
|
||||
}
|
||||
let fullPrefix = ''
|
||||
const allSlugPatterns = siteConfig(
|
||||
'POST_URL_PREFIX',
|
||||
@@ -290,5 +290,10 @@ function generateCustomizeSlug(postProperties, NOTION_CONFIG) {
|
||||
if (fullPrefix.endsWith('/')) {
|
||||
fullPrefix = fullPrefix.substring(0, fullPrefix.length - 1) // 去掉尾部部的"/"
|
||||
}
|
||||
return `${fullPrefix}/${postProperties.slug ?? postProperties.id}`
|
||||
|
||||
if(fullPrefix){
|
||||
return `${fullPrefix}/${postProperties.slug ?? postProperties.id}`
|
||||
}else{
|
||||
return `${postProperties.slug ?? postProperties.id}`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +110,8 @@ const compressImage = (image, width, quality = 50, fmt = 'webp') => {
|
||||
return image
|
||||
}
|
||||
|
||||
if (image.includes(".svg")) return image
|
||||
|
||||
if (!width || width === 0) {
|
||||
width = siteConfig('IMAGE_COMPRESS_WIDTH')
|
||||
}
|
||||
|
||||
@@ -47,7 +47,12 @@ export const memorize = Component => {
|
||||
return memo(MemoizedComponent)
|
||||
}
|
||||
|
||||
// 转换外链
|
||||
/**
|
||||
* 诸如 article/https://test.com 等被错误拼接前缀的slug进行处理
|
||||
* 转换为 https://test.com
|
||||
* @param {*} str
|
||||
* @returns
|
||||
*/
|
||||
export function sliceUrlFromHttp(str) {
|
||||
// 检查字符串是否包含http
|
||||
if (str?.includes('http:') || str?.includes('https:')) {
|
||||
@@ -99,7 +104,7 @@ export function checkStartWithHttp(str) {
|
||||
// 检查字符串是否包含http
|
||||
if (str?.indexOf('http:') === 0 || str?.indexOf('https:') === 0) {
|
||||
// 如果包含,找到http的位置
|
||||
return str?.indexOf('http') > -1
|
||||
return true
|
||||
} else {
|
||||
// 不包含
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user