Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
计算机应用开发
前端
Vuepress
提交
fda5476a
V
Vuepress
项目概览
计算机应用开发
/
前端
/
Vuepress
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vuepress
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
fda5476a
编写于
5月 13, 2019
作者:
U
ULIVZ
提交者:
GitHub
5月 13, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "feat($markdown): cache parser (#1359)" (#1596)
This reverts commit
f04adbf1
.
上级
fbbd677f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
17 addition
and
24 deletion
+17
-24
packages/@vuepress/markdown-loader/index.js
packages/@vuepress/markdown-loader/index.js
+16
-6
packages/@vuepress/markdown/index.js
packages/@vuepress/markdown/index.js
+1
-17
packages/@vuepress/markdown/package.json
packages/@vuepress/markdown/package.json
+0
-1
未找到文件。
packages/@vuepress/markdown-loader/index.js
浏览文件 @
fda5476a
...
...
@@ -6,10 +6,11 @@
const
{
EventEmitter
}
=
require
(
'
events
'
)
const
{
getOptions
}
=
require
(
'
loader-utils
'
)
const
{
fs
,
path
,
parseFrontmatter
,
inferTitle
,
extractHeaders
}
=
require
(
'
@vuepress/shared-utils
'
)
const
{
fs
,
path
,
hash
,
parseFrontmatter
,
inferTitle
,
extractHeaders
}
=
require
(
'
@vuepress/shared-utils
'
)
const
LRU
=
require
(
'
lru-cache
'
)
const
md
=
require
(
'
@vuepress/markdown
'
)
const
cache
=
new
LRU
({
max
:
1000
})
const
devCache
=
new
LRU
({
max
:
1000
})
/**
...
...
@@ -31,18 +32,26 @@ module.exports = function (src) {
// vue-loader, and will be applied on the same file multiple times when
// selecting the individual blocks.
const
file
=
this
.
resourcePath
const
{
content
,
data
}
=
parseFrontmatter
(
src
)
const
key
=
hash
(
file
+
src
)
const
cached
=
cache
.
get
(
key
)
if
(
cached
&&
(
isProd
||
/
\?
vue/
.
test
(
this
.
resourceQuery
)))
{
return
cached
}
const
frontmatter
=
parseFrontmatter
(
src
)
const
content
=
frontmatter
.
content
if
(
!
isProd
&&
!
isServer
)
{
const
inferredTitle
=
inferTitle
(
data
,
content
)
const
inferredTitle
=
inferTitle
(
frontmatter
.
data
,
frontmatter
.
content
)
const
headers
=
extractHeaders
(
content
,
[
'
h2
'
,
'
h3
'
],
markdown
)
delete
frontmatter
.
content
// diff frontmatter and title, since they are not going to be part of the
// returned component, changes in frontmatter do not trigger proper updates
const
cachedData
=
devCache
.
get
(
file
)
if
(
cachedData
&&
(
cachedData
.
inferredTitle
!==
inferredTitle
||
JSON
.
stringify
(
cachedData
.
frontmatterData
)
!==
JSON
.
stringify
(
data
)
||
JSON
.
stringify
(
cachedData
.
frontmatterData
)
!==
JSON
.
stringify
(
frontmatter
.
data
)
||
headersChanged
(
cachedData
.
headers
,
headers
)
))
{
// frontmatter changed... need to do a full reload
...
...
@@ -51,7 +60,7 @@ module.exports = function (src) {
devCache
.
set
(
file
,
{
headers
,
frontmatterData
:
data
,
frontmatterData
:
frontmatter
.
data
,
inferredTitle
})
}
...
...
@@ -64,7 +73,7 @@ module.exports = function (src) {
dataBlockString
}
=
markdown
.
render
(
content
,
{
loader
,
frontmatter
:
data
,
frontmatter
:
frontmatter
.
data
,
relativePath
:
path
.
relative
(
sourceDir
,
file
).
replace
(
/
\\
/g
,
'
/
'
)
})
...
...
@@ -105,6 +114,7 @@ module.exports = function (src) {
+
(
hoistedTags
||
[]).
join
(
'
\n
'
)
+
`\n
${
dataBlockString
}
\n`
)
cache
.
set
(
key
,
res
)
return
res
}
...
...
packages/@vuepress/markdown/index.js
浏览文件 @
fda5476a
...
...
@@ -5,7 +5,6 @@
*/
const
Config
=
require
(
'
markdown-it-chain
'
)
const
LRUCache
=
require
(
'
lru-cache
'
)
const
highlight
=
require
(
'
./lib/highlight
'
)
const
{
PLUGINS
,
REQUIRED_PLUGINS
}
=
require
(
'
./lib/constant
'
)
const
highlightLinesPlugin
=
require
(
'
./lib/highlightLines
'
)
...
...
@@ -21,7 +20,7 @@ const tocPlugin = require('markdown-it-table-of-contents')
const
{
slugify
:
_slugify
,
parseHeaders
,
logger
,
chalk
,
hash
,
normalizeConfig
,
logger
,
chalk
,
normalizeConfig
,
moduleResolver
:
{
getMarkdownItResolver
}
}
=
require
(
'
@vuepress/shared-utils
'
)
...
...
@@ -124,21 +123,6 @@ module.exports = (markdown = {}) => {
afterInstantiate
&&
afterInstantiate
(
md
)
// override parse to allow cache
const
parse
=
md
.
parse
const
cache
=
new
LRUCache
({
max
:
1000
})
md
.
parse
=
(
src
,
env
)
=>
{
const
key
=
hash
(
src
+
env
.
relativePath
)
const
cached
=
cache
.
get
(
key
)
if
(
cached
)
{
return
cached
}
else
{
const
tokens
=
parse
.
call
(
md
,
src
,
env
)
cache
.
set
(
key
,
tokens
)
return
tokens
}
}
module
.
exports
.
dataReturnable
(
md
)
// expose slugify
...
...
packages/@vuepress/markdown/package.json
浏览文件 @
fda5476a
...
...
@@ -20,7 +20,6 @@
],
"dependencies"
:
{
"@vuepress/shared-utils"
:
"^1.0.0-alpha.47"
,
"lru-cache"
:
"^5.1.1"
,
"markdown-it"
:
"^8.4.1"
,
"markdown-it-anchor"
:
"^5.0.2"
,
"markdown-it-chain"
:
"^1.3.0"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录