Skip to content

Commit

Permalink
chore: add contains_files method
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Oct 24, 2024
1 parent c2922ed commit d66e4fc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion mkdocs_mknodes/commands/build_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import io
import os
import pathlib
from typing import TYPE_CHECKING, Any
from urllib.parse import urljoin

Expand Down Expand Up @@ -105,7 +106,7 @@ def _build(
logger.warning("A 'dirty' build is being performed (for site dev purposes only)")
if not live_server_url: # pragma: no cover
logger.info("Building documentation to directory: %s", config.site_dir)
if dirty and mkdocs_build.site_directory_contains_stale_files(config.site_dir):
if dirty and contains_files(config.site_dir):
logger.info("The directory contains stale files. Use --clean to remove them.")
# First gather all data from all files/pages to ensure all data is
# consistent across all pages.
Expand Down Expand Up @@ -216,6 +217,16 @@ def _populate_page(
config._current_page = None


def contains_files(folder: str | os.PathLike[str]) -> bool:
"""Check if given path exists and contains any files or folders.
Args:
folder: The folder to check
"""
path = pathlib.Path(folder)
return path.exists() and any(path.iterdir())


if __name__ == "__main__":
config = mkdocsconfigfile.MkDocsConfigFile("mkdocs.yml")
print(config.dump_config())
Expand Down

0 comments on commit d66e4fc

Please sign in to comment.