소스 검색

Merge pull request #270 from tomasherman/master

Generate locale_date and locale_modified and rename update to modified in filetime_from_git
Justin Mayer 11 년 전
부모
커밋
b6b449b24d
1개의 변경된 파일13개의 추가작업 그리고 4개의 파일을 삭제
  1. 13 4
      filetime_from_git/filetime_from_git.py

+ 13 - 4
filetime_from_git/filetime_from_git.py

@@ -6,6 +6,7 @@ from git import Git, Repo, InvalidGitRepositoryError
 from pelican import signals, contents
 from pelican import signals, contents
 from datetime import datetime
 from datetime import datetime
 from time import mktime, altzone
 from time import mktime, altzone
+from pelican.utils import  strftime
 
 
 try:
 try:
     repo = Repo(os.path.abspath('.'))
     repo = Repo(os.path.abspath('.'))
@@ -48,13 +49,21 @@ def filetime_from_git(content):
                     with_extended_output=True, with_exceptions=False)
                     with_extended_output=True, with_exceptions=False)
             if status != 0:
             if status != 0:
                 # file has changed
                 # file has changed
-                content.updated = datetime.fromtimestamp(os.stat(path).st_ctime)
+                content.modified = datetime.fromtimestamp(os.stat(path).st_ctime)
             else:
             else:
                 # file is not changed
                 # file is not changed
                 if len(commits) > 1:
                 if len(commits) > 1:
-                    content.updated = datetime.fromtimestamp(mktime(commits[0].committed_date) - altzone)
-    if not hasattr(content, 'updated'):
-        content.updated = content.date
+                    content.modified = datetime.fromtimestamp(mktime(commits[0].committed_date) - altzone)
+    if not hasattr(content, 'modified'):
+        content.modified = content.date
+    if hasattr(content, 'date'):
+        content.locale_date = strftime(content.date, content.date_format)
+    if hasattr(content, 'modified'):
+        content.locale_modified = strftime(content.modified, content.date_format)
+
+
+
+
 
 
 def register():
 def register():
     signals.content_object_init.connect(filetime_from_git)
     signals.content_object_init.connect(filetime_from_git)