@@ -40,8 +40,26 @@ class CommandDeploy(Command):
40
40
doc_purpose = "display site status"
41
41
doc_description = "Show information about the posts and site deployment."
42
42
logger = None
43
-
44
- def _execute (self , command , args ):
43
+ cmd_options = [
44
+ {
45
+ 'name' : 'list_drafts' ,
46
+ 'short' : 'd' ,
47
+ 'long' : 'list-drafts' ,
48
+ 'type' : bool ,
49
+ 'default' : False ,
50
+ 'help' : 'List all drafts' ,
51
+ },
52
+ {
53
+ 'name' : 'list_scheduled' ,
54
+ 'short' : 's' ,
55
+ 'long' : 'list-scheduled' ,
56
+ 'type' : bool ,
57
+ 'default' : False ,
58
+ 'help' : 'List all scheduled posts' ,
59
+ },
60
+ ]
61
+
62
+ def _execute (self , options , args ):
45
63
46
64
self .site .scan_posts ()
47
65
@@ -73,23 +91,29 @@ def _execute(self, command, args):
73
91
else :
74
92
print ("Last deployment {0} ago." .format (self .human_time (last_deploy_offset )))
75
93
94
+ now = datetime .utcnow ().replace (tzinfo = gettz ("UTC" ))
95
+
76
96
posts_count = len (self .site .all_posts )
77
- posts_drafts = 0
78
- posts_scheduled = 0
79
- nearest_scheduled_offset = None
80
-
81
- for post in self .site .all_posts :
82
- if post .is_draft :
83
- posts_drafts = posts_drafts + 1
84
- if post .publish_later :
85
- posts_scheduled = posts_scheduled + 1
86
- post_due_offset = post .date - datetime .utcnow ().replace (tzinfo = gettz ("UTC" ))
87
- if (nearest_scheduled_offset is None ) or (post_due_offset .seconds < nearest_scheduled_offset .seconds ):
88
- nearest_scheduled_offset = post_due_offset
89
-
90
- if posts_scheduled > 0 and nearest_scheduled_offset is not None :
91
- print ("{0} to next scheduled post." .format (self .human_time (nearest_scheduled_offset )))
92
- print ("{0} posts in total, {1} scheduled, and {2} drafts." .format (posts_count , posts_scheduled , posts_drafts ))
97
+
98
+ # find all drafts
99
+ posts_drafts = [post for post in self .site .all_posts if post .is_draft ]
100
+ posts_drafts = sorted (posts_drafts , key = lambda post : post .source_path )
101
+
102
+ # find all scheduled posts with offset from now until publishing time
103
+ posts_scheduled = [(post .date - now , post ) for post in self .site .all_posts if post .publish_later ]
104
+ posts_scheduled = sorted (posts_scheduled , key = lambda offset_post : (offset_post [0 ],offset_post [1 ].source_path ))
105
+
106
+ if len (posts_scheduled ) > 0 :
107
+ if options ['list_scheduled' ]:
108
+ for offset , post in posts_scheduled :
109
+ print ("Scheduled: '{1}' ({2}; source: {3}) in {0}" .format (self .human_time (offset ), post .meta ('title' ), post .permalink (), post .source_path ))
110
+ else :
111
+ offset , post = posts_scheduled [0 ]
112
+ print ("{0} to next scheduled post ('{1}'; {2}; source: {3})." .format (self .human_time (offset ), post .meta ('title' ), post .permalink (), post .source_path ))
113
+ if options ['list_drafts' ]:
114
+ for post in posts_drafts :
115
+ print ("Draft: '{0}' ({1}; source: {2})" .format (post .meta ('title' ), post .permalink (), post .source_path ))
116
+ print ("{0} posts in total, {1} scheduled, and {2} drafts." .format (posts_count , len (posts_scheduled ), len (posts_drafts )))
93
117
94
118
def human_time (self , dt ):
95
119
days = dt .days
0 commit comments