Skip to content

Commit

Permalink
Expand dynamic documentation generation with including headers, foote…
Browse files Browse the repository at this point in the history
…r and image
  • Loading branch information
igorpecovnik committed Oct 24, 2024
1 parent c133d84 commit 40b099a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# docs output
/docs/
7 changes: 7 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ The script expects the JSON file to be located at:
- Creates navigation links (table of contents) for all IDs and descriptions.
- Generates technical documentation that includes commands, prompts, conditions, author information, and status.
- Creates user-focused documentation with simplified instructions.
- Includes custom header, footer and section image:

```
- tools/include/markdown/ID-header.md
- tools/include/markdown/ID-footer.md
- tools/include/images/ID.png
```

#### Dependencies

Expand Down
35 changes: 33 additions & 2 deletions tools/config-markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import json
import os
import os.path
import argparse

from pathlib import Path

# Get the absolute path of the script's directory
script_dir = os.path.dirname(os.path.abspath(__file__))

Expand Down Expand Up @@ -64,25 +67,53 @@ def create_markdown_technical(item, level=1):
return md_content

def create_markdown_user(item, level=1):

"""Recursively create Markdown content for user documentation from JSON."""
#user_content = f"<a id=\"{item['id'].lower()}\" style=\"display:none;\"></a>\n"
# if above A link is not working, use below line
#user_content += f"{'#' * level} {item['id']}\n"
#user_content = f"# {item.get('description', '')}\n"

# verify if header or footer exists
image_include = Path(os.path.dirname(os.path.abspath(__file__))+'/include/images/'+item['id']+'.png')
header_include = Path(os.path.dirname(os.path.abspath(__file__))+'/include/markdown/'+item['id']+'-header.md')
footer_include = Path(os.path.dirname(os.path.abspath(__file__))+'/include/markdown/'+item['id']+'-footer.md')

user_content = f"{'#' * level} {item.get('description', '')}\n"


# include image for section if exists
if image_include.is_file():
user_content +="\n<!--- section image START from tools/include/images/"+item['id']+".png --->\n"
with open(image_include, 'r') as file:
user_content += "[!["+ item.get('description', '') + "](images/"+item['id']+".png)](#)\n"
user_content +="<!--- section image STOP from tools/include/images/"+item['id']+".png --->\n\n"

# include markdown header for section if exists
if header_include.is_file():
user_content +="\n<!--- header START from tools/include/markdown/"+item['id']+"-header.md --->\n"
with open(header_include, 'r') as file:
user_content += f""+file.read().replace('\n', '')+"\n"
user_content +="<!--- header STOP from tools/include/markdown/"+item['id']+"-header.md --->\n\n"

if 'about' in item and item['about']:
user_content += f"{item['about']}\n\n"

if 'command' in item:
user_content += f"**Command:** \n~~~\n--cmd {item['id']}\n~~~\n\n"
user_content += f"**Command:** \n~~~\narmbian-config --cmd {item['id']}\n~~~\n\n"

if 'author' in item:
user_content += f"**Author:** {item['author']}\n\n"

if 'status' in item:
user_content += f"**Status:** {item['status']}\n\n"

# include footer for section if exists
if footer_include.is_file():
user_content +="\n<!--- footer START from tools/include/markdown/"+item['id']+"-footer.md --->\n"
with open(footer_include, 'r') as file:
user_content += f""+file.read().replace('\n', '')+"\n"
user_content +="<!--- footer STOP from tools/include/markdown/"+item['id']+"-header.md --->\n\n"

user_content += '\n\n***\n\n' # Add extra line for spacing

# Recursively add sub-items if they exist
Expand Down
7 changes: 7 additions & 0 deletions tools/include/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Images, headers and footers that contains:

- ID-header.md
- ID-footer.md
- ID.png

will be automatically embedded into respective parts of the documentation.
Binary file added tools/include/images/DE31.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tools/include/markdown/DE31-footer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Cinnamon is a Linux desktop that provides advanced innovative features and a traditional user experience.

The desktop layout is similar to Gnome 2 with underlying technology forked from Gnome Shell. Cinnamon makes users feel at home with an easy-to-use and comfortable desktop experience.

0 comments on commit 40b099a

Please sign in to comment.