# @mdpress/plugin-last-updated

last-updated plugin for MdPress

If you use the default theme, you don't need to install this plugin, because the plugin is already included in the core of MdPress, 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

module.exports = {
  plugins: ['@mdpress/last-updated']
}

# 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.

const moment = require('moment');

module.exports = {
  plugins: [
    [
      '@mdpress/last-updated',
      {
        transformer: (timestamp, lang) => {
          // Don't forget to install moment yourself
          const moment = require('moment')
          moment.locale(lang)
          return moment(timestamp).fromNow()
        }
      }
    ]
  ]
}

::: 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 MdPress, we follow this spec: W3C > Language tags in HTML and XML, 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. :::

# dateOptions

  • Type: object
  • Default: undefined

You can also pass in an options object to customize the timestamp output. For more properties check Date.prototype.toLocaleString() options argument


module.exports = {
  plugins: [
    [
      '@mdpress/last-updated',
      {
        dateOptions:{
          hours12: false
        }
      }
    ]
  ]
}