Skip to content

Commit d68de81

Browse files
committed
详情页采用 markdown-it 渲染
1 parent c269a40 commit d68de81

File tree

10 files changed

+103
-13
lines changed

10 files changed

+103
-13
lines changed

package-lock.json

Lines changed: 29 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"highlight.js": "^9.16.2",
1616
"js-cookie": "^2.2.1",
1717
"markdown-it": "^10.0.0",
18+
"markdown-it-toc-and-anchor": "^4.2.0",
1819
"mavon-editor": "^2.7.6",
1920
"moment": "^2.24.0",
2021
"node-sass": "^4.13.0",

src/components/AsideCard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<div v-for="o in 4" :key="o" class="box-card_item">
88
<router-link
99
class="box-card_item-link clearfix"
10-
to="/about">
10+
to="/list">
1111
<span class="sub-title fr">100 {{ subTitle }}</span>
1212
<span class="title ellipsis">{{'列表内容 ' + o }}</span>
1313
</router-link>

src/components/listArticle.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<template>
22
<div class="item-box">
3-
<router-link class="header" to="">
3+
<router-link class="header" to="/detail">
44
<el-tag class="header-icon">原创</el-tag>
55
<h2>Express4 环境变量配置</h2>
66
</router-link>
7-
<router-link class="content" to="">在进项项目开发中经常会遇到不同环境切换的问题,比如说开发环境和正式环境对应不同服务器的 mysql ,总不能每次切换不同环境的时候修改代码,这样既容易出错,也不利于代码维护,所以这个时候就需要用到环境变量来进行配置了。开发环境在开发环境中,我们一般链接的是本地服务器的 mysql ,这个时候我...</router-link>
7+
<router-link class="content" to="/detail">在进项项目开发中经常会遇到不同环境切换的问题,比如说开发环境和正式环境对应不同服务器的 mysql ,总不能每次切换不同环境的时候修改代码,这样既容易出错,也不利于代码维护,所以这个时候就需要用到环境变量来进行配置了。开发环境在开发环境中,我们一般链接的是本地服务器的 mysql ,这个时候我...</router-link>
88
<div class="footer clearfix">
99
<div class="footer-item">2019-10-17 08:35:58</div>
1010
<div class="footer-line"></div>
1111
<div class="footer-item">views <span>9</span></div>
1212
<div class="footer-line"></div>
1313
<div class="footer-item">stars <span>1</span></div>
1414
<div class="footer-editor fr">
15-
<div class="footer-item">编辑</div>
15+
<router-link class="footer-item" to="/editor">编辑</router-link>
1616
<div class="footer-line"></div>
1717
<div class="footer-item">删除</div>
1818
</div>

src/router/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const routes = [
7373
]
7474

7575
const router = new VueRouter({
76+
// mode: 'history',
7677
routes
7778
})
7879

src/style/common.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ body {
1616
$page-width: 1150px !default;
1717
$header-height: 60px !default;
1818
$logo-size: 34px !default;
19+
$theme-color: #333 !default;
20+
$theme-light-color: #666 !default;
1921
$border-color:#e6e6e6 !default;
2022
$split-line-color:#ddd !default;
2123

src/style/components/aside-card.scss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
.box-card_item-link {
77
display: block;
88
height: 26px;
9-
color: $--color-info;
9+
color: $theme-light-color;
1010
text-decoration: none;
1111
&:hover {
1212
color: $--color-primary;
13-
text-decoration: underline;
1413
}
1514
.sub-title {
1615
font-size: 12px;

src/style/components/list-article.scss

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
.header {
1515
line-height: 32px;
16-
color: $--color-info;
16+
color: $theme-color;
1717
text-decoration: none;
1818
&:hover {
1919
color: $--color-primary;
@@ -31,7 +31,7 @@
3131
display: block;
3232
margin: 8px 0;
3333
line-height: 20px;
34-
color: $--color-info;
34+
color: $theme-color;
3535
text-decoration: none;
3636
&:hover {
3737
color: $--color-primary;
@@ -40,7 +40,7 @@
4040
.footer {
4141
height: 32px;
4242
line-height: 32px;
43-
color: $--color-info;
43+
color: $theme-color;
4444
.footer-editor {
4545
display: none;
4646
.footer-item:hover {
@@ -50,6 +50,11 @@
5050
}
5151
.footer-item {
5252
display: inline-block;
53+
color: $theme-color;
54+
text-decoration: none;
55+
&:hover {
56+
color: $--color-primary;
57+
}
5358
span {
5459
color: $--color-primary;
5560
}

src/views/Detail.vue

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ import 'highlight.js/styles/vs2015.css'
4545
import hljs from 'highlight.js/lib/highlight'
4646
import javascript from 'highlight.js/lib/languages/javascript'
4747
import MarkdownIt from 'markdown-it'
48+
import markdownItTocAndAnchor from 'markdown-it-toc-and-anchor'
4849
hljs.registerLanguage('javascript', javascript)
4950
let md = new MarkdownIt({
51+
html: true,
52+
linkify: true,
53+
typographer: true,
5054
highlight: function (str, lang) {
5155
if (lang && hljs.getLanguage(lang)) {
5256
try {
@@ -64,10 +68,18 @@ export default {
6468
name: 'detail',
6569
data () {
6670
return {
67-
content: `在进项项目开发中经常会遇到不同环境切换的问题,比如说开发环境和正式环境对应不同服务器的 mysql ,总不能每次切换不同环境的时候修改代码,这样既容易出错,也不利于代码维护,所以这个时候就需要用到环境变量来进行配置了。
71+
content: `@[toc]在进项项目开发中经常会遇到不同环境切换的问题,比如说开发环境和正式环境对应不同服务器的 mysql ,总不能每次切换不同环境的时候修改代码,这样既容易出错,也不利于代码维护,所以这个时候就需要用到环境变量来进行配置了。
6872
6973
## 开发环境
70-
在开发环境中,我们一般链接的是本地服务器的 mysql ,这个时候我们可以通过以下设置来进行变量控制`
74+
在开发环境中,我们一般链接的是本地服务器的 mysql ,这个时候我们可以通过以下设置来进行变量控制
75+
76+
### 环境变量配置
77+
环境变量配置环境变量配置环境变量配置环境变量配置环境变量配置环境变量配置环境变量配置
78+
79+
## 生产环境
80+
生产环境生产环境生产环境生产环境生产环境生产环境生产环境生产环境生产环境生产环境生产环境生产环境生产环境生产环境生产环境生产环境
81+
82+
`
7183
}
7284
},
7385
components: {
@@ -76,7 +88,11 @@ export default {
7688
},
7789
computed: {
7890
markdownHtml () {
79-
return this.content && md.render(this.content)
91+
return this.content && md.use(markdownItTocAndAnchor, {
92+
tocCallback: function (tocMarkdown, tocArray, tocHtml) {
93+
console.log(tocArray)
94+
}
95+
}).render(this.content)
8096
}
8197
}
8298
}
@@ -86,3 +102,40 @@ export default {
86102
@import './../style/views/home.scss';
87103
@import './../style/views/detail.scss';
88104
</style>
105+
106+
<style lang="scss">
107+
.markdownIt-TOC {
108+
padding: 0;
109+
margin: 0 0 15px 15px;
110+
float: right;
111+
list-style: none;
112+
&::before {
113+
content: '目录:';
114+
font-weight: 700;
115+
color: currentColor;
116+
margin-left: 18px;
117+
line-height: 26px;
118+
}
119+
a {
120+
text-decoration: none;
121+
color: #666;
122+
&:hover {
123+
color: #409EFF;
124+
}
125+
}
126+
}
127+
.article-content {
128+
font-size: 14px;
129+
color: #333;
130+
line-height: 1.5;
131+
h1, h2, h3, h4, h5, h6 {
132+
a {
133+
color: #409EFF;
134+
text-decoration: none;
135+
&:hover {
136+
text-decoration: underline;
137+
}
138+
}
139+
}
140+
}
141+
</style>

src/views/Editor.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default {
8787
submitForm (formName) {
8888
this.$refs[formName].validate((valid) => {
8989
if (valid) {
90-
alert('submit!')
90+
console.log(this.articleInfo.desc)
9191
} else {
9292
console.log('error submit!!')
9393
return false

0 commit comments

Comments
 (0)