staticjinja icon indicating copy to clipboard operation
staticjinja copied to clipboard

staticpaths incorrectly identifies files

Open alex-way opened this issue 4 years ago • 1 comments

Given the code shown below and a file structure of:

  • policies/document_1.pdf
  • policies.html
from staticjinja import Site

if __name__ == "__main__":
    staticpaths = [
        "policies/",
    ]

    site = Site.make_site(
        staticpaths=staticpaths,
    )
    site.render()

Staticjinja is incorrectly identifying policies.html as a staticfile, whereas only the directory policies and it's subcomponents should be marked as a static file.

alex-way avatar Nov 09 '21 17:11 alex-way

The culprit seems to be https://github.com/staticjinja/staticjinja/blob/main/staticjinja/staticjinja.py#L344

The simple test below fails:

from pathlib import Path

# Create test file
filename = "readme.md"
Path(filename).touch()
staticpaths = ["readme/"]
for path in staticpaths:
    assert Path(path).exists() is False
path = Path(filename).as_posix()

# Fails assertion
assert any(path.startswith(Path(sp).as_posix()) for sp in staticpaths) is False

alex-way avatar Nov 09 '21 17:11 alex-way