(``settings[]`` ids, ``blocks[].settings[]`` ids) of the ``{% schema %}`` of a Liquid file.
(text: str)
| 401 | |
| 402 | |
| 403 | def _schema_scoped(text: str) -> tuple[set[str], set[str]]: |
| 404 | """(``settings[]`` ids, ``blocks[].settings[]`` ids) of the ``{% schema %}`` of a Liquid file.""" |
| 405 | m = re.search(r"\{%-?\s*schema\s*-?%\}(.*?)\{%-?\s*endschema\s*-?%\}", text, re.S) |
| 406 | if not m: |
| 407 | return set(), set() |
| 408 | try: |
| 409 | data = json.loads(m.group(1)) |
| 410 | except (ValueError, RecursionError): |
| 411 | return set(), set() |
| 412 | |
| 413 | def ids(entries: object) -> set[str]: |
| 414 | return { |
| 415 | e["id"] for e in entries if isinstance(e, dict) and isinstance(e.get("id"), str) and "type" in e |
| 416 | } if isinstance(entries, list) else set() |
| 417 | |
| 418 | if not isinstance(data, dict): |
| 419 | return set(), set() |
| 420 | blocks: set[str] = set() |
| 421 | for b in data.get("blocks") if isinstance(data.get("blocks"), list) else []: |
| 422 | if isinstance(b, dict): |
| 423 | blocks |= ids(b.get("settings")) |
| 424 | return ids(data.get("settings")), blocks |
| 425 | |
| 426 | |
| 427 | def _global_setting_ids(root: Path) -> set[str]: |