Skip to content

Commit

Permalink
Merge pull request #97 from tangly1024/preview
Browse files Browse the repository at this point in the history
样式调整
  • Loading branch information
tangly1024 authored Mar 23, 2022
2 parents 0781136 + 292a75f commit 86c42ae
Show file tree
Hide file tree
Showing 18 changed files with 562 additions and 97 deletions.
5 changes: 3 additions & 2 deletions blog.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ const BLOG = {
CONTACT_TELEGRAM: '',

// 悬浮挂件
WIDGET_PET: process.env.NEXT_PUBLIC_WIDGET_PET || false, // 是否显示宠物挂件
WIDGET_PET: process.env.NEXT_PUBLIC_WIDGET_PET || true, // 是否显示宠物挂件
WIDGET_PET_LINK: 'https://cdn.jsdelivr.net/npm/[email protected]/assets/wanko.model.json', // 挂件模型地址 @see https://github.com/xiazeyu/live2d-widget-models
WIDGET_PET_SWITCH_THEME: true, // 点击宠物挂件切换博客主题

// 评论互动 可同时开启 CUSDIS UTTERRANCES GITALK
COMMENT_CUSDIS_APP_ID: process.env.NEXT_PUBLIC_COMMENT_CUSDIS_APP_ID || '', // data-app-id 36位 see https://cusdis.com/
Expand Down Expand Up @@ -78,7 +79,7 @@ const BLOG = {
ADSENSE_GOOGLE_ID: process.env.NEXT_PUBLIC_ADSENSE_GOOGLE_ID || '', // 谷歌广告ID e.g ca-pub-xxxxxxxxxxxxxxxx

isProd: process.env.VERCEL_ENV === 'production', // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables) isProd: process.env.VERCEL_ENV === 'production' // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables)
VERSION: '2.8.0' // 版本号
VERSION: '2.8.1' // 版本号
}

module.exports = BLOG
11 changes: 6 additions & 5 deletions components/Live2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ export default function Live2D () {
const [init, setInit] = useState()
const { switchTheme } = useGlobal()

// if (typeof window !== 'undefined' && !hasLoad) {
// initLive2D()
// hasLoad = true
// }
function handleClick () {
if (BLOG.WIDGET_PET_SWITCH_THEME) {
switchTheme()
}
}

useEffect(() => {
if (!init) {
Expand All @@ -23,7 +24,7 @@ export default function Live2D () {
}
}, [init])

return <canvas id="live2d" className='cursor-pointer' width="280" height="250" onClick={switchTheme} alt='切换主题' title='切换主题'/>
return <canvas id="live2d" className='cursor-pointer' width="280" height="250" onClick={handleClick} alt='切换主题' title='切换主题'/>
}

function initLive2D () {
Expand Down
2 changes: 1 addition & 1 deletion lib/theme.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cookie from 'react-cookies'
import BLOG from '@/blog.config'

export const ALL_THEME = ['next', 'fukasawa', 'hexo', 'empty', 'medium']
export const ALL_THEME = ['hexo', 'next', 'medium', 'fukasawa', 'empty']
/**
* 初始化主题
* @param isDarkMode
Expand Down
73 changes: 68 additions & 5 deletions themes/empty/LayoutArchive.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,69 @@
export const LayoutArchive = (props) => {
// const { posts, tags, categories, postCount } = props
return <div {...props}>
Archive Page
</div>
import BLOG from '@/blog.config'
import { useGlobal } from '@/lib/global'
import Link from 'next/link'
import LayoutBase from './LayoutBase'

export const LayoutArchive = props => {
const { posts } = props
const { locale } = useGlobal()
const postsSortByDate = Object.create(posts)

postsSortByDate.sort((a, b) => {
const dateA = new Date(a?.date.start_date || a.createdTime)
const dateB = new Date(b?.date.start_date || b.createdTime)
return dateB - dateA
})

const meta = {
title: `${locale.NAV.ARCHIVE} | ${BLOG.TITLE}`,
description: BLOG.DESCRIPTION,
type: 'website'
}

const archivePosts = {}

postsSortByDate.forEach(post => {
const date = post.date.start_date.slice(0, 7)
if (archivePosts[date]) {
archivePosts[date].push(post)
} else {
archivePosts[date] = [post]
}
})
return (
<LayoutBase {...props} meta={meta}>
<div className="mb-10 pb-20 md:p-12 p-3 min-h-full">
{Object.keys(archivePosts).map(archiveTitle => (
<div key={archiveTitle}>
<div
className="pt-16 pb-4 text-3xl dark:text-gray-300"
id={archiveTitle}
>
{archiveTitle}
</div>
<ul>
{archivePosts[archiveTitle].map(post => (
<li
key={post.id}
className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500"
>
<div id={post?.date?.start_date}>
<span className="text-gray-400">
{post.date.start_date}
</span>{' '}
&nbsp;
<Link href={`${BLOG.PATH}/article/${post.slug}`} passHref>
<a className="dark:text-gray-400 dark:hover:text-gray-300 overflow-x-hidden hover:underline cursor-pointer text-gray-600">
{post.title}
</a>
</Link>
</div>
</li>
))}
</ul>
</div>
))}
</div>
</LayoutBase>
)
}
127 changes: 102 additions & 25 deletions themes/empty/LayoutBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,131 @@ import Live2D from '@/components/Live2D'
import Link from 'next/link'
import React from 'react'
import BLOG from '@/blog.config'
import { useGlobal } from '@/lib/global'
/**
* 基础布局 采用左右两侧布局,移动端使用顶部导航栏
* @returns {JSX.Element}
* @constructor
*/
const LayoutBase = props => {
const { children, meta } = props
const { children, meta, customNav } = props
const { locale } = useGlobal()
const d = new Date()
const currentYear = d.getFullYear()
const startYear = BLOG.SINCE && BLOG.SINCE !== currentYear && BLOG.SINCE + '-'

let links = [
{ icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search' },
{ icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive' },
{ icon: 'fas fa-folder', name: locale.COMMON.CATEGORY, to: '/category' },
{ icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag' }
]

if (customNav) {
links = links.concat(customNav)
}

return (
<div>
<CommonHead meta={meta} />
{/* 导航菜单 */}
<div className="w-full flex justify-center my-2">
<nav className="max-w-6xl space-x-3 underline">
<Link href="/">
<a>首页</a>
</Link>
</nav>
<div className=" max-w-6xl justify-between w-full flex">
<section>
<Link title={BLOG.TITLE} href={'/'}>
<a className={'cursor-pointer flex items-center hover:underline'}>
<i className={'fas fa-home mr-1'} />
<div className="text-center">{BLOG.TITLE} </div>
</a>
</Link>
</section>
<nav className="space-x-3 flex">
{links.map(link => {
if (link) {
return (
<Link key={`${link.to}`} title={link.to} href={link.to}>
<a
className={
'cursor-pointer flex items-center hover:underline'
}
>
<i className={`${link.icon} mr-1`} />
<div className="text-center">{link.name}</div>
</a>
</Link>
)
} else {
return null
}
})}
</nav>
</div>
</div>

{/* 内容主体 */}
<main id="wrapper" className="flex justify-center flex-1 pb-12">
<div className="max-w-4xl px-3">{children}</div>
<div >
<div className='sticky top-0 z-40'>
<Live2D/>
<div className="max-w-4xl w-full px-3">{children}</div>
<div>
<div className="sticky top-0 z-40">
<Live2D />
</div>
</div>
</main>
<footer
className='font-sans dark:bg-gray-900 flex-shrink-0 justify-center text-center m-auto w-full leading-6 text-sm p-6'
>
<i className='fas fa-copyright' /> {`${startYear}${currentYear}`} <span><i className='mx-1 animate-pulse fas fa-heart'/> <a href={BLOG.LINK} className='underline font-bold dark:text-gray-300 '>{BLOG.AUTHOR}</a>.
<br/>

<span>Powered by <a href='https://notion.so' className='underline font-bold dark:text-gray-300'>Notion</a> & <a href='https://github.com/tangly1024/NotionNext' className='underline font-bold dark:text-gray-300'>NotionNext {BLOG.VERSION}</a>.</span></span>

{BLOG.BEI_AN && <><br /><i className='fas fa-shield-alt' /> <a href='https://beian.miit.gov.cn/' className='mr-2'>{BLOG.BEI_AN}</a><br/></>}
<br/>
<span className='hidden busuanzi_container_site_pv'>
<i className='fas fa-eye'/><span className='px-1 busuanzi_value_site_pv'> </span> </span>
<span className='pl-2 hidden busuanzi_container_site_uv'>
<i className='fas fa-users'/> <span className='px-1 busuanzi_value_site_uv'> </span> </span>
<br/>
{/* 页脚 */}
<footer className="font-sans dark:bg-gray-900 flex-shrink-0 justify-center text-center m-auto w-full leading-6 text-sm p-6">
<i className="fas fa-copyright" /> {`${startYear}${currentYear}`}{' '}
<span>
<i className="mx-1 animate-pulse fas fa-heart" />{' '}
<a
href={BLOG.LINK}
className="underline font-bold dark:text-gray-300 "
>
{BLOG.AUTHOR}
</a>
.
<br />
<span>
Powered by{' '}
<a
href="https://notion.so"
className="underline font-bold dark:text-gray-300"
>
Notion
</a>{' '}
&{' '}
<a
href="https://github.com/tangly1024/NotionNext"
className="underline font-bold dark:text-gray-300"
>
NotionNext {BLOG.VERSION}
</a>
.
</span>
</span>
{BLOG.BEI_AN && (
<>
<br />
<i className="fas fa-shield-alt" />{' '}
<a href="https://beian.miit.gov.cn/" className="mr-2">
{BLOG.BEI_AN}
</a>
<br />
</>
)}
<br />
<span className="hidden busuanzi_container_site_pv">
<i className="fas fa-eye" />
<span className="px-1 busuanzi_value_site_pv"> </span>{' '}
</span>
<span className="pl-2 hidden busuanzi_container_site_uv">
<i className="fas fa-users" />{' '}
<span className="px-1 busuanzi_value_site_uv"> </span>{' '}
</span>
<br />
<h1>{meta?.title || BLOG.TITLE}</h1>
</footer>
</footer>
</div>
)
}
Expand Down
50 changes: 45 additions & 5 deletions themes/empty/LayoutCategory.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,48 @@
import BLOG from '@/blog.config'
import { useGlobal } from '@/lib/global'
import Link from 'next/link'
import { useState } from 'react'
import LayoutBase from './LayoutBase'

export const LayoutCategory = (props) => {
const { category } = props
return <LayoutBase {...props}>
Category - {category}
</LayoutBase>
export const LayoutCategory = props => {
const { category, posts } = props
const { locale } = useGlobal()

const [page, updatePage] = useState(1)
let hasMore = false
const postsToShow = posts
? Object.assign(posts).slice(0, BLOG.POSTS_PER_PAGE * page)
: []

if (posts) {
const totalCount = posts.length
hasMore = page * BLOG.POSTS_PER_PAGE < totalCount
}
const handleGetMore = () => {
if (!hasMore) return
updatePage(page + 1)
}

return (
<LayoutBase {...props}>
Category - {category}
{postsToShow.map(p => (
<div key={p.id} className="border my-12">
<Link href={`/article/${p.slug}`}>
<a className="underline cursor-pointer">{p.title}</a>
</Link>
<div>{p.summary}</div>
</div>
))}
<div>
<div
onClick={handleGetMore}
className="w-full my-4 py-4 text-center cursor-pointer "
>
{' '}
{hasMore ? locale.COMMON.MORE : `${locale.COMMON.NO_MORE} 😰`}{' '}
</div>
</div>
</LayoutBase>
)
}
21 changes: 19 additions & 2 deletions themes/empty/LayoutCategoryIndex.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
import { useGlobal } from '@/lib/global'
import Link from 'next/link'
import LayoutBase from './LayoutBase'

export const LayoutCategoryIndex = (props) => {
// const { tags, allPosts, categories, postCount, latestPosts } = props
const { categories } = props
const { locale } = useGlobal()
return <LayoutBase {...props}>
CategoryIndex
<div className=' p-10'>
<div className='dark:text-gray-200 mb-5'>
<i className='mr-4 fas fa-th' />{locale.COMMON.CATEGORY}:
</div>
<div id='category-list' className='duration-200 flex flex-wrap'>
{categories && categories.map(category => {
return <Link key={category.name} href={`/category/${category.name}`} passHref>
<div
className={'hover:text-black dark:hover:text-white dark:text-gray-300 dark:hover:bg-gray-600 px-5 cursor-pointer py-2 hover:bg-gray-100'}>
<i className='mr-4 fas fa-folder' />{category.name}({category.count})
</div>
</Link>
})}
</div>
</div>
</LayoutBase>
}
Loading

1 comment on commit 86c42ae

@vercel
Copy link

@vercel vercel bot commented on 86c42ae Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.