Skip to main content

An easy-to-use, lightweight MkDocs plugin for displaying the exact creation time, last modification time and author info of markdown documents.

Project description

mkdocs-document-dates

English | 简体中文

An easy-to-use, lightweight MkDocs plugin for displaying the exact creation time, last modification time and author info of markdown documents.

Features

  • Work in any environment, for Git-less environments, CI/CD environments (e.g. GitHub Actions), one-person collaboration, multi-person collaboration, etc
  • Support for manually specifying time and author info in Front Matter
  • Support for multiple time formats (date, datetime, timeago)
  • Support for document exclusion mode
  • Flexible display position (top or bottom)
  • Elegant styling (fully customizable)
  • Supports Tooltip Hover Tips
    • Intelligent repositioning to always float optimally in view
    • Supports automatic theme switching following Material's light/dark color scheme
    • Support for customizing themes, styles, animations
    • Compatible with mouse, keyboard and touch (mobile) to trigger hover
  • Multi-language support, cross-platform support (Windows, macOS, Linux)

Showcases

render

Installation

pip install mkdocs-document-dates

Configuration

Just add the plugin to your mkdocs.yml:

plugins:
  - document-dates

Or, personalize the configuration:

plugins:
  - document-dates:
      position: top            # Display position: top (after title)  bottom (end of document), default: bottom
      type: date               # Date type: date  datetime  timeago, default: date
      locale: en               # Localization: zh zh_tw en es fr de ar ja ko ru, default: en
      date_format: '%Y-%m-%d'  # Date format, Supports all Python datetime format strings, e.g., %Y-%m-%d, %b %d, %Y, etc
      time_format: '%H:%M:%S'  # Time format (valid only if type=datetime)
      exclude:                 # List of excluded files
        - temp.md              # Exclude specific file
        - private/*            # Exclude all files in private directory, including subdirectories
        - drafts/*.md          # Exclude all markdown files in the current directory drafts, but not subdirectories
      
      show_author: true        # Whether to display author: true false, default: true

Specify time manually

The plugin will automatically get the exact time of the document, will automatically cache the creation time, but of course, you can also specify it manually in Front Matter

Priority: Front Matter > Cache Files > File System Timestamps

---
created: 2023-01-01
modified: 2025-02-23
---

# Document Title
  • created can be replaced with: created, date, creation
  • modified can be replaced with: modified, updated, last_modified, last_updated

Specify author manually

The plugin will automatically get the author of the document, will parse the email and make a link, also you can specify it manually in Front Matter

Priority: Front Matter > Git Author Info > PC Username

---
author: any-name
email: e-name@gmail.com
---

# Document Title
  • author can be replaced with: author, name
  • email can be replaced with: email, mail

Customization

The plugin supports deep customization, such as icon style, font style, theme color, animation type, dividing line, etc. All of it can be customized by modifying the code in the corresponding file (I've already written the code and comments, you just need to turn on the switch and change the value, it's super easy):

  • Style & Theme: docs/assets/document_dates/user.config.css
  • Properties & Animations: docs/assets/document_dates/user.config.js
  • Localized languages: docs/assets/document_dates/languages/ , refer to the template file en.json for any additions or modifications

Note: Due to the redesign of the configuration file update mechanism, the configuration file starting with document-dates.config in the previous version has been canceled and replaced by user.config

Other Tips

  • In order to get the exact creation time, a separate cache file is used to store the creation time of the file, located in the doc folder (hidden by default), please don't delete it:
    • docs/.dates_cache.jsonl, cache file (.json without the l is the old cache file and will be automatically migrated to .jsonl after any git commit)
    • docs/.gitattributes, configuration file (merge mechanism for cache file in case of multi-person collaboration)
  • The Git Hooks mechanism is used to automatically trigger the storing of the cache (every time executes a git commit), and the cached file is automatically committed along with it
  • The installation of Git Hooks is automatically triggered when the plugin is installed
  • The above actions are fully automated without any manual intervention, applicable to any environment, and have been tested and validated in Git-less environments, CI/CD environments (e.g., GitHub Actions), one-person collaborations, multi-person collaborations, etc

Development Stories (Optional)

A dispensable, insignificant little plug-in, friends who have nothing to do can take a look ^_^

  • Origin:
    • Because mkdocs-git-revision-date-localized-plugin, a great project. When I used it at the end of 2024, I found that I couldn't use it locally because my mkdocs documentation was not included in git management, then I don't understand why not read the file system time, but to use the git time, and raised an issue to the author, but didn't get a reply for about a week (the author had a reply later, nice guy, I guess he was busy at the time), and then I thought, there is nothing to do during the Chinese New Year, and now AI is so hot, why not with the help of the AI try it out for myself, it was born, born in February 2025
  • Iteration:
    • After development, I understood why not use filesystem time, because files will be rebuilt when they go through git checkout or clone, resulting in the loss of original timestamp information, and there are many solutions:
    • Method 1: Use the last git commit time as the last update time, and the first git commit time as the creation (there is a margin of error, but it's acceptable), mkdocs-git-revision-date-localized-plugin does this
    • Method 2: You can cache the original time, and then read the cache subsequently. The cache can be in Front Matter of the source document or in a separate file, I chose the latter. Existing in the Front Matter is very reasonable and simple, but this will modify the source content of the document, although it doesn't have any impact on the body, but I still want to ensure the originality of the data!
  • Difficulty:
    1. When to read and store raw time? This is just a plugin for mkdocs, with very limited access and permissions, mkdocs provides only build and serve, so in case a user commits directly without executing build or serve (e.g., when using a CI/CD build system), then you won't be able to retrieve the time information of the file, not to mention caching it!
      • Let's take a straight shot: the Git Hooks mechanism was found, prompted by the AI, which can trigger a custom script when a specific action occurs, such as every time commit is performed
    2. How can I ensure that a single cache file does not conflict when collaborating with multi-person?
      • My solution: use JSONL (JSON Lines) instead of JSON, and with the merge strategy 'merge=union'
  • Improve:
    • Since it has been re-developed, it will be designed in the direction of excellent products, and the pursuit of the ultimate ease of use, simplicity and personalization
      • Ease of use: don't let users do things manually if you can, e.g., auto-install Git Hooks, auto-cache, auto-commit, provide customized templates, etc
      • Simplicity: no unnecessary configurations, the less the simpler, e.g. git account information, repo information, etc., are not required
      • Personalization: almost everything can be customized, whether it's icons, styles, themes, or features, it's all fully customizable
    • In addition, it has good compatibility and extensibility, and works well in WIN7, mobile devices, old Safari, etc
  • The Last Secret:
    • I'm not a programmer, my main job is marketing, can you believe it? (Feel free to leave a comment)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mkdocs_document_dates-3.1.tar.gz (39.9 kB view details)

Uploaded Source

File details

Details for the file mkdocs_document_dates-3.1.tar.gz.

File metadata

  • Download URL: mkdocs_document_dates-3.1.tar.gz
  • Upload date:
  • Size: 39.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for mkdocs_document_dates-3.1.tar.gz
Algorithm Hash digest
SHA256 2e07635b7b0c361f97ebae360c37233c6c61ae11f0f316b5ebc8b5210fd74241
MD5 b4e2ea9dd7ddec94b21a7a84c63a5fa6
BLAKE2b-256 64eb52fe21faf76355e9b2b0bd5d5c502d94f105beac549cbcce5145f9554fd9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page