Finished refactorization, need to test the whole thing
This commit is contained in:
parent
74102b2a08
commit
6c95856cbc
@ -145,6 +145,10 @@ modified_files = []
|
|||||||
deleted_files = []
|
deleted_files = []
|
||||||
added_files = []
|
added_files = []
|
||||||
|
|
||||||
|
#Lists of years and months with modified files
|
||||||
|
years_list = []
|
||||||
|
months_list = []
|
||||||
|
|
||||||
if not force_regen:
|
if not force_regen:
|
||||||
# Find the changes to be committed
|
# Find the changes to be committed
|
||||||
try:
|
try:
|
||||||
@ -190,9 +194,16 @@ for filename in list(added_files):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
int(filename[4:8])
|
int(filename[4:8])
|
||||||
|
years_list.append(filename[4:8])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
direct_copy = True
|
direct_copy = True
|
||||||
|
|
||||||
|
try:
|
||||||
|
int(filename[8:10])
|
||||||
|
months_list.append(filename[8:10])
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
if ((not filename.endswith(".html") and not filename.endswith(".ignore"))
|
if ((not filename.endswith(".html") and not filename.endswith(".ignore"))
|
||||||
or direct_copy):
|
or direct_copy):
|
||||||
# Note : this deal with CSS, images or footer file
|
# Note : this deal with CSS, images or footer file
|
||||||
@ -216,12 +227,18 @@ for filename in list(modified_files):
|
|||||||
if not filename.startswith("raw/"):
|
if not filename.startswith("raw/"):
|
||||||
modified_files.remove(filename)
|
modified_files.remove(filename)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
int(filename[4:6])
|
int(filename[4:8])
|
||||||
|
years_list.append(filename[4:8])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
direct_copy = True
|
direct_copy = True
|
||||||
|
|
||||||
|
try:
|
||||||
|
int(filename[8:10])
|
||||||
|
months_list.append(filename[8:10])
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
if ((not filename.endswith("html") and not filename.endswith("ignore"))
|
if ((not filename.endswith("html") and not filename.endswith("ignore"))
|
||||||
or direct_copy):
|
or direct_copy):
|
||||||
print("[INFO] (Direct copy) Updating directly the file "
|
print("[INFO] (Direct copy) Updating directly the file "
|
||||||
@ -245,10 +262,16 @@ for filename in list(deleted_files):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
int(filename[4:6])
|
int(filename[4:8])
|
||||||
|
years_list.append(filename[4:8])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
direct_delete = True
|
direct_delete = True
|
||||||
continue
|
|
||||||
|
try:
|
||||||
|
int(filename[8:10])
|
||||||
|
months_list.append(filename[8:10])
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
if ((not filename.endswith("html") and not filename.endswith("ignore"))
|
if ((not filename.endswith("html") and not filename.endswith("ignore"))
|
||||||
or direct_delete):
|
or direct_delete):
|
||||||
@ -638,7 +661,6 @@ for filename in added_files+modified_files:
|
|||||||
filename[4:]+" page.")
|
filename[4:]+" page.")
|
||||||
|
|
||||||
# Regenerate page for years / months
|
# Regenerate page for years / months
|
||||||
years_list = os.listdir("blog/")
|
|
||||||
years_list.sort(reverse=True)
|
years_list.sort(reverse=True)
|
||||||
for i in years_list:
|
for i in years_list:
|
||||||
try:
|
try:
|
||||||
@ -649,25 +671,29 @@ for i in years_list:
|
|||||||
# Generate page per year
|
# Generate page per year
|
||||||
page_year = header.replace("@title", params["BLOG_TITLE"]+" - "+i, 1)
|
page_year = header.replace("@title", params["BLOG_TITLE"]+" - "+i, 1)
|
||||||
|
|
||||||
months_list = os.listdir("blog/"+i)
|
|
||||||
months_list.sort(reverse=True)
|
months_list.sort(reverse=True)
|
||||||
for j in months_list:
|
for j in months_list:
|
||||||
if not os.path.isdir("blog/"+i+"/"+j):
|
if not os.path.isdir("blog/"+i+"/"+j):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Generate pages per month
|
# Generate pages per month
|
||||||
page_month = header.replace("@title", params["BLOG_TITLE"]+" - "+i+"/"+j, 1)
|
page_month = header.replace("@title",
|
||||||
|
params["BLOG_TITLE"]+" - "+i+"/"+j, 1)
|
||||||
|
|
||||||
articles_list = list_directory("gen/"+i+"/"+j)
|
articles_list = list_directory("gen/"+i+"/"+j)
|
||||||
articles_list.sort(key=lambda x: os.stat(x).st_mtime, reverse=True)
|
articles_list.sort(key=lambda x: os.stat(x).st_mtime, reverse=True)
|
||||||
for article in articles_list:
|
for article in articles_list:
|
||||||
try:
|
try:
|
||||||
with open(article, "r") as article_fh:
|
with open(article, "r") as article_fh:
|
||||||
article_content = replace_tags(article_fh.read(), search_list, replace_list)
|
article_content = replace_tags(article_fh.read(),
|
||||||
|
search_list, replace_list)
|
||||||
page_month += article_content
|
page_month += article_content
|
||||||
page_year += article_content
|
page_year += article_content
|
||||||
except IOError:
|
except IOError:
|
||||||
sys.exit("[ERROR] Error while generating years and months pages. Check your gen folder, you may need to regenerate some articles. The error was due to "+article+".")
|
sys.exit("[ERROR] Error while generating years and "
|
||||||
|
"months pages. Check your gen folder, you "
|
||||||
|
"may need to regenerate some articles. The "
|
||||||
|
"error was due to "+article+".")
|
||||||
|
|
||||||
page_month += footer
|
page_month += footer
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user