Coverage for src/lilbee/core/web_names.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-11-06 08:17 +0000

1"""The layout of the names crawled pages are saved under in the documents directory.""" 

2 

3from __future__ import annotations 

4 

5# The folder under the documents directory that holds every crawled page. 

6WEB_DIR = "_web" 

7# The start of every crawled page's source, a path relative to the documents directory. 

8WEB_PREFIX = f"{WEB_DIR}/" 

9# Separates a page's readable name from the hash of its address in the file stem. 

10PAGE_HASH_MARK = "~" 

11# The readable name of a page whose address ends in a slash or has no path. 

12INDEX_STEM = "index" 

13PAGE_SUFFIX = ".md" 

14 

15 

16def is_web_source(source: str) -> bool: 

17 """Whether *source*, a path relative to the documents directory, is a crawled page.""" 

18 return source.startswith(WEB_PREFIX) 

19 

20 

21def page_stem(file_name: str) -> str: 

22 """The readable part of a saved page's *file_name*: no suffix and no address hash.""" 

23 stem = file_name.removesuffix(PAGE_SUFFIX) 

24 readable, mark, _ = stem.rpartition(PAGE_HASH_MARK) 

25 return readable if mark else stem