Skip to content

Commit f2e4f23

Browse files
committed
2 parents 18500ec + 6c03068 commit f2e4f23

File tree

12 files changed

+583
-411
lines changed

12 files changed

+583
-411
lines changed

lib/lang.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,22 @@ export function generateLocaleDict(langString) {
6969
*/
7070
export function initLocale(lang, locale, changeLang, changeLocale) {
7171
if (isBrowser) {
72-
// 用户请求的预研
73-
const queryLang =
72+
// 用户请求的语言
73+
let queryLang =
7474
getQueryVariable('locale') ||
7575
getQueryVariable('lang') ||
7676
loadLangFromLocalStorage()
77+
78+
if (queryLang) {
79+
// 用正则表达式匹配有效的语言标识符例如zh-CN(可选的 -CN 部分)
80+
queryLang = queryLang.match(/[a-zA-Z]{2}(?:-[a-zA-Z]{2})?/)
81+
if (queryLang) {
82+
queryLang = queryLang[0]
83+
}
84+
}
85+
7786
let currentLang = lang
78-
if (queryLang && queryLang !== 'undefined' && queryLang !== lang) {
87+
if (queryLang && queryLang !== lang) {
7988
currentLang = queryLang
8089
}
8190

lib/notion/mapImage.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ const mapImgUrl = (img, block, type = 'block', needCompress = true) => {
2424
}
2525

2626
// Notion 图床转换为永久地址
27-
const hasConverted = ret.indexOf('https://www.notion.so/image') === 0
27+
const hasConverted =
28+
ret.indexOf('https://www.notion.so/image') === 0 ||
29+
ret.includes('notion.site/images/page-cover/')
2830
// 需要转化的URL ; 识别aws图床地址,或者bookmark类型的外链图片
2931
const needConvert =
3032
!hasConverted &&
31-
(ret.indexOf('secure.notion-static.com') > 0 ||
32-
ret.indexOf('prod-files-secure') > 0 ||
33-
block.type === 'bookmark')
33+
(block.type === 'bookmark' ||
34+
ret.includes('secure.notion-static.com') ||
35+
ret.includes('prod-files-secure'))
3436

3537
// 使用Notion图传
3638
if (needConvert) {

pages/[prefix]/[slug]/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export async function getStaticPaths() {
2626

2727
const from = 'slug-paths'
2828
const { allPages } = await getGlobalData({ from })
29+
// 根据slug中的 / 分割成prefix和slug两个字段 ; 例如 article/test
2930
const paths = allPages
3031
?.filter(row => checkSlug(row))
3132
.map(row => ({

themes/commerce/index.js

+39-41
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
import CONFIG from './config'
22

3-
import { useEffect, useRef } from 'react'
4-
import Footer from './components/Footer'
3+
import LazyImage from '@/components/LazyImage'
4+
import replaceSearchResult from '@/components/Mark'
5+
import NotionPage from '@/components/NotionPage'
6+
import { siteConfig } from '@/lib/config'
57
import { useGlobal } from '@/lib/global'
68
import { isBrowser, scanAndConvertToLinks } from '@/lib/utils'
9+
import { Transition } from '@headlessui/react'
10+
import Link from 'next/link'
11+
import { useRouter } from 'next/router'
12+
import { useEffect, useRef } from 'react'
13+
import { ArticleLock } from './components/ArticleLock'
14+
import BlogPostArchive from './components/BlogPostArchive'
715
import BlogPostListPage from './components/BlogPostListPage'
816
import BlogPostListScroll from './components/BlogPostListScroll'
9-
import Hero from './components/Hero'
10-
import { useRouter } from 'next/router'
1117
import Card from './components/Card'
18+
import Footer from './components/Footer'
19+
import Header from './components/Header'
20+
import Hero from './components/Hero'
21+
import PostHeader from './components/PostHeader'
22+
import ProductCategories from './components/ProductCategories'
23+
import ProductCenter from './components/ProductCenter'
1224
import RightFloatArea from './components/RightFloatArea'
1325
import SearchNav from './components/SearchNav'
14-
import BlogPostArchive from './components/BlogPostArchive'
15-
import { ArticleLock } from './components/ArticleLock'
16-
import PostHeader from './components/PostHeader'
17-
import TocDrawer from './components/TocDrawer'
18-
import NotionPage from '@/components/NotionPage'
19-
import TagItemMini from './components/TagItemMini'
20-
import Link from 'next/link'
2126
import SlotBar from './components/SlotBar'
22-
import { Transition } from '@headlessui/react'
27+
import TagItemMini from './components/TagItemMini'
28+
import TocDrawer from './components/TocDrawer'
2329
import { Style } from './style'
24-
import replaceSearchResult from '@/components/Mark'
25-
import { siteConfig } from '@/lib/config'
26-
import Header from './components/Header'
27-
import ProductCenter from './components/ProductCenter'
28-
import LazyImage from '@/components/LazyImage'
29-
import ProductCategories from './components/ProductCategories'
3030

3131
/**
3232
* 基础布局 采用左右两侧布局,移动端使用顶部导航栏
@@ -35,17 +35,19 @@ import ProductCategories from './components/ProductCategories'
3535
* @constructor
3636
*/
3737
const LayoutBase = props => {
38-
const { children, post, floatSlot, slotTop, slotRight, meta, className } =
39-
props
38+
const { children, post, floatSlot, slotTop, className } = props
4039
const { onLoading } = useGlobal()
41-
40+
const router = useRouter()
4241
// 查找页面上的 链接,并便成为可点击
4342
useEffect(() => {
4443
scanAndConvertToLinks(document.getElementById('theme-commerce'))
45-
})
44+
}, [router])
45+
46+
const slotRight = router.route !== '/' && !post && (
47+
<ProductCategories {...props} />
48+
)
4649

4750
let headerSlot = null
48-
const router = useRouter()
4951
if (router.route === '/' && !post) {
5052
headerSlot = JSON.parse(siteConfig('COMMERCE_HOME_BANNER_ENABLE', true)) ? (
5153
<Hero {...props} />
@@ -146,18 +148,15 @@ const LayoutIndex = props => {
146148
* @returns
147149
*/
148150
const LayoutPostList = props => {
149-
const slotRight = <ProductCategories {...props} />
150151
return (
151-
<LayoutBase {...props} slotRight={slotRight}>
152-
<div className='bg-white border-[#D2232A] p-4'>
153-
<SlotBar {...props} />
154-
{siteConfig('POST_LIST_STYLE') === 'page' ? (
155-
<BlogPostListPage {...props} />
156-
) : (
157-
<BlogPostListScroll {...props} />
158-
)}
159-
</div>
160-
</LayoutBase>
152+
<div className='bg-white border-[#D2232A] p-4'>
153+
<SlotBar {...props} />
154+
{siteConfig('POST_LIST_STYLE') === 'page' ? (
155+
<BlogPostListPage {...props} />
156+
) : (
157+
<BlogPostListScroll {...props} />
158+
)}
159+
</div>
161160
)
162161
}
163162

@@ -241,7 +240,6 @@ const LayoutSlug = props => {
241240
const headerImage = post?.pageCover
242241
? post.pageCover
243242
: siteConfig('HOME_BANNER_IMAGE')
244-
const floatSlot = <></>
245243

246244
return (
247245
<>
@@ -395,14 +393,14 @@ const LayoutTagIndex = props => {
395393
}
396394

397395
export {
398-
CONFIG as THEME_CONFIG,
396+
Layout404,
397+
LayoutArchive,
399398
LayoutBase,
399+
LayoutCategoryIndex,
400400
LayoutIndex,
401+
LayoutPostList,
401402
LayoutSearch,
402-
LayoutArchive,
403403
LayoutSlug,
404-
Layout404,
405-
LayoutCategoryIndex,
406-
LayoutPostList,
407-
LayoutTagIndex
404+
LayoutTagIndex,
405+
CONFIG as THEME_CONFIG
408406
}

themes/gitbook/components/ArticleLock.js

+22-13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useEffect, useRef } from 'react'
1111
export const ArticleLock = props => {
1212
const { validPassword } = props
1313
const { locale } = useGlobal()
14+
console.log('locale', locale)
1415

1516
const submitPassword = () => {
1617
const p = document.getElementById('password')
@@ -29,25 +30,33 @@ export const ArticleLock = props => {
2930
passwordInputRef.current.focus()
3031
}, [])
3132

32-
return <div id='container' className='w-full flex justify-center items-center h-96 '>
33-
<div className='text-center space-y-3'>
34-
<div className='font-bold'>{locale.COMMON.ARTICLE_LOCK_TIPS}</div>
35-
<div className='flex mx-4'>
36-
<input id="password" type='password'
37-
onKeyDown={(e) => {
33+
return (
34+
<div
35+
id='container'
36+
className='w-full flex justify-center items-center h-96 '>
37+
<div className='text-center space-y-3'>
38+
<div className='font-bold'>{locale.COMMON.ARTICLE_LOCK_TIPS}</div>
39+
<div className='flex mx-4'>
40+
<input
41+
id='password'
42+
type='password'
43+
onKeyDown={e => {
3844
if (e.key === 'Enter') {
3945
submitPassword()
4046
}
4147
}}
4248
ref={passwordInputRef} // 绑定ref到passwordInputRef变量
43-
className='outline-none w-full text-sm pl-5 rounded-l transition focus:shadow-lg dark:text-gray-300 font-light leading-10 text-black bg-gray-100 dark:bg-gray-500'>
44-
</input>
45-
<div onClick={submitPassword} className="px-3 whitespace-nowrap cursor-pointer items-center justify-center py-2 bg-green-500 hover:bg-green-400 text-white rounded-r duration-300" >
46-
<i className={'duration-200 cursor-pointer fas fa-key'} >&nbsp;{locale.COMMON.SUBMIT}</i>
49+
className='outline-none w-full text-sm pl-5 rounded-l transition focus:shadow-lg dark:text-gray-300 font-light leading-10 text-black bg-gray-100 dark:bg-gray-500'></input>
50+
<div
51+
onClick={submitPassword}
52+
className='px-3 whitespace-nowrap cursor-pointer items-center justify-center py-2 bg-green-500 hover:bg-green-400 text-white rounded-r duration-300'>
53+
<i className={'duration-200 cursor-pointer fas fa-key'}>
54+
&nbsp;{locale.COMMON.SUBMIT}
55+
</i>
56+
</div>
4757
</div>
48-
</div>
49-
<div id='tips'>
58+
<div id='tips'></div>
5059
</div>
5160
</div>
52-
</div>
61+
)
5362
}

themes/gitbook/components/BlogPostCard.js

+24-13
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
1+
import Badge from '@/components/Badge'
2+
import NotionIcon from '@/components/NotionIcon'
13
import { siteConfig } from '@/lib/config'
4+
import { checkContainHttp, sliceUrlFromHttp } from '@/lib/utils'
25
import Link from 'next/link'
36
import { useRouter } from 'next/router'
4-
import { checkContainHttp, sliceUrlFromHttp } from '@/lib/utils'
5-
import NotionIcon from '@/components/NotionIcon'
6-
import Badge from '@/components/Badge'
77
import CONFIG from '../config'
88

99
const BlogPostCard = ({ post, className }) => {
1010
const router = useRouter()
1111
const currentSelected = router.asPath.split('?')[0] === '/' + post.slug
12-
const url = checkContainHttp(post.slug) ? sliceUrlFromHttp(post.slug) : `${siteConfig('SUB_PATH', '')}/${post.slug}`
12+
const url = checkContainHttp(post.slug)
13+
? sliceUrlFromHttp(post.slug)
14+
: `${siteConfig('SUB_PATH', '')}/${post.slug}`
1315
return (
14-
<Link href={url} passHref>
15-
<div key={post.id} className={`${className} relative py-1.5 cursor-pointer px-1.5 hover:bg-gray-50 rounded-md dark:hover:bg-gray-600 ${currentSelected ? 'bg-green-50 text-green-500 dark:bg-yellow-100 dark:text-yellow-600' : ''}`}>
16-
<div className="w-full select-none">
17-
{siteConfig('POST_TITLE_ICON') && <NotionIcon icon={post?.pageIcon} />} {post.title}
18-
</div>
19-
{/* 最新文章加个红点 */}
20-
{post?.isLatest && siteConfig('GITBOOK_LATEST_POST_RED_BADGE', false, CONFIG) && <Badge/>}
21-
</div>
22-
</Link>
16+
<Link href={url} passHref>
17+
<div
18+
key={post.id}
19+
className={`${className} relative py-1.5 cursor-pointer px-1.5 hover:bg-gray-50 rounded-md dark:hover:bg-yellow-100 dark:hover:text-yellow-600
20+
${currentSelected && 'bg-green-50 text-green-500 dark:bg-yellow-100 dark:text-yellow-600'}`}>
21+
<div className='w-full select-none'>
22+
{siteConfig('POST_TITLE_ICON') && (
23+
<NotionIcon icon={post?.pageIcon} />
24+
)}{' '}
25+
{post.title}
26+
</div>
27+
{/* 最新文章加个红点 */}
28+
{post?.isLatest &&
29+
siteConfig('GITBOOK_LATEST_POST_RED_BADGE', false, CONFIG) && (
30+
<Badge />
31+
)}
32+
</div>
33+
</Link>
2334
)
2435
}
2536

0 commit comments

Comments
 (0)