README.rst 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. Some notes on git
  21. ~~~~~~~~~~~~~~~~~~
  22. * How to check if a file is managed?
  23. .. code-block:: sh
  24. git ls-files $file --error-unmatch
  25. * How to check if a file has changes?
  26. .. code-block:: sh
  27. git diff $file # compare staged area with working directory
  28. git diff --cached $file # compare HEAD with staged area
  29. git diff HEAD $file # compare HEAD with working directory
  30. * How to get commits related to a file?
  31. .. code-block:: sh
  32. git status $file
  33. with ``gitpython`` package, it's easier to parse commited time:
  34. .. code-block:: python
  35. repo = Git.repo('/path/to/repo')
  36. commits = repo.commits(path='path/to/file')
  37. commits[-1].committed_date # oldest commit time
  38. commits[0].committed_date # latest commit time