Skip to content

Commit

Permalink
Merge pull request tangly1024#3015 from tangly1024/fix/maginze-theme
Browse files Browse the repository at this point in the history
部分组件bug修复
  • Loading branch information
tangly1024 authored Nov 23, 2024
2 parents 0d832e4 + 401d714 commit 4488e14
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 37 deletions.
5 changes: 3 additions & 2 deletions components/ExternalPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { GlobalStyle } from './GlobalStyle'
import { initGoogleAdsense } from './GoogleAdsense'

import Head from 'next/head'
import ExternalScript from './ExternalScript'
import WebWhiz from './Webwhiz'

/**
Expand Down Expand Up @@ -258,10 +259,10 @@ const ExternalPlugin = props => {
{/* 提前连接到广告服务器 */}
<link rel='preconnect' href='https://cdn.wwads.cn' />
</Head>
<script
<ExternalScript
type='text/javascript'
src='https://cdn.wwads.cn/js/makemoney.js'
async></script>
/>
</>
)}

Expand Down
4 changes: 2 additions & 2 deletions components/ExternalScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isBrowser } from '@/lib/utils'
* 传入参数将转为 <script>标签。
* @returns
*/
const ExternalScript = (props) => {
const ExternalScript = props => {
const { src } = props
if (!isBrowser || !src) {
return null
Expand All @@ -22,7 +22,7 @@ const ExternalScript = (props) => {
script.setAttribute(key, value)
})
document.head.appendChild(script)
console.log('加载外部脚本', props, script)
// console.log('加载外部脚本', props, script)
return null
}

Expand Down
51 changes: 26 additions & 25 deletions components/SEO.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@ const SEO = props => {
let image
const router = useRouter()
const meta = getSEOMeta(props, router, useGlobal()?.locale)
const webFontUrl = siteConfig('FONT_URL')

useEffect(() => {
// 使用WebFontLoader字体加载
loadExternalResource(
'https://cdnjs.cloudflare.com/ajax/libs/webfont/1.6.28/webfontloader.js',
'js'
).then(url => {
const WebFont = window?.WebFont
if (WebFont) {
// console.log('LoadWebFont', webFontUrl)
WebFont.load({
custom: {
// families: ['"LXGW WenKai"'],
urls: webFontUrl
}
})
}
})
}, [])

// SEO关键词
let keywords = meta?.tags || siteConfig('KEYWORDS')
if (post?.tags && post?.tags?.length > 0) {
keywords = post?.tags?.join(',')
}
if (meta) {
url = `${url}/${meta.slug}`
image = meta.image || '/bg_image.jpg'
Expand All @@ -28,7 +54,6 @@ const SEO = props => {
const lang = siteConfig('LANG').replace('-', '_') // Facebook OpenGraph 要 zh_CN 這樣的格式才抓得到語言
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(
Expand Down Expand Up @@ -68,30 +93,6 @@ const SEO = props => {
)

const FACEBOOK_PAGE = siteConfig('FACEBOOK_PAGE', null, NOTION_CONFIG)
// SEO关键词
let keywords = meta?.tags || siteConfig('KEYWORDS')
if (post?.tags && post?.tags?.length > 0) {
keywords = post?.tags?.join(',')
}

useEffect(() => {
// 使用WebFontLoader字体加载
loadExternalResource(
'https://cdnjs.cloudflare.com/ajax/libs/webfont/1.6.28/webfontloader.js',
'js'
).then(url => {
const WebFont = window?.WebFont
if (WebFont) {
// console.log('LoadWebFont', webFontUrl)
WebFont.load({
custom: {
// families: ['"LXGW WenKai"'],
urls: webFontUrl
}
})
}
})
}, [])

return (
<Head>
Expand Down
15 changes: 12 additions & 3 deletions components/WWAds.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ import { siteConfig } from '@/lib/config'
* @param {boolean} sticky - 是否粘性定位
* @returns {JSX.Element | null} - 返回渲染的 JSX 元素或 null
*/
export default function WWAds({ orientation = 'vertical', sticky = false, className }) {
export default function WWAds({
orientation = 'vertical',
sticky = false,
className
}) {
const AD_WWADS_ID = siteConfig('AD_WWADS_ID')

if (!AD_WWADS_ID) {
return null
}

return <div data-id={AD_WWADS_ID} className={`wwads-cn
return (
<div
data-id={AD_WWADS_ID}
className={`wwads-cn
${orientation === 'vertical' ? 'wwads-vertical' : 'wwads-horizontal'}
${sticky ? 'wwads-sticky' : ''} z-10 ${className || ''}`} />
${sticky ? 'wwads-sticky' : ''} z-10 ${className || ''}`}
/>
)
}
8 changes: 4 additions & 4 deletions themes/magzine/components/MenuItemCollapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ export const MenuItemCollapse = props => {

const router = useRouter()

if (!link || !link.show) {
return null
}

const selected = router.pathname === link.href || router.asPath === link.href

const toggleShow = () => {
Expand All @@ -36,6 +32,10 @@ export const MenuItemCollapse = props => {
setOpen(false)
}, [router])

if (!link || !link.show) {
return null
}

return (
<>
<div
Expand Down
3 changes: 2 additions & 1 deletion themes/magzine/components/PostListRecommend.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import Swiper from './Swiper'
const PostListRecommend = ({ latestPosts, allNavPages }) => {
// 获取推荐文章
const recommendPosts = getTopPosts({ latestPosts, allNavPages })
const title = siteConfig('MAGZINE_RECOMMEND_POST_TITLE', '', CONFIG)

if (!recommendPosts || recommendPosts.length === 0) {
return <PostListEmpty />
}
const title = siteConfig('MAGZINE_RECOMMEND_POST_TITLE', '', CONFIG)

return (
<div className={`w-full py-10 px-2 bg-[#F6F6F1] dark:bg-black`}>
Expand Down

0 comments on commit 4488e14

Please sign in to comment.