封装isBroswer()

This commit is contained in:
tlyong1992
2022-05-24 17:01:42 +08:00
parent a324cc127c
commit 8c19d88630
29 changed files with 110 additions and 114 deletions

View File

@@ -5,13 +5,14 @@ import TagGroups from './components/TagGroups'
import CategoryGroup from './components/CategoryGroup'
import BlogPostListScroll from './components/BlogPostListScroll'
import { useEffect } from 'react'
import { isBrowser } from '@/lib/utils'
export const LayoutSearch = (props) => {
const { locale } = useGlobal()
const { keyword } = props
useEffect(() => {
setTimeout(() => {
const container = typeof document !== 'undefined' && document.getElementById('container')
const container = isBrowser() && document.getElementById('container')
if (container && container.innerHTML) {
const re = new RegExp(`${keyword}`, 'gim')
container.innerHTML = container.innerHTML.replace(re, `<span class='text-red-500 border-b border-dashed'>${keyword}</span>`)

View File

@@ -1,4 +1,5 @@
import React, { useEffect, useState } from 'react'
import { isBrowser } from '@/lib/utils'
/**
* 顶部页面阅读进度条
@@ -9,7 +10,7 @@ const Progress = ({ targetRef, showPercent = true }) => {
const currentRef = targetRef?.current || targetRef
const [percent, changePercent] = useState(0)
const scrollListener = () => {
const target = currentRef || (typeof document !== 'undefined' && document.getElementById('container'))
const target = currentRef || (isBrowser() && document.getElementById('container'))
if (target) {
const clientHeight = target.clientHeight
const scrollY = window.pageYOffset