|
40 | 40 | validate_repository_url,
|
41 | 41 | )
|
42 | 42 | from readthedocs.projects.version_handling import determine_stable_version
|
43 |
| -from readthedocs.search.parse_json import process_file |
| 43 | +from readthedocs.search.parse_json import process_file, process_mkdocs_index_file |
44 | 44 | from readthedocs.vcs_support.backends import backend_cls
|
45 | 45 | from readthedocs.vcs_support.utils import Lock, NonBlockingLock
|
46 | 46 |
|
@@ -1330,7 +1330,7 @@ class Meta:
|
1330 | 1330 |
|
1331 | 1331 | objects = HTMLFileManager.from_queryset(HTMLFileQuerySet)()
|
1332 | 1332 |
|
1333 |
| - def get_processed_json(self): |
| 1333 | + def get_processed_json_sphinx(self): |
1334 | 1334 | """
|
1335 | 1335 | Get the parsed JSON for search indexing.
|
1336 | 1336 |
|
@@ -1374,6 +1374,52 @@ def get_processed_json(self):
|
1374 | 1374 | 'domain_data': {},
|
1375 | 1375 | }
|
1376 | 1376 |
|
| 1377 | + def get_processed_json_mkdocs(self): |
| 1378 | + log.debug('Processing mkdocs index') |
| 1379 | + storage = get_storage_class(settings.RTD_BUILD_MEDIA_STORAGE)() |
| 1380 | + storage_path = self.project.get_storage_path( |
| 1381 | + type_='html', version_slug=self.version.slug, include_file=False |
| 1382 | + ) |
| 1383 | + try: |
| 1384 | + file_path = storage.join(storage_path, 'search/search_index.json') |
| 1385 | + if storage.exists(file_path): |
| 1386 | + index_data = process_mkdocs_index_file(file_path, page=self.path) |
| 1387 | + if index_data: |
| 1388 | + return index_data |
| 1389 | + except Exception: |
| 1390 | + log.warning( |
| 1391 | + 'Unhandled exception during search processing file: %s', |
| 1392 | + file_path, |
| 1393 | + ) |
| 1394 | + return { |
| 1395 | + 'path': self.path, |
| 1396 | + 'title': '', |
| 1397 | + 'sections': [], |
| 1398 | + 'domain_data': {}, |
| 1399 | + } |
| 1400 | + |
| 1401 | + def get_processed_json(self): |
| 1402 | + """ |
| 1403 | + Get the parsed JSON for search indexing. |
| 1404 | +
|
| 1405 | + Returns a dictionary with the following structure. |
| 1406 | + { |
| 1407 | + 'path': 'file path', |
| 1408 | + 'title': 'Title', |
| 1409 | + 'sections': [ |
| 1410 | + { |
| 1411 | + 'id': 'section-anchor', |
| 1412 | + 'title': 'Section title', |
| 1413 | + 'content': 'Section content', |
| 1414 | + }, |
| 1415 | + ], |
| 1416 | + 'domain_data': {}, |
| 1417 | + } |
| 1418 | + """ |
| 1419 | + if self.version.is_sphinx_type: |
| 1420 | + return self.get_processed_json_sphinx() |
| 1421 | + return self.get_processed_json_mkdocs() |
| 1422 | + |
1377 | 1423 | @cached_property
|
1378 | 1424 | def processed_json(self):
|
1379 | 1425 | return self.get_processed_json()
|
|
0 commit comments