19
19
# - images
20
20
# - content hash
21
21
# 2. mark the article if publish is true
22
- # 3. compare marked article hash with lockfile, update article if changed
22
+ # 3. compare marked article hash with lockfile
23
23
# in the lockfile:
24
24
# - if id exist
25
25
# - allow to publish, and content hash changed, update
26
26
# - disallow to publish, delete
27
- # - if id do not exist, publish as new article
27
+ # - if id does not exists
28
+ # - allow to publish, release the new article
29
+ # - disallow to publish, disregard
28
30
# 4. copy article to .content
29
31
# 5. copy all images to static-{{properties.title}} folder under ./content if has any
30
32
# 6. next article
31
33
#
32
34
# Requirements:
33
35
# 1. script should be able to dry run
34
- # 2. no 3th-part dependencies
36
+ # 2. no 3th-party dependencies
35
37
# 3. should not change article during the process
36
- # 4. Non declared "publish" equals false
38
+ # 4. non declared "publish" equals false
39
+ # 5. interrupting process should not cause state of lockfile loss
37
40
38
41
39
42
FILE_EXTENSION = ".md"
@@ -76,27 +79,29 @@ class Action:
76
79
# process individual file
77
80
for fname in os .listdir (OBVAULT_ARTICELS ):
78
81
if not fname .strip ().endswith (FILE_EXTENSION ):
79
- print (f"'{ fname } ' skipped, not a markdown file" )
82
+ print (f"'{ fname } ' skipped: not a markdown file" )
80
83
continue
81
84
82
85
with open (os .path .join (OBVAULT_ARTICELS , fname ), "r" ) as f :
83
86
print (f"process '{ fname } '..." )
84
87
if not f .readline ().strip ().startswith (PROPERTY_DELIMITER ):
85
- print ("file doesn't follow property format, skipped " )
88
+ print ("file skipped: doesn't follow property format" )
86
89
continue
87
90
88
91
# retrieve properties
89
92
meta = {"publish" :False , "fname" : fname }
90
93
line = f .readline ().strip ()
91
94
while not line .startswith (PROPERTY_DELIMITER ):
92
95
field = line .split (":" , 1 )
93
- h = RELEVANT_PROPERTY_HANDLER .get (field [0 ], None )
96
+ key = field [0 ].strip ()
97
+ h = RELEVANT_PROPERTY_HANDLER .get (key , None )
94
98
if h :
95
- meta [field [0 ]] = h (field [1 ])
99
+ val = field [1 ].strip ()
100
+ meta [key ] = h (val )
96
101
line = f .readline ().strip ()
97
102
98
103
# retrieve images and content hash of the article
99
- if meta .get ("publish" ):
104
+ if meta .get ("publish" ) is True :
100
105
# finds images of article and add to list
101
106
while line := f .readline ():
102
107
res = REGEX .search (line .strip ())
@@ -115,7 +120,7 @@ class Action:
115
120
# decides action to article
116
121
id = meta .get ("id" , None )
117
122
hash = meta .get ("hash" , None )
118
- if meta ["publish" ]:
123
+ if meta ["publish" ] is True :
119
124
if id not in lck :
120
125
meta .setdefault ("action" , Action .NEW )
121
126
elif lck .get (id ).get ("hash" , None ) != hash :
@@ -128,6 +133,7 @@ class Action:
128
133
ATCMETAARR .append (meta )
129
134
130
135
print ("\n ================================Dry Run Result================================\n " )
136
+
131
137
print (f"Articles ready to publish: { Action .NEW } , remove: { Action .DELETE } , update: { Action .UPDATE } \n " )
132
138
i = 1
133
139
for at in ATCMETAARR :
@@ -137,7 +143,11 @@ class Action:
137
143
print (f'images:{ at .get ("images" ,{})} ' )
138
144
print (f'\n ' )
139
145
i += 1
140
- print ("==============================================================================\n " )
146
+
147
+ if len (ATCMETAARR ) == 0 :
148
+ print ("nothing to update" )
149
+
150
+ print ("\n ==============================================================================\n " )
141
151
142
152
def apply ():
143
153
lckfnametemp = lckfname + ".tmp"
@@ -187,10 +197,7 @@ def apply():
187
197
188
198
189
199
if not DRYRUN :
190
- if len ( ATCMETAARR ) == 0 :
191
- print ( "nothing to update" )
200
+ if "yes" == input ( "type yes if you want to apply the change: \n \n " ) :
201
+ apply ( )
192
202
else :
193
- if "yes" == input ("type yes if you want to apply the change:\n \n " ):
194
- apply ()
195
- else :
196
- print ("operation abort" )
203
+ print ("operation abort" )
0 commit comments