|
1 | 1 | import typing as t |
2 | 2 | from pathlib import Path |
3 | 3 | import json |
4 | | -import re |
5 | 4 | import tomllib |
6 | 5 | import yaml |
7 | 6 |
|
8 | 7 | import httpx |
9 | 8 | from git import Repo |
10 | | -from bs4 import BeautifulSoup as bs |
11 | 9 | from mkdocs.config import Config, config_options |
12 | 10 | from mkdocs.config.defaults import MkDocsConfig |
13 | 11 | from mkdocs.plugins import event_priority, get_plugin_logger, BasePlugin |
|
18 | 16 |
|
19 | 17 | log = get_plugin_logger(__name__) |
20 | 18 |
|
21 | | -SECTION_PATTERN = re.compile(r"([a-z-_]+)/()|(/docs/dev)index.md") |
22 | | - |
23 | 19 | REST_API_MD = """\ |
24 | 20 | --- |
25 | | -restapi_json_file: "../api.json" |
| 21 | +template: "rest_api.html" |
26 | 22 | --- |
27 | 23 | """ |
28 | 24 |
|
29 | | -REDOC_HEADER = """ |
30 | | -<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet"> |
31 | | -<style> |
32 | | - body { |
33 | | - margin: 0; |
34 | | - padding: 0; |
35 | | - } |
36 | | -</style> |
37 | | -""" |
38 | | - |
39 | | -REDOC_TAG_TEMPLATE = """ |
40 | | -<redoc spec-url='%s'></redoc> |
41 | | -""" |
42 | | - |
43 | | -REDOC_SCRIPT = """ |
44 | | -<script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script> |
45 | | -""" |
46 | | - |
47 | 25 |
|
48 | 26 | @config_options.SubConfig |
49 | 27 | class RepositoryOption(Config): |
@@ -383,30 +361,3 @@ def on_pre_page( |
383 | 361 | if edit_url := pulp_meta.get("edit_url"): |
384 | 362 | page.edit_url = edit_url |
385 | 363 | return page |
386 | | - |
387 | | - def on_post_page( |
388 | | - self, |
389 | | - output: str, |
390 | | - page: Page, |
391 | | - config: MkDocsConfig, |
392 | | - ) -> str | None: |
393 | | - # TODO reimplement this as a template |
394 | | - if basepath := page.meta.get("restapi_json_file"): |
395 | | - redoc_tag = REDOC_TAG_TEMPLATE % basepath |
396 | | - bs_page = bs(output, "html.parser") |
397 | | - |
398 | | - # Append <head>scripts |
399 | | - bs_page.html.head.append(bs(REDOC_HEADER, "html.parser")) |
400 | | - |
401 | | - # Replace main content-container with <redoc> tag |
402 | | - main_container = bs_page.find_all("div", class_="md-main__inner")[0] |
403 | | - main_container.replace_with(bs(redoc_tag, "html.parser")) |
404 | | - |
405 | | - # Append <script> tag at the end of body |
406 | | - bs_page.html.body.append(bs(REDOC_SCRIPT, "html.parser")) |
407 | | - |
408 | | - # Remove footer (looks weird) |
409 | | - footer = bs_page.find_all(class_="md-footer")[0] |
410 | | - footer.decompose() |
411 | | - output = str(bs_page) |
412 | | - return output |
0 commit comments