roundabout,
created on Friday, 19 April 2024, 16:35:54 (1713544554),
received on Tuesday, 23 April 2024, 11:54:32 (1713873272)
Author identity: vlad <vlad.muntoiu@gmail.com>
6103eb7ebd511fbf0b8c33608fa6899c644bac25
ampoule_ssg/__init__.py
@@ -31,6 +31,7 @@ class Document:
self.encoding = "utf-8" # If the file is text, read it. self.front_matter = YAML() self.content = ""try: with open(file_name, "r", encoding=self.encoding) as f: print("!" + f"Loading document {file_name}".center(80, "-") + "!")
@@ -50,13 +51,15 @@ class Document:
if front_matter: self.front_matter = self.front_matter.load(front_matter) else: # put it back self.content = initial_lineprint("!" + "Reading content".center(80, "-") + "!") self.content = initial_line + f.read()self.content += f.read()print("!" + "Content loaded".center(80, "-") + "!") print(self.content)print(self.content[:256] + "..." if len(self.content) > 256 else self.content)except UnicodeDecodeError: print("!" + "Text decoding failed, assuming binary.".center(80, "-") + "!") self.encoding = None
@@ -66,7 +69,7 @@ class Document:
class Index: def __init__(self, directory, recursive=False):def __init__(self, directory, recursive=False, url_transform=lambda x: x):self.directory = directory # Temporarily move to the specified directory in order to read the files. with in_directory(directory):
@@ -74,7 +77,7 @@ class Index:
self.file_names = [os.path.join(dir_path, f) for dir_path, dir_name, filenames in os.walk(".") for f in filenames] else: self.file_names = [i for i in os.listdir() if os.path.isfile(i)] self.documents = [Document(i) for i in self.file_names]self.documents = [Document(url_transform(i)) for i in self.file_names]self.__current_index = 0 def __iter__(self):
@@ -109,7 +112,7 @@ class Site:
self.pages[os.path.join(location, document.file_name)] = Static(self, document) else: for document in index: self.pages[os.path.join(location, document.file_name)] = Page(self, template, os.path.join(index.directory, document), **kwargs)self.pages[os.path.join(location, document.file_name)] = Page(self, template, document, **kwargs)def filter(self, name): def decorator(func):