diff --git a/stsg/build.py b/stsg/build.py index 0afedc4..b97e3e6 100644 --- a/stsg/build.py +++ b/stsg/build.py @@ -114,7 +114,6 @@ class ArticleOverview: self.slug = self.directory.name self.article_written = self.directory.stat().st_mtime - print(self.article_written) self.location_in_tree: List[str] = location_in_tree or [] self.location_in_tree.append(self.slug) @@ -145,6 +144,8 @@ class ArticleOverview: self.article_translations.sort(key=lambda a: a.priority, reverse=True) self.overview_cards = "\n".join(a.get_overview_card() for a in self.article_translations) + logger.info("found %s at %s with the translations %s", self.slug, ".".join(list(self.location_in_tree)), ",".join(self.article_translations_map.keys())) + def build(self): # builds the tree structure to the dist directory self.dist_path.mkdir(parents=True, exist_ok=True) @@ -183,39 +184,6 @@ class ArticleOverview: return replace_values(TEMPLATE.overview, self._get_values()) -def copy_static(): - src = str(Path(config.setup.source_directory, "static")) - dst = str(Path(config.setup.dist_directory, "static")) - - - if not os.path.exists(src): - logger.warn("The static folder '%s' wasn't defined.", src) - return - - logger.info("copying static files from '%s' to '%r'", src, dst) - - os.makedirs(dst, exist_ok=True) - - for root, dirs, files in os.walk(src): - if any(p.startswith(".") for p in Path(root).parts): - continue - - # Compute relative path from the source root - rel_path = os.path.relpath(root, src) - dest_dir = os.path.join(dst, rel_path) - - os.makedirs(dest_dir, exist_ok=True) - - - for file in files: - if file.startswith("."): - continue - - src_file = os.path.join(root, file) - dest_file = os.path.join(dest_dir, file) - shutil.copy2(src_file, dest_file) - - # GLOBALS logger = logging.getLogger("stsg.build") TEMPLATE = Template(Path(config.setup.source_directory, "templates")) @@ -223,17 +191,19 @@ ARTICLE_LAKE: Dict[str, ArticleOverview] = {} ARTICLE_REFERENCE_VALUES: DefaultDict[str, Dict[str, str]] = defaultdict(dict) def build(): - logger.info("building static page") + logger.info("starting build process...") - copy_static() + logger.info("copying static folder...") + shutil.copytree(Path(config.setup.source_directory, "static"), Path(config.setup.dist_directory, "static"), dirs_exist_ok=True) + + logger.info("reading page tree...") tree = ArticleOverview(directory=Path(config.setup.source_directory, "articles")) # build article reverence values for article_overview in ARTICLE_LAKE.values(): - logger.info("found article %s", article_overview.slug) - ARTICLE_REFERENCE_VALUES[""].update(article_overview.get_article_values()) for language_code, at in article_overview.article_translations_map.items(): ARTICLE_REFERENCE_VALUES[language_code].update(at.get_article_values()) - + + logger.info("writing page tree...") tree.build() \ No newline at end of file