Skip to content

Commit

Permalink
Add function see_also
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha committed Jan 24, 2025
1 parent ff4b3e3 commit 3fd38a2
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 23 deletions.
2 changes: 1 addition & 1 deletion functions/Cursor/getCursorAlpha.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ client:
examples:
- path: 'examples/getCursorAlpha.lua'
see_also:
- 'category:GUI functions'
- 'category:Client element functions'
2 changes: 1 addition & 1 deletion functions/Cursor/setCursorAlpha.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ client:
examples:
- path: 'examples/setCursorAlpha.lua'
see_also:
- 'category:GUI functions'
- 'category:Client GUI functions'
2 changes: 1 addition & 1 deletion functions/Cursor/setCursorPosition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ client:
description: |
This example sets your cursor position to the center of your screen after using the command *cursorpos*.
see_also:
- 'tag:Client input functions'
- 'category:Client input functions'
4 changes: 2 additions & 2 deletions schemas/function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ $defs:
see_also:
type: array
description: |
A list of other items and categories for further reading.
A list of other categories for further reading.
Every function will implicitly display it's own category in *See Also*, unless you
introduce this property, then you have to be explicit about it.
items:
type: string
pattern: "^(item|category|tag):"
pattern: "^(category):"
uniqueItems: true

oop:
Expand Down
18 changes: 18 additions & 0 deletions web/resources/function.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,22 @@ <h3 id="example-{{ example.number }}">Example {{ example.number }} <span style="
{% endfor %}
{% if not function.has_example %}
<p>No examples available.</p>
{% endif %}

{% if function.related %}
<h2 id="see_also">See also <a href="#see_also"><i class="fa-solid fa-link"></i></a></h2>
{% for related in function.related %}
{% if related.category %}
<h3 style="margin-left: 1em;">{{ related.category }}:</h3>
<ul style="margin-bottom: 1em;">
{% for item in related['items'] %}
{% if item.name == function.name %}
<li><strong>{{ item.name }}</strong></li>
{% else %}
<li><a href="{{ item.path_html }}">{{ item.name }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
{% endfor %}
{% endif %}
64 changes: 46 additions & 18 deletions web/scripts/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ def parse_parameters_and_returns(parameters, returns):

function['syntaxes'] = syntaxes

function['path_html'] = f"/{function['name']}/"

self.functions.append(function)
except Exception as e:
self.logger.exception(e)
Expand Down Expand Up @@ -321,20 +323,11 @@ def render_page(self, title, content):
content = content
)

def create_function(self, function_name):

for function2 in self.functions:
if function2['name'] == function_name:
function = function2
break
if not function:
raise WikiBuilderError(f'Function not found: {function_name}')
return

def create_function_page(self, function):
function_template = self.input_env.get_template('function.html')
html_content = self.render_page(function['name'], function_template.render(function=function))

web_path = f"/{function['name']}/"
web_path = function["path_html"]
function_folder = OUTPUT_HTML_PATH + web_path

Path(function_folder).mkdir(parents=True, exist_ok=True)
Expand All @@ -343,12 +336,8 @@ def create_function(self, function_name):
with open(output_path, 'w') as html_file:
html_file.write(html_content)

function["path_html"] = web_path

self.logger.info(f"Generated {output_path}")

return function

def create_article(self, article_name, articles_folder='', custom_web_path=False):
article_real_path = os.path.join(DOCS_REPO_PATH, 'articles', articles_folder, article_name, f"article.yaml")
article = utils.load_and_validate_yaml(article_real_path, self.schema_article)
Expand Down Expand Up @@ -423,7 +412,7 @@ def create_category(self, web_path, category_data):
functions_folder_path = os.path.join(DOCS_REPO_PATH, 'functions', functions_folder)
for function in self.functions:
if function['type_name'] == functions_type and function['folder'] == functions_folder:
function = self.create_function(function['name'])
function["category"] = category_name
items.append({
'name': function['name'],
'path_html': function['path_html']
Expand All @@ -440,6 +429,8 @@ def create_category(self, web_path, category_data):
'path_html': f"/lua/functions/{functions_type}/{functions_folder}"
})

self.categories[category_name] = items

category_template = self.input_env.get_template('category.html')
html_content = self.render_page(category_name, category_template.render(
category_name = category_name,
Expand Down Expand Up @@ -560,6 +551,8 @@ def create_pages(self):
with open(os.path.join(DOCS_REPO_PATH, 'VERSION'), 'r') as file:
self.wiki_version = file.read().strip()

self.categories = {}

def create_item(item):
if 'article' in item:
self.create_article(item['article']['name'], item['article']['folder'], item['path_html'])
Expand All @@ -572,10 +565,45 @@ def create_item(item):
create_item(subitem)
else:
create_item(item)

# Generate related pages for each function
for function in self.functions:
function['related'] = []

# Fill with the function's category items
function_category = function.get('category')
if function_category:
category_items = self.categories.get(function_category)
function['related'].append({
'category': function_category,
'items': category_items
})

# Fill with other see_also entries
for type_name in ['shared', 'client', 'server']:
type_info = function.get(type_name, {})
if not type_info:
continue
for see_also in type_info.get('see_also', []):
parts = see_also.split(':')
if len(parts) != 2:
continue
entry_type = parts[0]
entry_name = parts[1]
if entry_type == 'category':
category_items = self.categories.get(entry_name)
if category_items:
function['related'].append({
'category': entry_name,
'items': category_items
})

# Create function pages
for function in self.functions:
self.create_function_page(function)

self.create_misc_pages()



def copy_assets(self):

copy_files = [
Expand Down

0 comments on commit 3fd38a2

Please sign in to comment.