README.rst 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. Use git commit to determine page date
  2. ======================================
  3. If the blog content is managed by git repo, this plugin will set articles'
  4. and pages' ``metadata['date']`` according to git commit. This plugin depends
  5. on python package ``gitpython``, install::
  6. pip install gitpython
  7. The determine logic will works so:
  8. * if a file is not tracked by git, or a file is staged but never commited
  9. - metadata['date'] = fs time
  10. - metadata['updated'] = fs time
  11. * if a file is tracked, but no changes in stage area or work dir
  12. - metadata['date'] = first commit time
  13. - metadata['updated'] = last commit time
  14. * if a file is tracked, and has changes in stage area or work dir
  15. - metadata['date'] = first commit time
  16. - metadata['updated'] = fs time
  17. When this module is enabled, ``date`` and ``updated`` will be set automatically
  18. by git status, no need to manually set in article/page's metadata. And
  19. operations like copy, move will not affect the generated results.
  20. If some article or page doesn't like to use git time, set a ``gittime: off``
  21. metadata to disable it.
  22. Some notes on git
  23. ~~~~~~~~~~~~~~~~~~
  24. * How to check if a file is managed?
  25. .. code-block:: sh
  26. git ls-files $file --error-unmatch
  27. * How to check if a file has changes?
  28. .. code-block:: sh
  29. git diff $file # compare staged area with working directory
  30. git diff --cached $file # compare HEAD with staged area
  31. git diff HEAD $file # compare HEAD with working directory
  32. * How to get commits related to a file?
  33. .. code-block:: sh
  34. git status $file
  35. with ``gitpython`` package, it's easier to parse commited time:
  36. .. code-block:: python
  37. repo = Git.repo('/path/to/repo')
  38. commits = repo.commits(path='path/to/file')
  39. commits[-1].committed_date # oldest commit time
  40. commits[0].committed_date # latest commit time