@vuepress/plugin-last-updated

last-updated plugin for VuePress

If you use the default theme, you don't need to install this plugin, because the plugin is already included in the core of VuePress, and you should use the themeConfig.lastUpdated option directly.

If you use it at your custom theme, you'll need to handle the UI by yourself, and you can use $page.lastUpdated to access the date string.

Usage

  1. module.exports = {
  2. plugins: ['@vuepress/last-updated']
  3. }

Options

transformer

  • Type: (timestamp: number, lang: string) => string
  • Default: undefined

By default, this plugin produces a 13-bit timestamp for each page, you can also pass in a transformer to convert it to any format that you want.

e.g.

  1. const moment = require('moment');
  2. module.exports = {
  3. plugins: [
  4. [
  5. '@vuepress/last-updated',
  6. {
  7. transformer: (timestamp, lang) => {
  8. // Don't forget to install moment yourself
  9. const moment = require('moment')
  10. moment.locale(lang)
  11. return moment(timestamp).fromNow()
  12. }
  13. }
  14. ]
  15. ]
  16. }

TIP

If you are running in i18n mode, you can also use the second argument lang to generate time strings for different languages.

Note that in VuePress, we follow this spec: W3C > Language tags in HTML and XMLlast-updated - 图1, so en-US uses hyphens (-) instead of underscores (_). Please make sure that the library you are using follows this spec, otherwise please convert it yourself.