Add configurable subpath.

This commit is contained in:
Sergio Martínez Portela 2024-05-05 12:29:26 +02:00
parent d9b85c8475
commit ce35091852

View File

@ -46,13 +46,14 @@ IMG_EXTENSIONS = set([
"gif", "gif",
]) ])
SKIPPED_TAGS = set(['attach']) SKIPPED_TAGS = set(['attach'])
DEFAULT_SUBPATH = "public"
WATCH = True WATCH = True
if os.getenv('WATCH_AND_REBUILD', '1') == '0': if os.getenv('WATCH_AND_REBUILD', '1') == '0':
WATCH = False WATCH = False
MIN_HIDDEN_HEADLINE_LEVEL = 2 MIN_HIDDEN_HEADLINE_LEVEL = 2
INDEX_ID = "ea48ec1d-f9d4-4fb7-b39a-faa7b6e2ba95" INDEX_ID = os.getenv("INDEX_ID", "ea48ec1d-f9d4-4fb7-b39a-faa7b6e2ba95")
SITE_NAME = "Código para llevar" SITE_NAME = "Código para llevar"
MONITORED_EVENT_TYPES = ( MONITORED_EVENT_TYPES = (
@ -120,7 +121,7 @@ def load_all(top_dir_relative):
logging.info("Collected {} files".format(len(docs))) logging.info("Collected {} files".format(len(docs)))
return docs return docs
def regen_all(src_top, dest_top, *, docs=None, db=None): def regen_all(src_top, dest_top, subpath, *, docs=None, db=None):
files_generated = 0 files_generated = 0
cur = db.cursor() cur = db.cursor()
cleaned_db = False cleaned_db = False
@ -150,7 +151,7 @@ def regen_all(src_top, dest_top, *, docs=None, db=None):
changed = False changed = False
headlines = list(doc.getAllHeadlines()) headlines = list(doc.getAllHeadlines())
related = None related = None
if not relpath.startswith("public/"): if not relpath.startswith(subpath + "/"):
# print("Skip:", relpath) # print("Skip:", relpath)
continue continue
@ -349,7 +350,7 @@ def regen_all(src_top, dest_top, *, docs=None, db=None):
dirs_exist_ok=True) dirs_exist_ok=True)
def main(src_top, dest_top): def main(src_top, dest_top, subpath):
notifier = inotify.adapters.InotifyTrees([src_top, STATIC_PATH]) notifier = inotify.adapters.InotifyTrees([src_top, STATIC_PATH])
## Initial load ## Initial load
@ -357,7 +358,7 @@ def main(src_top, dest_top):
os.makedirs(dest_top, exist_ok=True) os.makedirs(dest_top, exist_ok=True)
db = create_db(os.path.join(dest_top, 'db.sqlite3')) db = create_db(os.path.join(dest_top, 'db.sqlite3'))
docs = regen_all(src_top, dest_top, db=db) docs = regen_all(src_top, dest_top, subpath=subpath, db=db)
if not WATCH: if not WATCH:
logging.info("Build completed in {:.2f}s".format(time.time() - t0)) logging.info("Build completed in {:.2f}s".format(time.time() - t0))
@ -375,7 +376,7 @@ def main(src_top, dest_top):
print("CHANGED: {}".format(filepath)) print("CHANGED: {}".format(filepath))
t0 = time.time() t0 = time.time()
try: try:
docs = regen_all(src_top, dest_top, docs=docs, db=db) docs = regen_all(src_top, dest_top, subpath=subpath, docs=docs, db=db)
except: except:
logging.error(traceback.format_exc()) logging.error(traceback.format_exc())
logging.error("Loading new templates failed 😿") logging.error("Loading new templates failed 😿")
@ -825,9 +826,13 @@ def save_changes(doc):
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) != 3: if len(sys.argv) not in (3, 4):
print("Usage: {} SOURCE_TOP DEST_TOP".format(sys.argv[0])) print("Usage: {} SOURCE_TOP DEST_TOP <SUBPATH>".format(sys.argv[0]))
exit(0) exit(0)
logging.basicConfig(level=logging.INFO, format="%(levelname)-8s %(message)s") logging.basicConfig(level=logging.INFO, format="%(levelname)-8s %(message)s")
exit(main(sys.argv[1], sys.argv[2])) subpath = DEFAULT_SUBPATH
if len(sys.argv) == 4:
subpath = sys.argv[3]
exit(main(sys.argv[1], sys.argv[2], subpath=subpath))