Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
计算机应用开发
前端
Vuepress
提交
50e34673
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,发现更多精彩内容 >>
提交
50e34673
编写于
6月 02, 2018
作者:
U
ULIVZ
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: make lastUpdated as a plugin.
上级
46e1992f
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
24 addition
and
35 deletion
+24
-35
docs/.vuepress/config.js
docs/.vuepress/config.js
+1
-1
lib/plugin-api/index.js
lib/plugin-api/index.js
+16
-11
lib/plugins/vuepress-plugin-last-updated/index.js
lib/plugins/vuepress-plugin-last-updated/index.js
+2
-2
lib/prepare/resolveOptions.js
lib/prepare/resolveOptions.js
+5
-16
lib/prepare/util.js
lib/prepare/util.js
+0
-5
未找到文件。
docs/.vuepress/config.js
浏览文件 @
50e34673
...
@@ -27,7 +27,7 @@ module.exports = {
...
@@ -27,7 +27,7 @@ module.exports = {
theme
:
'
vue
'
,
theme
:
'
vue
'
,
plugins
:
[
plugins
:
[
[
[
require
(
'
../../lib/plugins/vuepress-plugin-last-updated/index
'
)
,
require
(
'
../../lib/plugins/vuepress-plugin-last-updated/index
'
)
]
]
],
],
themeConfig
:
{
themeConfig
:
{
...
...
lib/plugin-api/index.js
浏览文件 @
50e34673
...
@@ -20,7 +20,7 @@ module.exports = class Plugin {
...
@@ -20,7 +20,7 @@ module.exports = class Plugin {
'
outFiles
'
,
'
outFiles
'
,
'
extendPageData
'
'
extendPageData
'
])
])
this
.
resolvePluginConfig
(
pluginConfigs
)
this
.
resolvePluginConfig
s
(
pluginConfigs
)
}
}
extendHooks
(
hooks
)
{
extendHooks
(
hooks
)
{
...
@@ -35,27 +35,32 @@ module.exports = class Plugin {
...
@@ -35,27 +35,32 @@ module.exports = class Plugin {
})
})
}
}
registerHook
(
name
,
hook
,
symbol
)
{
if
(
hook
)
{
this
.
hooks
[
name
].
tap
(
symbol
,
hook
)
}
return
this
}
registerAPI
(
name
,
api
)
{
if
(
api
)
{
this
.
apis
[
name
].
push
(
api
)
}
return
this
}
resolvePluginConfigs
(
pluginConfigs
)
{
resolvePluginConfigs
(
pluginConfigs
)
{
pluginConfigs
.
forEach
(([
name
,
pluginOptions
])
=>
{
pluginConfigs
.
forEach
(([
name
,
pluginOptions
])
=>
{
let
plugin
=
resolvePlugin
(
name
)
let
plugin
=
resolvePlugin
(
name
)
if
(
typeof
plugin
===
'
function
'
)
{
if
(
typeof
plugin
===
'
function
'
)
{
plugin
=
plugin
(
pluginOptions
)
plugin
=
plugin
(
pluginOptions
)
}
}
console
.
log
(
plugin
)
plugin
=
Object
.
assign
(
plugin
,
{
name
:
inferPluginName
(
name
,
plugin
)
})
plugin
=
Object
.
assign
(
plugin
,
{
name
:
inferPluginName
(
name
,
plugin
)
})
this
.
resolvePluginConfig
(
plugin
)
this
.
resolvePluginConfig
(
plugin
)
})
})
}
}
registerHook
(
name
,
hook
,
symbol
)
{
this
.
hooks
[
name
].
tap
(
symbol
,
hook
)
return
this
}
registerAPI
(
name
,
api
)
{
this
.
apis
[
name
].
push
(
api
)
return
this
}
resolvePluginConfig
({
resolvePluginConfig
({
name
,
name
,
client
,
client
,
...
...
lib/plugins/vuepress-plugin-last-updated/index.js
浏览文件 @
50e34673
...
@@ -3,9 +3,9 @@ const spawn = require('cross-spawn')
...
@@ -3,9 +3,9 @@ const spawn = require('cross-spawn')
module
.
exports
=
options
=>
({
module
.
exports
=
options
=>
({
client
:
path
.
resolve
(
__dirname
,
'
client.js
'
),
client
:
path
.
resolve
(
__dirname
,
'
client.js
'
),
extendPageData
(
filepath
)
{
extendPageData
(
{
filepath
}
)
{
return
{
return
{
last
Modifi
ed
:
getGitLastUpdatedTimeStamp
(
filepath
)
last
Updat
ed
:
getGitLastUpdatedTimeStamp
(
filepath
)
}
}
}
}
})
})
...
...
lib/prepare/resolveOptions.js
浏览文件 @
50e34673
...
@@ -4,7 +4,7 @@ const globby = require('globby')
...
@@ -4,7 +4,7 @@ const globby = require('globby')
const
createMarkdown
=
require
(
'
../markdown
'
)
const
createMarkdown
=
require
(
'
../markdown
'
)
const
Plugin
=
require
(
'
../plugin-api
'
)
const
Plugin
=
require
(
'
../plugin-api
'
)
const
loadConfig
=
require
(
'
./loadConfig
'
)
const
loadConfig
=
require
(
'
./loadConfig
'
)
const
{
encodePath
,
fileToPath
,
sort
,
getGitLastUpdatedTimeStamp
}
=
require
(
'
./util
'
)
const
{
encodePath
,
fileToPath
,
sort
}
=
require
(
'
./util
'
)
const
{
const
{
inferTitle
,
inferTitle
,
extractHeaders
,
extractHeaders
,
...
@@ -117,33 +117,22 @@ module.exports = async function resolveOptions (sourceDir) {
...
@@ -117,33 +117,22 @@ module.exports = async function resolveOptions (sourceDir) {
// resolve pageFiles
// resolve pageFiles
const
pageFiles
=
sort
(
await
globby
([
'
**/*.md
'
,
'
!.vuepress
'
,
'
!node_modules
'
],
{
cwd
:
sourceDir
}))
const
pageFiles
=
sort
(
await
globby
([
'
**/*.md
'
,
'
!.vuepress
'
,
'
!node_modules
'
],
{
cwd
:
sourceDir
}))
// resolve lastUpdated
const
shouldResolveLastUpdated
=
(
themeConfig
.
lastUpdated
||
Object
.
keys
(
siteConfig
.
locales
&&
themeConfig
.
locales
||
{})
.
some
(
base
=>
themeConfig
.
locales
[
base
].
lastUpdated
)
)
// resolve pagesData
// resolve pagesData
const
pagesData
=
await
Promise
.
all
(
pageFiles
.
map
(
async
(
fil
e
)
=>
{
const
pagesData
=
await
Promise
.
all
(
pageFiles
.
map
(
async
(
relativ
e
)
=>
{
const
filepath
=
path
.
resolve
(
sourceDir
,
fil
e
)
const
filepath
=
path
.
resolve
(
sourceDir
,
relativ
e
)
const
key
=
'
v-
'
+
Math
.
random
().
toString
(
16
).
slice
(
2
)
const
key
=
'
v-
'
+
Math
.
random
().
toString
(
16
).
slice
(
2
)
const
data
=
{
const
data
=
{
key
,
key
,
path
:
encodePath
(
fileToPath
(
fil
e
))
path
:
encodePath
(
fileToPath
(
relativ
e
))
}
}
for
(
const
fn
of
plugin
.
apis
.
extendPageData
)
{
for
(
const
fn
of
plugin
.
apis
.
extendPageData
)
{
const
res
=
await
fn
(
file
)
const
res
=
await
fn
(
{
filepath
,
relative
,
key
,
sourceDir
}
)
if
(
typeof
res
===
'
object
'
)
{
if
(
typeof
res
===
'
object
'
)
{
Object
.
assign
(
data
,
res
)
Object
.
assign
(
data
,
res
)
}
}
}
}
if
(
shouldResolveLastUpdated
)
{
data
.
lastUpdated
=
getGitLastUpdatedTimeStamp
(
filepath
)
}
// extract yaml frontmatter
// extract yaml frontmatter
const
content
=
await
fs
.
readFile
(
filepath
,
'
utf-8
'
)
const
content
=
await
fs
.
readFile
(
filepath
,
'
utf-8
'
)
const
frontmatter
=
parseFrontmatter
(
content
)
const
frontmatter
=
parseFrontmatter
(
content
)
...
...
lib/prepare/util.js
浏览文件 @
50e34673
const
path
=
require
(
'
path
'
)
const
path
=
require
(
'
path
'
)
const
spawn
=
require
(
'
cross-spawn
'
)
const
fs
=
require
(
'
fs-extra
'
)
const
fs
=
require
(
'
fs-extra
'
)
const
globby
=
require
(
'
globby
'
)
const
globby
=
require
(
'
globby
'
)
...
@@ -74,7 +73,3 @@ exports.sort = function (arr) {
...
@@ -74,7 +73,3 @@ exports.sort = function (arr) {
exports
.
encodePath
=
function
(
userpath
)
{
exports
.
encodePath
=
function
(
userpath
)
{
return
userpath
.
split
(
'
/
'
).
map
(
item
=>
encodeURIComponent
(
item
)).
join
(
'
/
'
)
return
userpath
.
split
(
'
/
'
).
map
(
item
=>
encodeURIComponent
(
item
)).
join
(
'
/
'
)
}
}
exports
.
getGitLastUpdatedTimeStamp
=
function
(
filepath
)
{
return
parseInt
(
spawn
.
sync
(
'
git
'
,
[
'
log
'
,
'
-1
'
,
'
--format=%ct
'
,
filepath
]).
stdout
.
toString
(
'
utf-8
'
))
*
1000
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录