diff --git a/pre-commit.py b/pre-commit.py
index 2a555e9..2ac5b65 100755
--- a/pre-commit.py
+++ b/pre-commit.py
@@ -28,6 +28,7 @@ import re
import locale
from time import gmtime, strftime, mktime
+from bs4 import BeautifulSoup
# =========
@@ -134,6 +135,16 @@ def replace_tags(article, search_list, replace_list):
return return_string
+# Return text in
for rss description
+# ========================================================
+def get_text_rss(content):
+ soup = BeautifulSoup(content)
+ date = soup.find(attrs={'class': 'date'})
+ date.extract()
+ title = soup.find(attrs={'class': 'article_title'})
+ title.extract()
+ return str(soup.div)
+
# Set locale
locale.setlocale(locale.LC_ALL, '')
@@ -175,12 +186,18 @@ try:
if line.strip() == "" or line.strip().startswith("#"):
continue
option, value = line.split("=", 1)
+ option = option.strip()
+
if option == "SEARCH":
search_list = [i.strip() for i in value.split(",")]
elif option == "REPLACE":
replace_list = [i.strip() for i in value.split(",")]
elif option == "MONTHS":
months = [i.strip() for i in value.split(",")]
+ elif option == "IGNORE_FILES":
+ params["IGNORE_FILES"] = [i.strip() for i in value.split(",")]
+ elif option == "BLOG_URL":
+ params["BLOG_URL"] = value.strip(" \n\t\r/")
else:
params[option.strip()] = value.strip()
@@ -190,6 +207,7 @@ except IOError:
"parameters. Does such a file exist ? See doc for more info "
"on this file.")
+print("[INFO] Blog url is "+params["BLOG_URL"]+".")
# Fill lists for modified, deleted and added files
modified_files = []
@@ -227,9 +245,12 @@ if not force_regen:
else:
sys.exit("[ERROR] An error occurred when running git diff.")
else:
- shutil.rmtree("blog/")
- shutil.rmtree("gen/")
- added_files = list_directory("raw")
+ try:
+ shutil.rmtree("blog/")
+ shutil.rmtree("gen/")
+ added_files = list_directory("raw")
+ except FileNotFoundError:
+ pass
if not added_files and not modified_files and not deleted_files:
sys.exit("[ERROR] Nothing to do... Did you add new files with "
@@ -239,7 +260,8 @@ if not added_files and not modified_files and not deleted_files:
for filename in list(added_files):
direct_copy = False
- if not filename.startswith("raw/"):
+ if (not filename.startswith("raw/") or filename.endswith("~") or
+ filename in params["IGNORE_FILES"]):
added_files.remove(filename)
continue
@@ -277,7 +299,8 @@ for filename in list(added_files):
for filename in list(modified_files):
direct_copy = False
- if not filename.startswith("raw/"):
+ if (not filename.startswith("raw/") or filename.endswith("~")
+ or filename in params["IGNORE_FILES"]):
modified_files.remove(filename)
continue
try:
@@ -312,7 +335,8 @@ for filename in list(modified_files):
for filename in list(deleted_files):
direct_copy = False
- if not filename.startswith("raw/"):
+ if (not filename.startswith("raw/") or filename.endswith("~") or
+ filename in params["IGNORE_FILES"]):
deleted_files.remove(filename)
continue
@@ -401,8 +425,8 @@ for filename in modified_files:
print("[INFO] (TAGS) No more article with tag " +
tag[8:-4]+", deleting it.")
except FileNotFoundError:
- print("[INFO] (TAGS) "+tag+" was found to be empty "
- "but there was an error during deletion. "
+ print("[INFO] (TAGS) "+tag+" was found to be empty"
+ " but there was an error during deletion. "
"You should check manually.")
tags.remove(tag_file[9:])
@@ -518,7 +542,9 @@ for filename in added_files+modified_files:
"\t\t
"
articles_index = ""
@@ -550,7 +576,7 @@ rss = ("\n"
"\n")
rss += ("\t"
- "\t\t\n"
"\t\t"+params["BLOG_TITLE"]+"\n"
"\t\t"+params["BLOG_URL"]+"\n"
@@ -589,7 +615,7 @@ for i, article in enumerate(["gen/"+x[4:-5]+".gen" for x in last_articles]):
if i < 5:
articles_header += "
"
@@ -601,11 +627,11 @@ for i, article in enumerate(["gen/"+x[4:-5]+".gen" for x in last_articles]):
rss += ("\t\t\n"
"\t\t\t"+title+"\n"
- "\t\t\t"+params["BLOG_URL"]+article[5:]+"\n"
+ "\t\t\t"+params["BLOG_URL"]+"/"+article[5:]+"\n"
"\t\t\t" +
- params["BLOG_URL"]+article[5:]+"\n"
+ params["BLOG_URL"]+"/"+article[5:]+"\n"
"\t\t\t\n"
"\t\t\t"+date_rss+"\n"
"\t\t\t"+', '.join(tags)+"\n"
@@ -614,7 +640,8 @@ for i, article in enumerate(["gen/"+x[4:-5]+".gen" for x in last_articles]):
# Finishing header gen
-articles_header += "