README.rst 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. You can also set GIT_FILETIME_FOLLOW to True in your pelican config to
  23. make the plugin follow file renames i.e. ensure the creation date matches
  24. the original file creation date, not the date is was renamed.
  25. FAQ
  26. ---
  27. ### Q. I get a GitCommandError: 'git rev-list ...' when I run the plugin. What's up?
  28. Be sure to use the correct gitpython module for your distros git binary.
  29. Using the GIT_FILETIME_FOLLOW option to True may also make your problem go away as it uses
  30. a different method to find commits.
  31. Some notes on git
  32. ~~~~~~~~~~~~~~~~~~
  33. * How to check if a file is managed?
  34. .. code-block:: sh
  35. git ls-files $file --error-unmatch
  36. * How to check if a file has changes?
  37. .. code-block:: sh
  38. git diff $file # compare staged area with working directory
  39. git diff --cached $file # compare HEAD with staged area
  40. git diff HEAD $file # compare HEAD with working directory
  41. * How to get commits related to a file?
  42. .. code-block:: sh
  43. git status $file
  44. with ``gitpython`` package, it's easier to parse commited time:
  45. .. code-block:: python
  46. repo = Git.repo('/path/to/repo')
  47. commits = repo.commits(path='path/to/file')
  48. commits[-1].committed_date # oldest commit time
  49. commits[0].committed_date # latest commit time