nav-theme postCard http link

This commit is contained in:
tangly1024
2024-01-31 21:54:28 +08:00
parent c0c18e3fbe
commit f5a710ce90
2 changed files with 6 additions and 55 deletions

View File

@@ -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 (
<Link href={`${siteConfig('SUB_PATH', '')}/${removeHttp(post.slug)}`} target={(checkRemoveHttp(post.slug) ? '_blank' : '_self')} passHref>
<Link href={`${url}`} target={(checkContainHttp(post.slug) ? '_blank' : '_self')} passHref>
<div key={post.id} className={`${className} h-full rounded-2xl p-4 dark:bg-neutral-800 cursor-pointer bg-white hover:bg-white dark:hover:bg-gray-800 ${currentSelected ? 'bg-green-50 text-green-500' : ''}`}>
<div className="stack-entry w-full flex space-x-3 select-none dark:text-neutral-200">
<NotionIcon icon={pageIcon} size='10' className='text-6xl w-11 h-11 mx-1 my-0 flex-none' />
@@ -21,7 +22,7 @@ const BlogPostCard = ({ post, className }) => {
</div>
</Link>
)
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的位置