import { useRouter } from 'next/router' import { useEffect, useRef } from 'react' import BlogPostListPage from './components/BlogPostListPage' import LayoutBase from './LayoutBase' import SearchInput from './components/SearchInput' import { useGlobal } from '@/lib/global' import TagItemMini from './components/TagItemMini' import Card from './components/Card' import Link from 'next/link' export const LayoutSearch = props => { const { keyword, tags, categories } = props const { locale } = useGlobal() const router = useRouter() const currentSearch = keyword || router?.query?.s const cRef = useRef(null) useEffect(() => { setTimeout(() => { // 自动聚焦到搜索框 cRef?.current?.focus() if (currentSearch) { const targets = document.getElementsByClassName('replace') for (const container of targets) { if (container && container.innerHTML) { const re = new RegExp(`${currentSearch}`, 'gim') container.innerHTML = container.innerHTML.replace( re, `${currentSearch}` ) } } } }, 100) }) return (
{/* 分类 */}
{locale.COMMON.CATEGORY}:
{categories?.map(category => { return (
{category.name}({category.count})
) })}
{/* 标签 */}
{locale.COMMON.TAGS}:
{tags?.map(tag => { return (
) })}
) }