Skip to content

Commit 14359bc

Browse files
committed
Update documentation with API for liberty
1 parent f498dc5 commit 14359bc

File tree

8 files changed

+1478
-2
lines changed

8 files changed

+1478
-2
lines changed

.DS_Store

0 Bytes
Binary file not shown.

docs/liberty/api/liberty-api.md

Lines changed: 1230 additions & 0 deletions
Large diffs are not rendered by default.

json/liberty-api.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

json/liberty_documentation.json

Lines changed: 47 additions & 0 deletions
Large diffs are not rendered by default.

json/ly_user_guide.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import os
2+
from playwright.sync_api import sync_playwright
3+
import json
4+
5+
BASE_URL = "http://docs.nomana-it.fr"
6+
OUTPUT_FILE = "liberty_documentation.json"
7+
8+
NAV = [
9+
{"title": "Getting Started", "path": "liberty/getting-started.md", "description": "Learn the basics of Liberty Framework."},
10+
{"title": "Release Notes", "path": "liberty/release-notes.md", "description": "See what's new in the latest release."},
11+
{
12+
"title": "Installation",
13+
"description": "Step-by-step installation guides.",
14+
"children": [
15+
{"title": "Architecture", "path": "liberty/technical/architecture.md", "description": "Understand the architecture of Liberty Framework."},
16+
{"title": "Docker Installation Guide", "path": "liberty/technical/installation.md", "description": "Set up Liberty Framework using Docker."},
17+
{"title": "Installation Tools Deployment Guide", "path": "liberty/technical/tools-deployment.md", "description": "Learn about tools for deploying Liberty Framework."},
18+
{"title": "Liberty Deployment Guide", "path": "liberty/technical/liberty-deployment.md", "description": "Guide to deploying Liberty Framework."},
19+
{"title": "Create Linux Services", "path": "liberty/technical/linux-services.md", "description": "Create Linux services for Liberty Framework."},
20+
{"title": "Enable SSL with Traefik", "path": "liberty/technical/post-ssl.md", "description": "Enable SSL using Traefik for enhanced security."},
21+
]
22+
},
23+
{
24+
"title": "Nomasx-1",
25+
"description": "Guides and settings for Nomasx-1.",
26+
"children": [
27+
{
28+
"title": "Administrator's Guide",
29+
"description": "Administrator resources and tools.",
30+
"children": [
31+
{"title": "Global Settings", "path": "liberty/nomasx1/admin/global-settings.md", "description": "Manage global settings for Nomasx-1."},
32+
]
33+
}
34+
]
35+
}
36+
]
37+
38+
def flatten_nav(nav, parent_title=""):
39+
"""Flatten the navigation into a list of titles and paths."""
40+
pages = []
41+
for item in nav:
42+
title = f"{parent_title} > {item['title']}" if parent_title else item['title']
43+
if "path" in item:
44+
pages.append({"title": title, "path": item["path"]})
45+
if "children" in item:
46+
pages.extend(flatten_nav(item["children"], title))
47+
return pages
48+
49+
def extract_page_content(page, url):
50+
"""Extract the main content from a MkDocs Material page."""
51+
page.goto(url, wait_until="networkidle")
52+
content = page.locator("main").inner_text() # Main content selector for MkDocs Material
53+
return content.strip()
54+
55+
def generate_documentation_json(base_url, nav):
56+
"""Generate a JSON file with all documentation content."""
57+
pages = flatten_nav(nav)
58+
documentation = []
59+
60+
with sync_playwright() as p:
61+
browser = p.chromium.launch()
62+
context = browser.new_context()
63+
64+
for page_info in pages:
65+
title = page_info["title"]
66+
path = page_info["path"]
67+
url = f"{base_url}/{path.replace('.md', '').strip('/')}"
68+
69+
try:
70+
page = context.new_page()
71+
content = extract_page_content(page, url)
72+
documentation.append({"title": title, "url": url, "content": content})
73+
print(f"Extracted content for {title}")
74+
except Exception as e:
75+
print(f"Failed to extract content for {title}: {e}")
76+
continue
77+
78+
browser.close()
79+
80+
# Save to a JSON file
81+
with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
82+
json.dump(documentation, f, indent=2, ensure_ascii=False)
83+
print(f"Documentation saved to {OUTPUT_FILE}")
84+
85+
if __name__ == "__main__":
86+
generate_documentation_json(BASE_URL, NAV)

mkdocs.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ theme:
3232
- navigation.top
3333
- navigation.footer
3434
- header.autohide
35+
- content.tooltips
3536
nav:
3637
- Home: index.md
3738
- Liberty:
@@ -45,7 +46,8 @@ nav:
4546
- Enable SSL with Traefik: liberty/technical/post-ssl.md
4647
- Nomasx-1:
4748
- Administrator's Guide:
48-
- Global Settings: liberty/nomasx1/admin/global-settings.md
49+
- Global Settings: liberty/nomasx1/admin/global-settings.md
50+
- API Documentation: liberty/api/liberty-api.md
4951
- Release Notes: liberty/release-notes.md
5052
- Issues: liberty/issues.md
5153
- Incidents: liberty/incidents.md
@@ -62,7 +64,7 @@ nav:
6264
plugins:
6365
- search
6466
- awesome-pages
65-
- minify
67+
- minify
6668
- blog:
6769
blog_toc: true
6870
extra:
@@ -95,6 +97,10 @@ markdown_extensions:
9597
- pymdownx.inlinehilite
9698
- pymdownx.snippets
9799
- pymdownx.superfences
100+
- admonition
101+
- pymdownx.details
102+
- pymdownx.tabbed:
103+
alternate_style: true
98104
extra_css:
99105
- css/custom.css
100106
extra_javascript:

scripts/gendoc.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import json
2+
from collections import defaultdict
3+
4+
# Load the OpenAPI JSON
5+
with open("../json/liberty-api.json", "r") as f:
6+
openapi_data = json.load(f)
7+
8+
# Add background color for method
9+
def method_with_style(method):
10+
color_map = {
11+
"GET": "green", # Light green
12+
"POST": "blue", # Light blue
13+
"PUT": "purple", # Light purple
14+
"DELETE": "red", # Light red
15+
}
16+
color = color_map.get(method.upper(), "inherit") # Default to inherit color
17+
return f'<span style="background:{color}; font-size: 16px; padding-left: 10px; padding-right: 10px">{method.upper()}</span>'
18+
19+
20+
# Initialize Markdown content
21+
markdown = f"# {openapi_data['info']['title']}\n\n"
22+
markdown += f"**Description:** {openapi_data['info']['description']}\n\n"
23+
markdown += f"**Version:** {openapi_data['info']['version']}\n\n"
24+
25+
method_order = ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"]
26+
27+
# Sort paths and methods
28+
paths = openapi_data["paths"]
29+
30+
# Group paths by tags
31+
tagged_paths = defaultdict(list)
32+
for path, methods in paths.items():
33+
for method, details in methods.items():
34+
tags = details.get("tags", ["Untagged"]) # Use "Untagged" if no tags are provided
35+
for tag in tags:
36+
tagged_paths[tag].append((path, method, details))
37+
38+
# Iterate through tags and their respective paths
39+
for tag, endpoints in tagged_paths.items():
40+
markdown += f"## {tag}\n\n" # Add tag as a section header
41+
42+
# Sort endpoints by their method order and path
43+
endpoints = sorted(
44+
endpoints,
45+
key=lambda x: (method_order.index(x[1].upper()) if x[1].upper() in method_order else len(method_order), x[0])
46+
)
47+
48+
for path, method, details in endpoints:
49+
method_with_bg = method_with_style(method)
50+
markdown += f"### {details.get('summary', 'No summary available')}\n\n"
51+
markdown += f"{details.get('description', 'No description available.')}\n\n"
52+
markdown += f"{method_with_bg} **`{path}`**\n\n"
53+
54+
# Parameters Section
55+
markdown += "!!! abstract \"Query Parameters\"\n"
56+
if "parameters" in details:
57+
for param in details["parameters"]:
58+
required = " (**Required**)" if param.get("required", False) else ""
59+
default = f" *(Default: `{param['schema']['default']}`)*" if "default" in param["schema"] else ""
60+
markdown += f" - **`{param['name']}`** *(in {param['in']})*: {param.get('description', 'No description')}{required}{default}\n"
61+
else:
62+
markdown += " - **None**\n\n"
63+
64+
# Request Body Section
65+
if "requestBody" in details:
66+
markdown += "!!! abstract \"Request Body\"\n"
67+
request_body = details["requestBody"]["content"]
68+
for content_type, body_details in request_body.items():
69+
markdown += f" - **Content-Type:** `{content_type}`\n"
70+
body_json = json.dumps(body_details.get('schema', {}), indent=4)
71+
json_block = "\n".join([f" {line}" for line in body_json.splitlines()])
72+
markdown += f" - **Example:**\n\n"
73+
markdown += f" ```json\n{json_block}\n ```\n"
74+
75+
# Responses Section
76+
markdown += "**📥 Responses:**\n\n"
77+
for status, response in details["responses"].items():
78+
# Determine the type of admonition based on the status code
79+
if str(status).startswith("2"):
80+
admonition_type = "success"
81+
elif str(status).startswith("4"):
82+
admonition_type = "warning"
83+
elif str(status).startswith("5"):
84+
admonition_type = "danger"
85+
else:
86+
admonition_type = "note" # Default to 'note' for other status codes
87+
markdown += f"??? {admonition_type} \"Response `{status}`: {response.get('description', 'No description available.')}\"\n"
88+
if "content" in response:
89+
for content_type, content_details in response["content"].items():
90+
markdown += f" - **Content-Type:** `{content_type}`\n"
91+
if "example" in content_details:
92+
example_json = json.dumps(content_details["example"], indent=4)
93+
# Ensure the JSON block is properly indented
94+
json_block = "\n".join([f" {line}" for line in example_json.splitlines()])
95+
markdown += f" - **Example:**\n\n"
96+
markdown += f" ```json\n{json_block}\n ```\n"
97+
98+
markdown += "\n---\n\n"
99+
100+
101+
# Save to a Markdown file for MkDocs
102+
with open("../docs/liberty/api/liberty-api.md", "w") as f:
103+
f.write(markdown)
104+
105+
print("API documentation exported to docs/liberty/api/liberty-api.md!")

site/css/custom.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
padding: 12px 20px; /* Spacious padding */
2020
border-radius: 6px; /* Slightly rounded corners */
2121
}
22+

0 commit comments

Comments
 (0)