Added more content, Minor incremental improvements

Update app.py, uuid-generator.yml, and 23 more files...
This commit is contained in:
2025-02-24 21:17:56 +01:00
parent 0e91b5ed96
commit ec905b4735
23 changed files with 608 additions and 69 deletions

View File

@@ -1,5 +1,4 @@
import os
from pathlib import Path
from typing import Any
from locked_dict.locked_dict import LockedDict
@@ -9,11 +8,6 @@ from .dataclasses import *
__CONTENT: ContentRoot = ContentRoot()
__CONTENT_APPLETS: LockedDict[str, ContentApplet] = LockedDict()
__CONTENT_ARTICLES: LockedDict = LockedDict()
__CONTENT_PROJECTS: LockedDict[str, ContentProject] = LockedDict()
__CONTENT_TOOLS: LockedDict[str, ContentTool] = LockedDict()
def get_content() -> ContentRoot:
return __CONTENT
@@ -23,8 +17,8 @@ def get_applets() -> LockedDict[str, ContentApplet]:
return __CONTENT.applets
def get_articles() -> LockedDict:
return __CONTENT_ARTICLES
#def get_articles() -> LockedDict:
# return __CONTENT.a
def get_projects() -> LockedDict[str, ContentProject]:
@@ -39,12 +33,24 @@ def get_projects_by_tags(tags: list[str]) -> dict[Any, ContentProject]:
}
def get_projects_by_languages(languages: list[str]) -> dict[Any, ContentProject]:
project_obj: ContentProject
return {
project_key: project_value for project_key, project_value in __CONTENT.projects.items()
if any(language in project_value.metadata.general.languages for language in languages)
}
def get_projects_languages() -> list[str]:
return __CONTENT.projects_languages
def get_tools() -> LockedDict[str, ContentTool]:
return __CONTENT.tools
def get_tools_by_tags(tags: list[str]) -> dict[Any, ContentProject]:
tool_obj: ContentProject
tool_obj: ContentTool
return {
tool_key: tool_value for tool_key, tool_value in __CONTENT.tools.items()
if any(tag in tool_value.metadata.general.tags for tag in tags)
@@ -100,7 +106,7 @@ def load_content_items() -> None:
for project_data in projects_data["projects"]:
_project = ContentProject(**project_data)
__CONTENT.projects[_project.id] = _project
print(_project)
#print(_project)
"""for project_item in os.listdir(os.path.join(os.getcwd(), "data/projects")):
project_item_path = os.path.join(os.getcwd(), "data/projects/", project_item)
@@ -143,6 +149,13 @@ def load_content_items() -> None:
# FIXME: Check if the required files exist too !"""
# Preparing some more stuff
for project in __CONTENT.projects.values():
__CONTENT.projects_languages.extend(project.metadata.general.languages)
__CONTENT.projects_languages = list(set(__CONTENT.projects_languages))
__CONTENT.projects_languages.sort()
#print(__CONTENT.projects_languages)
def validate_content_items() -> bool:
pass

View File

@@ -114,3 +114,4 @@ class ContentRoot:
# articles: list[Con] = field(default_factory=list)
projects: LockedDict[str, ContentProject] = field(default_factory=LockedDict)
tools: LockedDict[str, ContentTool] = field(default_factory=LockedDict)
projects_languages: list[str] = field(default_factory=list)

View File

@@ -1,29 +1,41 @@
import os
from flask import url_for
from website.content import ContentApplet
def render_applet_head(applet_data: ContentApplet) -> str:
def render_applet_head(applet_data: ContentApplet, is_standalone: bool = False) -> str:
applet_style_html = ""
for applet_style in applet_data.resources.stylesheets:
applet_style_html += ("<link rel='stylesheet' href='" +
url_for(
"static",
filename="/resources/NibblePoker/applets/" + applet_data.id + "/" + applet_style) +
"'>")
if is_standalone:
with open(os.path.join("./static/resources/NibblePoker/applets/", applet_data.id, applet_style)) as applet_style_file:
applet_style_html += "<style>" + applet_style_file.read() + "</style>"
else:
applet_style_html += ("<link rel='stylesheet' href='" +
url_for(
"static",
filename="/resources/NibblePoker/applets/" + applet_data.id + "/" + applet_style) +
"'>")
return applet_style_html
def render_applet_scripts(applet_data: ContentApplet):
def render_applet_scripts(applet_data: ContentApplet, is_standalone: bool = False):
applet_script_html = ""
for applet_script in applet_data.resources.scripts:
applet_script_html += ("<script src='" +
url_for(
"static",
filename="/resources/NibblePoker/applets/" + applet_data.id + "/" + applet_script) +
"'" + (" type='module'" if applet_script.endswith(".mjs") else "") + "></script>")
if is_standalone:
with open(os.path.join("./static/resources/NibblePoker/applets/", applet_data.id, applet_script)) as applet_script_file:
applet_script_html += "<script" + (" type='module'>" if applet_script.endswith(".mjs") else ">")
applet_script_html += applet_script_file.read()
applet_script_html += "</script>"
else:
applet_script_html += ("<script src='" +
url_for(
"static",
filename="/resources/NibblePoker/applets/" + applet_data.id + "/" + applet_script) +
"'" + (" type='module'" if applet_script.endswith(".mjs") else "") + "></script>")
return applet_script_html

View File

@@ -0,0 +1,6 @@
def get_standalone_common_headers() -> str:
_html = ""
with open("./static/resources/Standalone/nibblepoker.min.css", encoding='utf-8') as f:
_html += "<style>" + f.read() + "</style>"
return _html