From f5a710ce904a412ce9e6100994d11fe3f9c4a4a8 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 31 Jan 2024 21:54:28 +0800 Subject: [PATCH 1/2] nav-theme postCard http link --- themes/nav/components/BlogPostCard.js | 7 +-- themes/nav/components/BlogPostListAll.js | 54 +----------------------- 2 files changed, 6 insertions(+), 55 deletions(-) diff --git a/themes/nav/components/BlogPostCard.js b/themes/nav/components/BlogPostCard.js index e0040f7a..d52ef0e6 100755 --- a/themes/nav/components/BlogPostCard.js +++ b/themes/nav/components/BlogPostCard.js @@ -8,8 +8,9 @@ const BlogPostCard = ({ post, className }) => { const currentSelected = router.asPath.split('?')[0] === '/' + post.slug let pageIcon = post.pageIcon !== '' ? post.pageIcon : siteConfig('IMG_LAZY_LOAD_PLACEHOLDER') pageIcon = post.pageIcon.indexOf('amazonaws.com') !== -1 ? post.pageIcon + '&width=88' : post.pageIcon + const url = checkContainHttp(post.slug) ? sliceUrlFromHttp(post.slug) : `${siteConfig('SUB_PATH', '')}/${post.slug}` return ( - +
@@ -21,7 +22,7 @@ const BlogPostCard = ({ post, className }) => {
) - function removeHttp(str) { + function sliceUrlFromHttp(str) { // 检查字符串是否包含http if (str.includes('http')) { // 如果包含,找到http的位置 @@ -33,7 +34,7 @@ const BlogPostCard = ({ post, className }) => { return str; } } - function checkRemoveHttp(str) { + function checkContainHttp(str) { // 检查字符串是否包含http if (str.includes('http')) { // 如果包含,找到http的位置 diff --git a/themes/nav/components/BlogPostListAll.js b/themes/nav/components/BlogPostListAll.js index d1249c56..9b3bc85c 100755 --- a/themes/nav/components/BlogPostListAll.js +++ b/themes/nav/components/BlogPostListAll.js @@ -13,15 +13,9 @@ import { siteConfig } from '@/lib/config' * @constructor */ const BlogPostListAll = (props) => { - // const { customMenu, posts, category, tag, allNavPages, categoryOptions } = props - // const [filteredNavPages, setFilteredNavPages] = useState(allNavPages) const { customMenu } = props - - // const [filteredNavPages, setFilteredNavPages] = useState(allNavPages) const { filteredNavPages, setFilteredNavPages, allNavPages } = useNavGlobal() - // const [filteredNavPages] = useState(allNavPages) - // const router = useRouter() // 对自定义分类格式化,方便后续使用分类名称做索引,检索同步图标信息 // 目前只支持二级分类 const links = customMenu @@ -29,9 +23,6 @@ const BlogPostListAll = (props) => { // for循环遍历数组 links?.map((link, i) => { const linkTitle = link.title + '' - // console.log('####### link') - // console.log(link) - // filterLinks[linkTitle] = link filterLinks[linkTitle] = { title: link.title, icon: link.icon, pageIcon: link.pageIcon } if (link?.subMenus) { link.subMenus?.map((group, index) => { @@ -44,22 +35,10 @@ const BlogPostListAll = (props) => { } }) - console.log('####### filterLinks') - console.log(filterLinks) - - // console.log('####### filterLinks') - // console.log(filterLinks) - const selectedSth = false const groupedArray = filteredNavPages?.reduce((groups, item) => { const categoryName = item?.category ? item?.category : '' // 将category转换为字符串 const categoryIcon = filterLinks[categoryName]?.icon ? filterLinks[categoryName]?.icon : '' // 将pageIcon转换为字符串 - - // console.log('####### categoryName') - // console.log(categoryName) - // console.log('####### categoryIcon') - // console.log(categoryIcon) - let existingGroup = null // 开启自动分组排序 if (JSON.parse(siteConfig('NAV_AUTO_SORT', null, CONFIG))) { @@ -81,17 +60,9 @@ const BlogPostListAll = (props) => { groupedArray?.map((group) => { // 自定义分类图标与post的category共用 // 判断自定义分类与Post中category同名的项,将icon的值传递给post - // let groupTitle = group?.category - // item.icon = filterLinks[categoryName]?.icon ? filterLinks[categoryName]?.icon : '' - // console.log('####### item') - // console.log(item) + const groupSelected = false - // for (const post of group?.items) { - // if (router.asPath.split('?')[0] === '/' + post.slug) { - // groupSelected = true - // selectedSth = true - // } - // } + group.selected = groupSelected return null }) @@ -110,27 +81,6 @@ const BlogPostListAll = (props) => {
} - // 处理自定义导航菜单项 - // let keyword = searchInputRef.current.value - // if (keyword) { - // keyword = keyword.trim() - // } else { - // setFilteredNavPages(allNavPages) - // } - // for (const filterGroup of filterAllNavPages) { - // for (let i = filterGroup.items.length - 1; i >= 0; i--) { - // const post = filterGroup.items[i] - // const articleInfo = post.title + '' - // const hit = articleInfo.toLowerCase().indexOf(keyword.toLowerCase()) > -1 - // if (!hit) { - // // 删除 - // filterGroup.items.splice(i, 1) - // } - // } - // if (filterGroup.items && filterGroup.items.length > 0) { - // filterPosts.push(filterGroup) - // } - // } } export default BlogPostListAll From ea859a6c3c54bb3221e2871e6f61959939bfbdb5 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 31 Jan 2024 21:59:11 +0800 Subject: [PATCH 2/2] Annotation --- themes/nav/components/BlogPostCard.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/themes/nav/components/BlogPostCard.js b/themes/nav/components/BlogPostCard.js index d52ef0e6..cc3934e0 100755 --- a/themes/nav/components/BlogPostCard.js +++ b/themes/nav/components/BlogPostCard.js @@ -22,6 +22,8 @@ const BlogPostCard = ({ post, className }) => { ) + + // 检查连接是否是外链 function sliceUrlFromHttp(str) { // 检查字符串是否包含http if (str.includes('http')) {