Skip to content

Commit 68b1a5b

Browse files
committed
feat: add animation tags cloud
* feat: add animation tags cloud * refactor: tag style perfect
1 parent e8a2e36 commit 68b1a5b

File tree

12 files changed

+369
-31
lines changed

12 files changed

+369
-31
lines changed

client/pages/category/[category].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const Home: NextPage<IProps> = ({ articles: defaultArticles = [], total, categor
9090
rightNode={
9191
<div className="sticky">
9292
<ArticleRecommend mode="inline" />
93-
<Tags tags={tags} />
93+
<Tags tags={tags} animationMode />
9494
<AboutUs className={style.footer} setting={setting} />
9595
</div>
9696
}

client/pages/index.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
p {
2222
margin-bottom: 0;
2323
color: var(--font-color-base);
24+
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
2425
&:first-of-type {
2526
margin-top: 80px;
2627
font-size: 2rem;

client/pages/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ const Home: NextPage<IHomeProps> = ({ articles: defaultArticles = [], recommende
113113
}
114114
rightNode={
115115
<div className="sticky">
116-
<Tags tags={tags} />
117116
<ArticleRecommend mode="inline" />
117+
<Tags tags={tags} animationMode />
118118
<AboutUs className={style.footer} setting={setting} />
119119
</div>
120120
}

client/pages/nav/[id].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ const Article: NextPage<IProps> = ({ siteKey }) => {
149149
}
150150
rightNode={
151151
<div className={'sticky'}>
152-
<Tags tags={tags} />
152+
<Tags tags={tags} animationMode />
153153
<AboutUs setting={setting} />
154154
</div>
155155
}

client/src/components/ArticleList/index.module.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
&:hover {
3232
opacity: 0.7;
3333
}
34-
> * {
35-
margin-left: 4px;
34+
.category {
35+
color: var(--second-text-color);
3636
}
3737
}
3838

client/src/components/ArticleList/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ export const ArticleList: React.FC<IProps> = ({ articles = [] }) => {
5656
as={`/category/${article?.category?.value}`}
5757
scroll={false}
5858
>
59-
<Tag className={style.antBadge} color={getColorFromNumber(categoryIndex)}>
60-
<FolderOutlined />
59+
<Tag className={style.antBadge} icon={<FolderOutlined />}>
6160
<span className={style.category}>{article.category?.label}</span>
6261
</Tag>
6362
</Link>

client/src/components/ArticleRecommend/index.module.scss

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,41 @@
2323
ul.inlineWrapper {
2424
padding: 0 1rem 1rem;
2525

26+
.article {
27+
display: flex;
28+
justify-content: space-between;
29+
width: 100%;
30+
.seqId {
31+
display: inline-block;
32+
width: 40px;
33+
border-radius: 4px;
34+
background-color: var(--primary-color);
35+
}
36+
.articleTitle {
37+
flex: 1;
38+
width: 100%;
39+
display: inline-block;
40+
overflow: hidden;
41+
text-overflow: ellipsis;
42+
&::before {
43+
background-color: var(--primary-color);
44+
color: #fff;
45+
content: attr(data-num);
46+
display: inline-block;
47+
font-size: 14px;
48+
line-height: 18px;
49+
margin-right: 5px;
50+
text-align: center;
51+
width: 18px;
52+
}
53+
}
54+
.views {
55+
display: inline-block;
56+
width: 54px;
57+
color: var(--second-text-color);
58+
}
59+
}
60+
2661
li {
2762
display: flex;
2863
flex-wrap: nowrap;

client/src/components/ArticleRecommend/index.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import { useTranslations } from 'next-intl';
55
import Link from 'next/link';
66
import React, { useEffect, useState } from 'react';
77

8-
import { LocaleTime } from '@/components/LocaleTime';
98
import { useAsyncLoading } from '@/hooks/useAsyncLoading';
109
import { ArticleProvider } from '@/providers/article';
11-
import { LikeOutlined } from '@ant-design/icons';
10+
import { LikeOutlined, EyeOutlined } from '@ant-design/icons';
1211

1312
import style from './index.module.scss';
1413

@@ -22,12 +21,14 @@ export const ArticleRecommend: React.FC<IProps> = ({ mode = 'vertical', articleI
2221
const t = useTranslations();
2322
const [getRecommend, loading] = useAsyncLoading(ArticleProvider.getRecommend, 150, true);
2423
const [fetched, setFetched] = useState('');
25-
const [articles, setArticles] = useState([]);
24+
const [articles, setArticles] = useState<IArticle[]>([]);
2625

2726
useEffect(() => {
2827
if (fetched === articleId) return;
2928
getRecommend(articleId).then((res) => {
30-
setArticles(res.slice(0, 6));
29+
const articles = res.slice(0, 6);
30+
articles.sort((a, b) => b.views - a.views);
31+
setArticles(articles);
3132
setFetched(articleId);
3233
});
3334
}, [articleId, getRecommend, fetched]);
@@ -36,7 +37,7 @@ export const ArticleRecommend: React.FC<IProps> = ({ mode = 'vertical', articleI
3637
<div className={cls(style.wrapper, mode === 'inline' && style.inline)}>
3738
{needTitle && (
3839
<div className={style.title}>
39-
<LikeOutlined className={style.recommendIcon}/>
40+
<LikeOutlined className={style.recommendIcon} />
4041
<span>{t('recommendToReading')}</span>
4142
</div>
4243
)}
@@ -53,15 +54,17 @@ export const ArticleRecommend: React.FC<IProps> = ({ mode = 'vertical', articleI
5354
)
5455
) : (
5556
<ul className={style.inlineWrapper}>
56-
{articles.map((article) => {
57+
{articles.map((article, index) => {
5758
return (
5859
<li key={article.id}>
5960
<Link href={`/article/[id]`} as={`/article/${article.id}`} scroll={false}>
60-
<a>
61-
<span>{article.title}</span>
62-
{' · '}
63-
<span>
64-
<LocaleTime date={article.publishAt} timeago={true} />
61+
<a className={style.article} title={article.title}>
62+
<span className={style.articleTitle} data-num={index + 1}>
63+
<span>{article.title}</span>
64+
</span>
65+
<span className={style.views}>
66+
<EyeOutlined />
67+
<span className={style.number}>{article.views}</span>
6568
</span>
6669
</a>
6770
</Link>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.tagCloud {
2+
width: 250px;
3+
height: 260px;
4+
position: relative;
5+
font-size: 12px;
6+
color: #333;
7+
margin: 0 20px;
8+
text-align: center;
9+
10+
a {
11+
position: absolute;
12+
top: 0px;
13+
left: 0px;
14+
color: rgb(255, 255, 255);
15+
text-decoration: none;
16+
margin: 0 10px 15px 0;
17+
line-height: 18px;
18+
text-align: center;
19+
font-size: 12px;
20+
padding: 5px 8px;
21+
display: inline-block;
22+
border-radius: 3px;
23+
white-space: nowrap;
24+
}
25+
26+
a:hover {
27+
background: var(--primary-color) !important;
28+
}
29+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useEffect, useRef, FC, ReactNode } from 'react';
2+
import styles from './index.module.scss';
3+
import Tag from './tag';
4+
5+
interface IProps {
6+
children: ReactNode;
7+
className: string;
8+
}
9+
10+
const TagCloud: FC<IProps> = (props) => {
11+
const ref = useRef<HTMLDivElement>();
12+
const tagInstance = useRef<Tag>(new Tag()).current;
13+
14+
useEffect(() => {
15+
tagInstance.init(ref.current);
16+
}, []);
17+
18+
return (
19+
<div className={styles.tagCloud} ref={ref}>
20+
{props.children}
21+
</div>
22+
);
23+
};
24+
25+
export default TagCloud;

0 commit comments

Comments
 (0)