Skip to content

Commit 2bcc674

Browse files
添加文章归档功能,格式化一下代码
1 parent 41b08a9 commit 2bcc674

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1959
-1882
lines changed

README.md

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@
3737
- [X] 移动端适配
3838
- [X] 网站波浪效果(请看 http://biaochenxuying.cn/wave.html)
3939
- [X] 第三方 github 授权登录
40+
- [X] 文章归档
4041

4142
## 2.2 待实现功能
4243

43-
- [ ] 文章归档
4444
- [ ] 文章分类
4545
- [ ] 文章详情的目录
46-
- [ ] 升级 webpack 版本到 4.X
4746

4847
# 3. 前端技术
4948

@@ -77,7 +76,8 @@
7776
- project 项目
7877
- register 注册
7978
- slider 右边栏(博主 logo 、链接和标签等)
80-
- timeLine 时间轴
79+
- artchive 归档
80+
- timeLine 时间轴(历程)
8181
- router 路由
8282
- store redux 的状态管理
8383
- utils 封装的常用的方法
@@ -219,23 +219,7 @@ p img{
219219

220220
# 7. 注意点
221221

222-
## 7.1 打包的配置
223-
224-
因为项目是用了 react-app-rewired (一个对 create-react-app 进行自定义配置的社区解决方案) 来打包了,所以如果你想修改 webpack.config.dev.js 和 webpack.config.prod.js 的配置,打包后可能看不到想要的效果,因为 react-app-rewired 打包时,是根据根目录的 config-overrides.js 来进行打包,**所以要修改 webpack 的配置的话,请修改 config-overrides.js 。**
225-
226-
比如:关闭 sourceMap 和 支持装饰器
227-
```
228-
config.devtool = false; // 关闭 sourceMap
229-
config = injectBabelPlugin('babel-plugin-transform-decorators-legacy', config); // 支持装饰器
230-
```
231-
232-
因为 linux 和 window 的设置端口的打包命令有点不同,如果 window 下打包出错,请把 package.json 修改成如下的命令:
233-
234-
```
235-
"start": "set PORT=3001 && react-app-rewired start",
236-
```
237-
238-
## 7.2 关于 页面
222+
## 7.1 关于 页面
239223

240224
对于 关于 的页面,其实是一篇文章来的,根据文章类型 type 来决定的,数据库里面 type 为 3
241225
的文章,只能有一篇就是 博主介绍 ;达到了想什么时候修改内容都可以。
@@ -267,8 +251,6 @@ npm run build 或者 yarn run build
267251

268252
其他具体的业务代码,都是些常会见到的需求,这里就不展开讲了。
269253

270-
如果你觉得该文章不错,欢迎到我的 github,star 一下,谢谢。
271-
272254
**项目地址:**
273255
> [前台展示: https://github.com/biaochenxuying/blog-react](https://github.com/biaochenxuying/blog-react)
274256
@@ -285,22 +267,19 @@ npm run build 或者 yarn run build
285267
- 3. [基于 node + express + mongodb 的 blog-node 项目文档说明](http://biaochenxuying.cn/articleDetail?article_id=5bf8c57185e0f13af26e7d0d)
286268
- 4. [服务器小白的我,是如何将node+mongodb项目部署在服务器上并进行性能优化的](http://biaochenxuying.cn/articleDetail?article_id=5bfa728bb54f044b4f9da240)
287269
- 5. [github 授权登录教程与如何设计第三方授权登录的用户表](http://biaochenxuying.cn/articleDetail?article_id=5c7bd34e42b55e2ecc90976d)
270+
- 6. [一次网站的性能优化之路 -- 天下武功,唯快不破](http://biaochenxuying.cn/articleDetail?article_id=5c8ca2d3b87b8a04f1860c9a)
288271

289272

290273

291274
# 10. 最后
292275

293276

294-
鉴于问问题的人有点多,小汪时间有限,处理不过来,大家可以加入 QQ 群:**186045338**,加群暗号:**全栈修炼** ,一起相互交流学习。
295-
296-
297-
**全栈开发** 有兴趣的朋友可以扫下方二维码关注我的公众号,我会不定期更新有价值的内容。
298-
299-
关注公众号并回复 **福利** 便免费送你视频资源,绝对干货。
277+
鉴于问问题的人有点多,笔者时间有限,处理不过来,大家可以加入 QQ 群:**186045338**,加群暗号:**全栈修炼** ,一起相互交流学习。
300278

301-
福利详情请点击: [免费资源分享--Python、Java、Linux、Go、node、vue、react、javaScript](https://mp.weixin.qq.com/s?__biz=MzA4MDU1MDExMg==&mid=2247483711&idx=1&sn=1ffb576159805e92fc57f5f1120fce3a&chksm=9fa3c0b0a8d449a664f36f6fdd017ac7da71b6a71c90261b06b4ea69b42359255f02d0ffe7b3&token=1560489745&lang=zh_CN#rd)
279+
如果您觉得本项目和文章不错或者对你有所帮助,请给个星呗,你的肯定就是我继续创作的最大动力。
302280

303-
![BiaoChenXuYing](https://upload-images.jianshu.io/upload_images/12890819-091ccce387e2ea34.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
281+
欢迎关注公众号,并回复 **福利** 可领取免费学习资料,福利详情请猛戳: [免费资源获取--Python、Java、Linux、Go、node、vue、react、javaScript](https://mp.weixin.qq.com/s?__biz=MzA4MDU1MDExMg==&mid=2247483711&idx=1&sn=1ffb576159805e92fc57f5f1120fce3a&chksm=9fa3c0b0a8d449a664f36f6fdd017ac7da71b6a71c90261b06b4ea69b42359255f02d0ffe7b3&token=1560489745&lang=zh_CN#rd)
304282

283+
![BiaoChenXuYing](https://upload-images.jianshu.io/upload_images/12890819-0fc16a9e50276521.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
305284

306285

config/webpack.config.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ const getClientEnvironment = require('./env');
2323
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
2424
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
2525
const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
26-
26+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
2727

2828
// Source maps are resource heavy and can cause out of memory issue for large source files.
2929
// const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
30-
console.log('process.env :', process.env)
31-
console.log('process.env.GENERATE_SOURCEMAP :', process.env.GENERATE_SOURCEMAP)
3230
const shouldUseSourceMap = process.env.NODE_ENV === 'production' ? false : true;
3331
// Some apps do not need the benefits of saving a web request, so not inlining the chunk
3432
// makes for a smoother build process.
@@ -322,10 +320,10 @@ module.exports = function(webpackEnv) {
322320
// smaller than specified limit in bytes as data URLs to avoid requests.
323321
// A missing `test` is equivalent to a match.
324322
{
325-
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
323+
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/,/\.jpg$/,/\.svg$/],
326324
loader: require.resolve('url-loader'),
327325
options: {
328-
limit: 10000,
326+
limit: 40000,
329327
name: 'static/media/[name].[hash:8].[ext]',
330328
},
331329
},
@@ -507,6 +505,7 @@ module.exports = function(webpackEnv) {
507505
],
508506
},
509507
plugins: [
508+
new BundleAnalyzerPlugin(),
510509
// Generates an `index.html` file with the <script> injected.
511510
new HtmlWebpackPlugin(
512511
Object.assign(

package-lock.json

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585
"devDependencies": {
8686
"@babel/plugin-proposal-decorators": "^7.3.0",
8787
"babel-plugin-import": "^1.11.0",
88-
"http-proxy-middleware": "^0.19.1"
88+
"http-proxy-middleware": "^0.19.1",
89+
"webpack-bundle-analyzer": "^3.1.0"
8990
},
9091
"jest": {
9192
"collectCoverageFrom": [

src/components/archive/archive.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import './index.less';
2+
import React, { Component } from 'react';
3+
import { Link } from 'react-router-dom';
4+
import { Timeline, Icon, message } from 'antd';
5+
import https from '../../utils/https';
6+
import urls from '../../utils/urls';
7+
import { timestampToTime } from '../../utils/utils';
8+
import LoadingCom from '../loading/loading';
9+
10+
class Archive extends Component {
11+
constructor(props) {
12+
super(props);
13+
this.state = {
14+
isLoading: false,
15+
isLoadEnd: false,
16+
article: 1,
17+
// keyword: '',
18+
// pageNum: 1,
19+
// pageSize: 10,
20+
total: 0,
21+
list: [],
22+
};
23+
this.handleSearch = this.handleSearch.bind(this);
24+
}
25+
26+
componentDidMount() {
27+
this.handleSearch();
28+
}
29+
30+
handleSearch = () => {
31+
this.setState({
32+
isLoading: true,
33+
});
34+
https
35+
.get(urls.getArticleList, {
36+
params: {
37+
// keyword: this.state.keyword,
38+
// pageNum: this.state.pageNum,
39+
// pageSize: this.state.pageSize,
40+
article: this.state.article,
41+
},
42+
})
43+
.then(res => {
44+
let num = this.state.pageNum;
45+
if (res.status === 200 && res.data.code === 0) {
46+
this.setState({
47+
list: this.state.list.concat(res.data.data.list),
48+
total: res.data.data.count,
49+
pageNum: ++num,
50+
isLoading: false,
51+
});
52+
if (this.state.total === this.state.list.length) {
53+
this.setState({
54+
isLoadEnd: true,
55+
});
56+
}
57+
} else {
58+
message.error(res.data.message);
59+
}
60+
})
61+
.catch(err => {
62+
console.log(err);
63+
});
64+
};
65+
66+
render() {
67+
const list = this.state.list.map((item, i) => (
68+
<Timeline.Item
69+
key={i}
70+
color={'red'}
71+
dot={<Icon type="clock-circle-o" style={{ fontSize: '16px' }} />}
72+
>
73+
<h1>{item.year}</h1>
74+
{item.list.map(ele => {
75+
return (
76+
<Timeline key={ele._id}>
77+
<Timeline.Item>
78+
<Link
79+
className="title"
80+
target="_blank"
81+
to={`/articleDetail?article_id=${ele._id}`}
82+
>
83+
<h3>{ele.title}</h3>
84+
</Link>
85+
<p>
86+
<span>
87+
{ele.create_time
88+
? timestampToTime(ele.create_time, true)
89+
: ''}
90+
</span>
91+
</p>
92+
</Timeline.Item>
93+
</Timeline>
94+
);
95+
})}
96+
</Timeline.Item>
97+
));
98+
99+
return (
100+
<div className="archive">
101+
<Timeline>{list}</Timeline>
102+
{this.state.isLoading ? <LoadingCom /> : ''}
103+
</div>
104+
);
105+
}
106+
}
107+
108+
export default Archive;

src/components/archive/index.less

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.archive {
2+
padding: 50px 5px;
3+
h1{
4+
position: relative;
5+
top: -15px;
6+
font-size: 36px;
7+
padding: 0 0 20px 10px;
8+
}
9+
h3:hover{
10+
color: #1890ff;
11+
}
12+
}
13+
.clearfix {
14+
clear: both;
15+
}

0 commit comments

Comments
 (0)