Skip to content

Commit

Permalink
Merge branch 'tangly1024:main' into mine
Browse files Browse the repository at this point in the history
  • Loading branch information
narohaz committed May 9, 2024
2 parents 0ac457e + 2da448f commit 8a6a165
Show file tree
Hide file tree
Showing 135 changed files with 3,240 additions and 2,375 deletions.
2 changes: 1 addition & 1 deletion .env.local
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables
NEXT_PUBLIC_VERSION=4.4.6
NEXT_PUBLIC_VERSION=4.5.0


# 可在此添加环境变量,去掉最左边的(# )注释即可
Expand Down
83 changes: 57 additions & 26 deletions components/GlobalHead.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import { useRouter } from 'next/router'
import { useEffect } from 'react'

/**
* 页面的Head头,通常有用于SEO
* 页面的Head头,有用于SEO
* @param {*} param0
* @returns
*/
const GlobalHead = props => {
const { children, siteInfo, post } = props
const { children, siteInfo, post, NOTION_CONFIG } = props
let url = siteConfig('PATH')?.length
? `${siteConfig('LINK')}/${siteConfig('SUB_PATH', '')}`
: siteConfig('LINK')
let image
const router = useRouter()
const meta = getSEOMeta(props, router, useGlobal())
const meta = getSEOMeta(props, router, useGlobal()?.locale)
if (meta) {
url = `${url}/${meta.slug}`
image = meta.image || '/bg_image.jpg'
Expand All @@ -29,7 +29,45 @@ const GlobalHead = props => {
const category = meta?.category || siteConfig('KEYWORDS') // section 主要是像是 category 這樣的分類,Facebook 用這個來抓連結的分類
const favicon = siteConfig('BLOG_FAVICON')
const webFontUrl = siteConfig('FONT_URL')
const BACKGROUND_DARK = siteConfig('BACKGROUND_DARK', '', NOTION_CONFIG)

const SEO_BAIDU_SITE_VERIFICATION = siteConfig(
'SEO_BAIDU_SITE_VERIFICATION',
null,
NOTION_CONFIG
)

const SEO_GOOGLE_SITE_VERIFICATION = siteConfig(
'SEO_GOOGLE_SITE_VERIFICATION',
null,
NOTION_CONFIG
)

const BLOG_FAVICON = siteConfig('BLOG_FAVICON', null, NOTION_CONFIG)

const COMMENT_WEBMENTION_ENABLE = siteConfig(
'COMMENT_WEBMENTION_ENABLE',
null,
NOTION_CONFIG
)

const COMMENT_WEBMENTION_HOSTNAME = siteConfig(
'COMMENT_WEBMENTION_HOSTNAME',
null,
NOTION_CONFIG
)
const COMMENT_WEBMENTION_AUTH = siteConfig(
'COMMENT_WEBMENTION_AUTH',
null,
NOTION_CONFIG
)
const ANALYTICS_BUSUANZI_ENABLE = siteConfig(
'ANALYTICS_BUSUANZI_ENABLE',
null,
NOTION_CONFIG
)

const FACEBOOK_PAGE = siteConfig('FACEBOOK_PAGE', null, NOTION_CONFIG)
// SEO关键词
let keywords = meta?.tags || siteConfig('KEYWORDS')
if (post?.tags && post?.tags?.length > 0) {
Expand Down Expand Up @@ -59,24 +97,23 @@ const GlobalHead = props => {
<Head>
<link rel='icon' href={favicon} />
<title>{title}</title>
<meta name='theme-color' content={siteConfig('BACKGROUND_DARK')} />

<meta name='theme-color' content={BACKGROUND_DARK} />
<meta
name='viewport'
content='width=device-width, initial-scale=1.0, maximum-scale=5.0, minimum-scale=1.0'
/>
<meta name='robots' content='follow, index' />
<meta charSet='UTF-8' />
{siteConfig('SEO_GOOGLE_SITE_VERIFICATION') && (
{SEO_GOOGLE_SITE_VERIFICATION && (
<meta
name='google-site-verification'
content={siteConfig('SEO_GOOGLE_SITE_VERIFICATION')}
content={SEO_GOOGLE_SITE_VERIFICATION}
/>
)}
{siteConfig('SEO_BAIDU_SITE_VERIFICATION') && (
{SEO_BAIDU_SITE_VERIFICATION && (
<meta
name='baidu-site-verification'
content={siteConfig('SEO_BAIDU_SITE_VERIFICATION')}
content={SEO_BAIDU_SITE_VERIFICATION}
/>
)}
<meta name='keywords' content={keywords} />
Expand All @@ -86,44 +123,39 @@ const GlobalHead = props => {
<meta property='og:description' content={description} />
<meta property='og:url' content={url} />
<meta property='og:image' content={image} />
<meta property='og:site_name' content={siteConfig('TITLE')} />
<meta property='og:site_name' content={title} />
<meta property='og:type' content={type} />
<meta name='twitter:card' content='summary_large_image' />
<meta name='twitter:description' content={description} />
<meta name='twitter:title' content={title} />

<link rel='icon' href={`${siteConfig('BLOG_FAVICON')}`} />
<link rel='icon' href={BLOG_FAVICON} />

{siteConfig('COMMENT_WEBMENTION_ENABLE') && (
{COMMENT_WEBMENTION_ENABLE && (
<>
<link
rel='webmention'
href={`https://webmention.io/${siteConfig('COMMENT_WEBMENTION_HOSTNAME')}/webmention`}
href={`https://webmention.io/${COMMENT_WEBMENTION_HOSTNAME}/webmention`}
/>
<link
rel='pingback'
href={`https://webmention.io/${siteConfig('COMMENT_WEBMENTION_HOSTNAME')}/xmlrpc`}
href={`https://webmention.io/${COMMENT_WEBMENTION_HOSTNAME}/xmlrpc`}
/>
{COMMENT_WEBMENTION_AUTH && (
<link href={COMMENT_WEBMENTION_AUTH} rel='me' />
)}
</>
)}

{siteConfig('COMMENT_WEBMENTION_ENABLE') &&
siteConfig('COMMENT_WEBMENTION_AUTH') !== '' && (
<link href={siteConfig('COMMENT_WEBMENTION_AUTH')} rel='me' />
)}

{JSON.parse(siteConfig('ANALYTICS_BUSUANZI_ENABLE')) && (
{ANALYTICS_BUSUANZI_ENABLE && (
<meta name='referrer' content='no-referrer-when-downgrade' />
)}
{meta?.type === 'Post' && (
<>
<meta property='article:published_time' content={meta.publishDay} />
<meta property='article:author' content={siteConfig('AUTHOR')} />
<meta property='article:section' content={category} />
<meta
property='article:publisher'
content={siteConfig('FACEBOOK_PAGE')}
/>
<meta property='article:publisher' content={FACEBOOK_PAGE} />
</>
)}
{children}
Expand All @@ -136,8 +168,7 @@ const GlobalHead = props => {
* @param {*} props
* @param {*} router
*/
const getSEOMeta = (props, router, global) => {
const { locale } = global
const getSEOMeta = (props, router, locale) => {
const { post, siteInfo, tag, category, page } = props
const keyword = router?.query?.s

Expand Down
88 changes: 60 additions & 28 deletions components/NotionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ const Equation = dynamic(
{ ssr: false }
)

const Pdf = dynamic(() => import('react-notion-x/build/third-party/pdf').then(m => m.Pdf), {
ssr: false
})
const Pdf = dynamic(
() => import('react-notion-x/build/third-party/pdf').then(m => m.Pdf),
{
ssr: false
}
)

// https://github.com/txs
// import PrismMac from '@/components/PrismMac'
Expand All @@ -46,13 +49,25 @@ const TweetEmbed = dynamic(() => import('react-tweet-embed'), {
/**
* 文内google广告
*/
const AdEmbed = dynamic(() => import('@/components/GoogleAdsense').then(m => m.AdEmbed), { ssr: true })
const AdEmbed = dynamic(
() => import('@/components/GoogleAdsense').then(m => m.AdEmbed),
{ ssr: true }
)

const Collection = dynamic(() => import('react-notion-x/build/third-party/collection').then(m => m.Collection), {
ssr: true
})
const Collection = dynamic(
() =>
import('react-notion-x/build/third-party/collection').then(
m => m.Collection
),
{
ssr: true
}
)

const Modal = dynamic(() => import('react-notion-x/build/third-party/modal').then(m => m.Modal), { ssr: false })
const Modal = dynamic(
() => import('react-notion-x/build/third-party/modal').then(m => m.Modal),
{ ssr: false }
)

const Tweet = ({ id }) => {
return <TweetEmbed tweetId={id} />
Expand All @@ -69,29 +84,32 @@ const NotionPage = ({ post, className }) => {
}, [])

const zoom =
typeof window !== 'undefined' &&
isBrowser &&
mediumZoom({
container: '.notion-viewport',
// container: '.notion-viewport',
background: 'rgba(0, 0, 0, 0.2)',
margin: getMediumZoomMargin()
})

const zoomRef = useRef(zoom ? zoom.clone() : null)

useEffect(() => {
if (!isBrowser) return

// 将相册gallery下的图片加入放大功能
if (siteConfig('POST_DISABLE_GALLERY_CLICK')) {
setTimeout(() => {
if (isBrowser) {
const imgList = document?.querySelectorAll('.notion-collection-card-cover img')
const imgList = document?.querySelectorAll(
'.notion-collection-card-cover img'
)
if (imgList && zoomRef.current) {
for (let i = 0; i < imgList.length; i++) {
zoomRef.current.attach(imgList[i])
}
}

const cards = document.getElementsByClassName('notion-collection-card')
const cards = document.getElementsByClassName(
'notion-collection-card'
)
for (const e of cards) {
e.removeAttribute('href')
}
Expand All @@ -108,10 +126,16 @@ const NotionPage = ({ post, className }) => {
const allAnchorTags = document.getElementsByTagName('a') // 或者使用 document.querySelectorAll('a') 获取 NodeList
for (const anchorTag of allAnchorTags) {
if (anchorTag?.target === '_blank') {
const hrefWithoutQueryHash = anchorTag.href.split('?')[0].split('#')[0]
const hrefWithRelativeHash = currentURL.split('#')[0] + anchorTag.href.split('#')[1]

if (currentURL === hrefWithoutQueryHash || currentURL === hrefWithRelativeHash) {
const hrefWithoutQueryHash = anchorTag.href
.split('?')[0]
.split('#')[0]
const hrefWithRelativeHash =
currentURL.split('#')[0] + anchorTag.href.split('#')[1]

if (
currentURL === hrefWithoutQueryHash ||
currentURL === hrefWithRelativeHash
) {
anchorTag.target = '_self'
}
}
Expand All @@ -121,36 +145,44 @@ const NotionPage = ({ post, className }) => {
// 放大图片:调整图片质量
const observer = new MutationObserver((mutationsList, observer) => {
mutationsList.forEach(mutation => {
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
if (
mutation.type === 'attributes' &&
mutation.attributeName === 'class'
) {
if (mutation.target.classList.contains('medium-zoom-image--opened')) {
// 等待动画完成后替换为更高清的图像
setTimeout(() => {
// 获取该元素的 src 属性
const src = mutation?.target?.getAttribute('src')
// 替换为更高清的图像
mutation?.target?.setAttribute('src', compressImage(src, siteConfig('IMAGE_ZOOM_IN_WIDTH', 1200)))
mutation?.target?.setAttribute(
'src',
compressImage(src, siteConfig('IMAGE_ZOOM_IN_WIDTH', 1200))
)
}, 800)
}
}
})
})

// 监视整个文档中的元素和属性的变化
observer.observe(document.body, { attributes: true, subtree: true, attributeFilter: ['class'] })
observer.observe(document.body, {
attributes: true,
subtree: true,
attributeFilter: ['class']
})

return () => {
observer.disconnect()
}
}, [])

if (!post || !post.blockMap) {
return <>{post?.summary || ''}</>
}
}, [post])

return (
<div id='notion-article' className={`mx-auto overflow-hidden ${className || ''}`}>
<div
id='notion-article'
className={`mx-auto overflow-hidden ${className || ''}`}>
<NotionRenderer
recordMap={post.blockMap}
recordMap={post?.blockMap}
mapPageUrl={mapPageUrl}
mapImageUrl={mapImgUrl}
components={{
Expand Down
22 changes: 3 additions & 19 deletions lib/db/getSiteData.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,11 @@ function getCustomNav({ allPages }) {
if (allPages && allPages.length > 0) {
allPages.forEach(p => {
p.to = p.slug
if (p?.slug?.indexOf('http') === 0) {
p.target = '_blank'
} else {
p.target = '_self'
if (p?.slug?.indexOf('/') !== 0) {
p.to = '/' + p.slug
}
}
customNav.push({
icon: p.icon || null,
name: p.title,
to: p.slug,
target: '_blank',
href: p.href,
target: p.target,
show: true
})
})
Expand All @@ -192,15 +184,6 @@ function getCustomMenu({ collectionData, NOTION_CONFIG }) {
if (menuPages && menuPages.length > 0) {
menuPages.forEach(e => {
e.show = true
if (e?.slug?.indexOf('http') === 0) {
e.target = '_blank'
e.to = e.slug
} else {
e.target = '_self'
if (e?.slug?.indexOf('http') !== 0 && e?.slug?.indexOf('/') !== 0) {
e.to = '/' + e.slug
}
}
if (e.type === BLOG.NOTION_PROPERTY_NAME.type_menu) {
menus.push(e)
} else if (e.type === BLOG.NOTION_PROPERTY_NAME.type_sub_menu) {
Expand Down Expand Up @@ -312,6 +295,7 @@ export function getNavPages({ allPages }) {
tags: item.tags || null,
summary: item.summary || null,
slug: item.slug,
href: item.href,
pageIcon: item.pageIcon || '',
lastEditedDate: item.lastEditedDate,
publishDate: item.publishDate,
Expand Down

0 comments on commit 8a6a165

Please sign in to comment.