diff --git a/store/app.py b/store/app.py index 112bbb3..02f21fa 100644 --- a/store/app.py +++ b/store/app.py @@ -1,3 +1,4 @@ +import markdown import time import re import toml @@ -13,6 +14,7 @@ from slugify import slugify from flask import Flask, send_from_directory, render_template, session, redirect, request from github import Github, InputGitAuthor +locale = "en" app = Flask(__name__, static_url_path='/assets', static_folder="assets") catalog = json.load(open("apps.json")) catalog['categories'] = {c['id']:c for c in catalog['categories']} @@ -122,8 +124,48 @@ def browse_catalog(category_filter=None): @app.route('/app/') def app_info(app_id): infos = catalog["apps"].get(app_id) - if not infos: + app_folder = os.path.join(config["APPS_CACHE"], app_id) + if not infos or not os.path.exists(app_folder): return f"App {app_id} not found", 404 + + if os.path.exists(os.path.join(app_folder, "doc", f"DESCRIPTION_{locale}.md")): + description_path = os.path.join(app_folder, "doc", f"DESCRIPTION_{locale}.md") + elif os.path.exists(os.path.join(app_folder, "doc", "DESCRIPTION.md")): + description_path = os.path.join(app_folder, "doc", "DESCRIPTION.md") + else: + description_path = None + if description_path: + with open(description_path) as f: + infos["full_description_html"] = markdown.markdown(f.read()) + else: + infos["full_description_html"] = infos['manifest']['description'][locale] + + if os.path.exists(os.path.join(app_folder, "doc", f"PRE_INSTALL_{locale}.md")): + pre_install_path = os.path.join(app_folder, "doc", f"PRE_INSTALL_{locale}.md") + elif os.path.exists(os.path.join(app_folder, "doc", "PRE_INSTALL.md")): + pre_install_path = os.path.join(app_folder, "doc", "PRE_INSTALL.md") + else: + pre_install_path = None + if pre_install_path: + with open(pre_install_path) as f: + infos["pre_install_html"] = markdown.markdown(f.read()) + + infos["screenshot"] = None + + screenshots_folder = os.path.join(app_folder, "doc", "screenshots") + + if os.path.exists(screenshots_folder): + with os.scandir(screenshots_folder) as it: + for entry in it: + ext = os.path.splitext(entry.name)[1].replace(".", "").lower() + if entry.is_file() and ext in ("png", "jpg", "jpeg", "webp", "gif"): + with open(entry.path, "rb") as img_file: + data = base64.b64encode(img_file.read()).decode("utf-8") + infos[ + "screenshot" + ] = f"data:image/{ext};charset=utf-8;base64,{data}" + break + return render_template("app.html", user=session.get('user', {}), app_id=app_id, infos=infos) diff --git a/store/requirements.txt b/store/requirements.txt index 655dbae..b15084d 100644 --- a/store/requirements.txt +++ b/store/requirements.txt @@ -2,3 +2,4 @@ Flask==2.3.2 python-slugify PyGithub toml +markdown diff --git a/store/templates/app.html b/store/templates/app.html index ece7293..f3bbe2f 100644 --- a/store/templates/app.html +++ b/store/templates/app.html @@ -1,9 +1,55 @@ {% extends "base.html" %} {% block main %} -
+
-

{{ app_id }}

+ + +

{{ infos["manifest"]["name"] }}

+
+ + 123 + + + {% if infos["manifest"]["upstream"]["demo"] %} + + + Try the demo + + {% endif %} +
+
-

{{ infos }}

+

Current version: {{ infos["manifest"]["version"] }}

+ {% if infos["potential_alternative_to"] %} +

Potential alternative to: {{ infos["potential_alternative_to"]|join(', ') }}

+ {% endif %} + +
{{ infos["full_description_html"]|safe }}
+ + {% if infos["screenshot"] %} + + {% endif %} + + +

{{ infos["category"] }}

+

{{ infos["level"] }}

+ +

Antifeatures: {{ infos["anti_features"] }}

+

{{ infos["manifest"]["integration"] }}

+

{{ infos["manifest"]["upstream"] }}

+
{{ infos["pre_install_html"] | safe }}
{% endblock %} diff --git a/store/templates/base.html b/store/templates/base.html index 5f96ad1..2aa3bf8 100644 --- a/store/templates/base.html +++ b/store/templates/base.html @@ -7,6 +7,38 @@ + @@ -39,7 +71,7 @@