From 23dacbcbc294cc667cd2bf8ff9667da792e12349 Mon Sep 17 00:00:00 2001 From: "kam (from the studio)" Date: Fri, 11 Nov 2022 10:11:09 +0100 Subject: [PATCH] test static gen --- flask_boat.py | 58 +++++++++++++++++++++++++++++---------------------- log.txt | 0 render.html | 0 3 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 log.txt create mode 100644 render.html diff --git a/flask_boat.py b/flask_boat.py index a6bbfa5..5b03e54 100644 --- a/flask_boat.py +++ b/flask_boat.py @@ -46,6 +46,32 @@ def get_md_contents(filename, directory='./contents'): return metadata, html_content +def render_home(): + with open('render.html', 'r+w') as f: + # get the basic info of the website from the /contents/home.md file + meta, content = get_md_contents("home.md") + projects_list = [] + for project in list_folders("./projects"): + project_info = get_md_contents("documentation.md", + f"./{projects}/{project}")[0] + project_date = datetime.strptime(project_info['date'], '%d/%m/%Y') + project_info['date'] = datetime.strftime(project_date, '%d %b, %y') + project_info['categories'].sort() + + project_info['slug'] = project + projects_list.append(project_info) + + projects_list.sort(reverse=True, key=lambda project: datetime.strptime( + project['date'], '%d %b, %y')) + + # get the list of the projects, the functions, and the corpora + home = { + **meta, + "content": content, + "projects": projects_list + } + f.write(render_template("home.html", **home)) + # FLASK APP base_url = "~kamo" projects = 'projects' @@ -67,30 +93,7 @@ def set_base_url(): # Homepage @app.route(f"/{base_url}/") def home_page(): - - # get the basic info of the website from the /contents/home.md file - meta, content = get_md_contents("home.md") - projects_list = [] - for project in list_folders("./projects"): - project_info = get_md_contents("documentation.md", - f"./{projects}/{project}")[0] - project_date = datetime.strptime(project_info['date'], '%d/%m/%Y') - project_info['date'] = datetime.strftime(project_date, '%d %b, %y') - project_info['categories'].sort() - - project_info['slug'] = project - projects_list.append(project_info) - - projects_list.sort(reverse=True, key=lambda project: datetime.strptime( - project['date'], '%d %b, %y')) - - # get the list of the projects, the functions, and the corpora - home = { - **meta, - "content": content, - "projects": projects_list - } - return render_template("home.html", **home) + return send_from_directory(f'{app.root_path}/render.html') # For generic pages we can include a common template and change only the contents @@ -123,7 +126,12 @@ def sendStaticFiles(project, filename): def pull(): if request.method == 'POST': subprocess.call(['sh', '/home/kamo/public_html/update.sh']) - print(request.form['payload']) + + with open('log.txt', 'a') as f: + f.write(request.form['payload']) + + render_home() + return 'Updated' return 'GET method not supported' diff --git a/log.txt b/log.txt new file mode 100644 index 0000000..e69de29 diff --git a/render.html b/render.html new file mode 100644 index 0000000..e69de29