|
10 | 10 | import re |
11 | 11 | import tempfile |
12 | 12 | import urllib.parse |
| 13 | +from collections.abc import Callable |
13 | 14 | from typing import Any |
14 | 15 |
|
15 | 16 | import libzim.writer # pyright: ignore |
@@ -65,6 +66,11 @@ def get_hints(self) -> dict: |
65 | 66 | return getattr(self, "hints", {}) |
66 | 67 |
|
67 | 68 |
|
| 69 | +def no_indexing_indexdata() -> IndexData: |
| 70 | + """IndexData asking libzim not to index this item""" |
| 71 | + return IndexData("", "") |
| 72 | + |
| 73 | + |
68 | 74 | class StaticItem(Item): |
69 | 75 | """scraperlib Item with auto contentProvider from `content` or `filepath` |
70 | 76 |
|
@@ -107,19 +113,17 @@ def __init__( |
107 | 113 | path=path, title=title, mimetype=mimetype, hints=hints, **kwargs |
108 | 114 | ) |
109 | 115 | if index_data: |
110 | | - self.get_indexdata = lambda: index_data |
| 116 | + self.get_indexdata: Callable[[], IndexData] = lambda: index_data |
111 | 117 | elif not auto_index: |
112 | | - self.get_indexdata = lambda: IndexData("", "") # index nothing |
| 118 | + self.get_indexdata = no_indexing_indexdata # index nothing |
113 | 119 | else: |
114 | 120 | self._get_auto_index() # consider to add auto index |
115 | 121 |
|
116 | 122 | # Populate item title from index data if title is not set by caller |
117 | | - if ( |
118 | | - (not hasattr(self, "title") or not self.title) |
119 | | - and hasattr(self, "get_indexdata") |
120 | | - and self.get_indexdata().get_title() |
121 | | - ): |
122 | | - self.title = self.get_indexdata().get_title() |
| 123 | + if (not getattr(self, "title", None)) and hasattr(self, "get_indexdata"): |
| 124 | + title = self.get_indexdata().get_title() |
| 125 | + if title: |
| 126 | + self.title = title |
123 | 127 |
|
124 | 128 | def get_contentprovider(self) -> libzim.writer.ContentProvider: |
125 | 129 | # content was set manually |
|
0 commit comments