From 272df57421d20907b5a1edecabcaad649641e791 Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Wed, 9 May 2018 00:15:58 +0800 Subject: [PATCH] feat: last updated UI in default theme. (#338) --- docs/.vuepress/config.js | 2 ++ docs/default-theme-config/README.md | 20 +++++++++++++- docs/guide/custom-themes.md | 7 ++--- docs/zh/default-theme-config/README.md | 18 +++++++++++++ docs/zh/guide/basic-config.md | 2 +- docs/zh/guide/custom-themes.md | 8 +++--- docs/zh/guide/deploy.md | 2 +- docs/zh/guide/markdown.md | 2 +- docs/zh/guide/using-vue.md | 4 +-- lib/default-theme/Page.vue | 36 ++++++++++++++++++++++++++ lib/prepare.js | 15 ++++++++--- lib/util/index.js | 4 +-- 12 files changed, 102 insertions(+), 18 deletions(-) diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 5b3f866095..ad70d04dba 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -34,6 +34,7 @@ module.exports = { label: 'English', selectText: 'Languages', editLinkText: 'Edit this page on GitHub', + lastUpdated: 'Last Updated', nav: [ { text: 'Guide', @@ -56,6 +57,7 @@ module.exports = { label: '简体中文', selectText: '选择语言', editLinkText: '在 GitHub 上编辑此页', + lastUpdated: '上次更新', nav: [ { text: '指南', diff --git a/docs/default-theme-config/README.md b/docs/default-theme-config/README.md index 8a2ea09f6e..577419a14d 100644 --- a/docs/default-theme-config/README.md +++ b/docs/default-theme-config/README.md @@ -267,7 +267,7 @@ Built-in Search only builds index from the title, `h2` and `h3` headers, if you The `themeConfig.algolia` option allows you to use [Algolia DocSearch](https://community.algolia.com/docsearch/) to replace the simple built-in search. To enable it, you need to provide at least `apiKey` and `indexName`: -```js +``` js module.exports = { themeConfig: { algolia: { @@ -280,6 +280,24 @@ module.exports = { For more options, refer to [Algolia DocSearch's documentation](https://github.com/algolia/docsearch#docsearch-options). +## Last Updated + +The `themeConfig.lastUpdated` option allows you to get the UNIX timestamp(ms) of each file's last `git` commit, and it will also display at the bottom of each page with a appropriate format: + +``` js +module.exports = { + themeConfig: { + lastUpdated: 'Last Updated', // string | boolean + } +} +``` + +Note that it's `off` by default. If given `string`, it will be displayed as a prefix (default value: `Last Updated`). + +::: warning + Since `lastUpdated` is based on `git`, so you can only use it in a `git` repository. +::: + ## Prev / Next Links Prev and next links are automatically inferred based on the sidebar order of the active page. You can also explicitly overwrite or disable them using `YAML front matter`: diff --git a/docs/guide/custom-themes.md b/docs/guide/custom-themes.md index 190173df77..8c3dbd94eb 100644 --- a/docs/guide/custom-themes.md +++ b/docs/guide/custom-themes.md @@ -28,7 +28,7 @@ This is the value of `$site` of this very website: "base": "/", "pages": [ { - "lastModified": 1524027677, + "lastUpdated": 1524027677000, "path": "/", "title": "VuePress", "frontmatter": {} @@ -44,7 +44,7 @@ This is the `$page` object for this page you are looking at: ``` json { - "lastModified": 1524847549, + "lastUpdated": 1524847549000, "path": "/guide/custom-themes.html", "title": "Custom Themes", "headers": [/* ... */], @@ -57,7 +57,8 @@ If the user provided `themeConfig` in `.vuepress/config.js`, it will also be ava Finally, don't forget that `this.$route` and `this.$router` are also available as part of Vue Router's API. ::: tip - `lastModified` is the UNIX timestamp of this file's last git commit, so please ensure you have git installed. + `lastUpdated` is the UNIX timestamp of this file's last git commit, for more details, refer to [Last Updated](../default-theme-config/#last-updated). + ::: ## Content Excerpt diff --git a/docs/zh/default-theme-config/README.md b/docs/zh/default-theme-config/README.md index 97d444bebb..2848312092 100644 --- a/docs/zh/default-theme-config/README.md +++ b/docs/zh/default-theme-config/README.md @@ -276,6 +276,24 @@ module.exports = { 更多选项请参考 [Algolia DocSearch 的文档](https://github.com/algolia/docsearch#docsearch-options)。 +## 最近更新 + +你可以通过 `themeConfig.lastUpdated` 选项来获取每个文件最后一次 `git` 提交的 UNIX 时间戳(ms),同时它将以合适的日期格式显示在每一页的底部: + +``` js +module.exports = { + themeConfig: { + lastUpdated: 'Last Updated', // string | boolean + } +} +``` + +请注意,`themeConfig.lastUpdated` 默认是关闭的,如果给定一个字符串,它将会作为前缀显示(默认值是:`Last Updated`)。 + +::: warning 使用须知 + 由于 `lastUpdated` 是基于 `git` 的, 所以你只能在一个基于 `git` 的项目中启用它。 +::: + ## 上 / 下一篇链接 上一篇和下一篇文章的链接将会自动地根据当前页面的侧边栏的顺序来获取。你也可以使用 `YAML front matter` 来明确地重写或者禁用它: diff --git a/docs/zh/guide/basic-config.md b/docs/zh/guide/basic-config.md index 7dfe504b52..b8a0b0a54b 100644 --- a/docs/zh/guide/basic-config.md +++ b/docs/zh/guide/basic-config.md @@ -32,7 +32,7 @@ module.exports = { 由于 VuePress 是一个标准的 Vue 应用,你可以通过创建一个 `.vuepress/enhanceApp.js` 文件来做一些应用级别的配置,当该文件存在的时候,会被导入到应用内部。`enhanceApp.js` 应该 `export default` 一个钩子函数,并接受一个包含了一些应用级别属性的对象作为参数。你可以使用这个钩子来安装一些附加的 Vue 插件、注册全局组件,或者增加额外的路由钩子等: -```js +``` js export default ({ Vue, // VuePress 正在使用的 Vue 构造函数 options, // 附加到根实例的一些选项 diff --git a/docs/zh/guide/custom-themes.md b/docs/zh/guide/custom-themes.md index 8b5ebffc3e..bbc6f19cc8 100644 --- a/docs/zh/guide/custom-themes.md +++ b/docs/zh/guide/custom-themes.md @@ -28,7 +28,7 @@ VuePress 使用单文件组件来构建自定义主题。想要开发一个自 "base": "/", "pages": [ { - "lastModified": 1524027677, + "lastUpdated": 1524027677000, "path": "/", "title": "VuePress", "frontmatter": {} @@ -44,7 +44,7 @@ VuePress 使用单文件组件来构建自定义主题。想要开发一个自 ``` json { - "lastModified": 1524847549, + "lastUpdated": 1524847549000, "path": "/custom-themes.html", "title": "自定义主题", "headers": [/* ... */], @@ -57,7 +57,7 @@ VuePress 使用单文件组件来构建自定义主题。想要开发一个自 最后,别忘了,作为 Vue Router API 的一部分,`this.$route` 和 `this.$router` 同样可以使用。 ::: tip 提示 - `lastModified` 是这个文件最后一次 git 提交的 unix 时间戳,所以请确保你已经安装了 git。 + `lastUpdated` 是这个文件最后一次 git 提交的 UNIX 时间戳,更多细节请参考:[最近更新](../default-theme-config/#最近更新)。 ::: ## 内容摘抄 @@ -80,7 +80,7 @@ VuePress 使用单文件组件来构建自定义主题。想要开发一个自 自定义主题也可以通过主题根目录下的 `enhanceApp.js` 文件来对 VuePress 应用进行拓展配置。这个文件应当 `export default` 一个钩子函数,并接受一个包含了一些应用级别属性的对象作为参数。你可以使用这个钩子来安装一些附加的 Vue 插件、注册全局组件,或者增加额外的路由钩子等: -```js +``` js export default ({ Vue, // VuePress 正在使用的 Vue 构造函数 options, // 附加到根实例的一些选项 diff --git a/docs/zh/guide/deploy.md b/docs/zh/guide/deploy.md index a79dd3357d..45979bb301 100644 --- a/docs/zh/guide/deploy.md +++ b/docs/zh/guide/deploy.md @@ -111,7 +111,7 @@ pages: ``` `.firebaserc`: - ```js + ``` js { "projects": { "default": "" diff --git a/docs/zh/guide/markdown.md b/docs/zh/guide/markdown.md index 7163f13137..01808d6038 100644 --- a/docs/zh/guide/markdown.md +++ b/docs/zh/guide/markdown.md @@ -38,7 +38,7 @@ └─ four.md ``` -```md +``` md [Home](/) [foo](/foo/) [foo heading anchor](/foo/#heading) diff --git a/docs/zh/guide/using-vue.md b/docs/zh/guide/using-vue.md index 2d1d6369ae..3a9dbca08c 100644 --- a/docs/zh/guide/using-vue.md +++ b/docs/zh/guide/using-vue.md @@ -131,7 +131,7 @@ export default { VuePress 对以下预处理器已经内置相关的 webpack 配置:`sass`、`scss`、`less`、`stylus` 和 `pug`。要使用它们你只需要在项目中安装对应的依赖即可。例如,要使用 `sass`,需要安装: -```bash +``` bash yarn add -D sass-loader node-sass ``` @@ -146,7 +146,7 @@ yarn add -D sass-loader node-sass 要在组件中使用 `