timvink / mkdocs-git-revision-date-localized-plugin

MkDocs plugin to add a last updated date to your site pages
https://timvink.github.io/mkdocs-git-revision-date-localized-plugin/index.html
MIT License
206 stars 44 forks source link

`... has no git logs, using current timestamp` #54

Closed connerxyz closed 3 years ago

connerxyz commented 3 years ago

I'm looking to resolve getting warnings that git logs cannot be found for any files.

I thought it was my directory structure, which is non-standard, where we have MkDocs nested one level.

root/
  .git/
  ...
  docs/    <-- Where the MkDocs builds go
  docs-source/   <--  Where the MkDocs source is
    mkdocs.yml
    src/
    theme/

I tried copying root/.git to docs-source to test this, but got the same result.

Any advice? Thanks.

connerxyz commented 3 years ago

Ahh. I figured out why at least... I copy the files into docs-source/ from another directory... this other directory is where they are actually version controlled. Duh.

connerxyz commented 3 years ago

I was able to solve this by using the Util class and computing timeago myself.

# Roughly what I did...

from mkdocs_git_revision_date_localized_plugin.util import Util

u = Util()

...

unix_timestamp_last_updated = u.get_git_commit_timestamp(path=path)
date_last_updated = datetime.datetime.fromtimestamp(unix_timestamp_last_updated)
print(timeago.format(date_last_updated, datetime.datetime.now()))
timvink commented 3 years ago

Bit puzzled by this one though.

This plugin uses the on_page_markdown event to retrieve the absolute path of a markdown source file, and then extracts the date by running git commands on them:

https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/blob/9c6dd76ef567242425cecadcfd8ff3249f83da21/mkdocs_git_revision_date_localized_plugin/plugin.py#L151-L157

So a nested structure should not be an issue.

Which command do you use to build your docs? Do you define a docs_dir in your mkdocs.yml ?

joshooaj commented 1 year ago

Not OP but I had the same question today and this issue helped me realize what was happening.

In my case, the site has a combination of auto-generated docs from a PowerShell module, and manually created pages. The module docs are version controlled under docs/ (this was the path prior to starting to use mkdocs) while the content of the site is under mkdocs/ as it was easier to give mkdocs a custom docs folder name than to modify the build step to generate docs in a subfolder of docs.

The contents at docs/en-US/*.md are copied to to mkdocs/functions prior to invoking mkdocs so there is no git history for the files in that folder when mkdocs runs.

Going forward, I'll customize the build-step for generating/updating the PowerShell docs so I can have them placed directly in the mkdocs build folder rather than copy the latest versions of them over at build time.