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
193 stars 39 forks source link

Edited and Created time become same when publishing with github pages #100

Closed zerenxyz closed 1 year ago

zerenxyz commented 1 year ago

I am using mkdocs-material-insiders (this issue is also the same with mkdocs-material, the example below does the same issue for me) with the plugin, locally the file last edited and created date work correctly, when updating document it only updates last edited time. However, when pushing to github repo and publishing the site with workflow/ci.yml it updates both last edited and created time to when the site was published that moment.

Here is my project setup: (You can access the repo in https://github.com/zerenxyz/mkdocs-material-plugin its public, I made it to test and it is still happening on a fresh install) mkdocs.yml

site_name: My Docs
repo_url: https://github.com/zerenxyz/mkdocs-material-plugin.git
theme:
  name: material

plugins:
  - git-revision-date-localized:
      enable_creation_date: true
      type: timeago

ci.yml

name: ci 
on:
  push:
    branches:
      - main
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: 3.x
      - run: pip install mkdocs-material 
      - name: Install Plugins
        run: |
          pip install \
            "mkdocs-git-revision-date-localized-plugin" \
      - run: mkdocs gh-deploy --force

I asked in the mkdocs-material matrix chat, and did try with fetch-depth=0 in the ci.yml but the issue still happens.

For me running the project locally works fine, but issue is when it is on github pages for some reason resets all of created time to be the same as edited time.

timvink commented 1 year ago

This plugin uses the git history to determine the creation date and the revision date. However, many build systems optimize by using git clone --depth 1, meaning they only download the last commit. That means the last revision date and the creation date become the same.

So you need to update your deployment. For instructions, see the README (screenshot below)

image

Or the documentation: https://timvink.github.io/mkdocs-git-revision-date-localized-plugin/index.html#note-when-using-build-environments

zerenxyz commented 1 year ago

Yup, I did set in the ci.yml (forgot to update the issue text) fetch-update=0 like so

- name: Checkout repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

so the build deployment looked like this:

name: ci 
on:
  push:
    branches:
      - main
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: 3.x
      - run: pip install mkdocs-material 
      - name: Install Plugins
        run: |
          pip install \
            "mkdocs-git-revision-date-localized-plugin" \
      - run: mkdocs gh-deploy --force

But the issue still happens, unless im not doing it correctly?

timvink commented 1 year ago

I don't think it's setup correctly. Your first checkout (with V3) is correct, but is then overwritten on your second checkout (with V2).

Remove the line with - uses: actions/checkout@v2

timvink commented 1 year ago

@zerenxyz did that solve the issue for you?

zerenxyz commented 1 year ago

Apologies, I have been out of work for some time since I made this issue and did not get the chance to test it, I willt test it tomorrow and let you know! Sorry for the delay!

zerenxyz commented 1 year ago

@timvink I tested it with the solution and removing the - uses: actions/checkout@v2 was the issue and is now fixed! Thank you!

timvink commented 1 year ago

You're welcome!