diff --git a/pre-commit.py b/pre-commit.py index 39f82dc..7570b55 100755 --- a/pre-commit.py +++ b/pre-commit.py @@ -27,6 +27,7 @@ import subprocess import re import locale +from functools import cmp_to_key from time import gmtime, strftime, mktime from bs4 import BeautifulSoup @@ -110,7 +111,8 @@ def latest_articles(directory, number): latest_articles = latest_articles.strip().split("\n") latest_articles = [x for x in latest_articles if(isint(x[4:8]) and x.endswith(".html"))] - latest_articles.sort(key=lambda x: get_date(x), + latest_articles.sort(key=lambda x: (get_date(x)[4:8], get_date(x)[2:4], + get_date(x)[:2], get_date(x)[9:]), reverse=True) return latest_articles[:number] @@ -146,6 +148,9 @@ def get_text_rss(content): title.extract() return str(soup.div) +def remove_tags(html): + return ''.join( BeautifulSoup(html).findAll(text = True)) + # Set locale locale.setlocale(locale.LC_ALL, '') @@ -248,10 +253,13 @@ if not force_regen: else: try: shutil.rmtree("blog/") - shutil.rmtree("gen/") - added_files = list_directory("raw") except FileNotFoundError: pass + try: + shutil.rmtree("gen/") + except FileNotFoundError: + pass + added_files = list_directory("raw") if not added_files and not modified_files and not deleted_files: sys.exit("[ERROR] Nothing to do... Did you add new files with " @@ -582,11 +590,14 @@ for filename in added_files+modified_files: # Starting to generate header file (except title) tags_header = "" -for tag in tags_full_list: +for tag in sorted(tags_full_list, key=cmp_to_key(locale.strcoll)): + with open("gen/tags/"+tag[9:-4]+".tmp", "r") as tag_fh: + nb = len(tag_fh.readlines()) + tags_header += "