from flask import Flask, render_template_string, send_file import subprocess import os import re import datetime from waitress import serve pocelo = datetime.datetime.now() app = Flask(__name__) visits = 0 navbar = """ """ base_dir = os.path.abspath('..') html_files = { 'index.html': os.path.join(base_dir, 'html', 'index.html'), 'projects.html': os.path.join(base_dir, 'html', 'projects.html'), 'contribute.html': os.path.join(base_dir, 'html', 'contribute.html'), 'foss.jpg': os.path.join(base_dir, 'html', 'foss.jpg'), 'git.png': os.path.join(base_dir, 'html', 'git.png'), 'main.css': os.path.join(base_dir, 'html', 'main.css'), 'main.js': os.path.join(base_dir, 'html', 'main.js'), } visit_file = os.path.join(base_dir, 'visits.txt') git_commit = result = subprocess.run( ['git', 'log', '-1', '--pretty=%B'], capture_output=True, text=True, check=True ).stdout.splitlines()[0] motd = "Dobrodošli na našu stranicu!" def replace_placeholders(file_path): with open(file_path, 'r', encoding='utf-8') as file: global visits global pocelo content = file.read() footer = f''' ''' content = re.sub(r'{{GIT_COMMIT}}', git_commit, content) content = re.sub(r'{{MOTD}}', motd, content) content = re.sub(r'{{nav}}', navbar, content) content = re.sub(r'{{footer}}', footer, content) visits+=1 return content @app.route('/') def home(): print(html_files) content = replace_placeholders(html_files['index.html']) return content @app.route('/') def other_pages(page): if page in html_files: if(not page.endswith('.html')): if(page.endswith('.css')): with open(html_files[page], 'rb') as file: return send_file(html_files[page], mimetype="text/css") with open(html_files[page], 'rb') as file: return file.read() content = replace_placeholders(html_files[page]) return content else: return "

Stranica nije pronađena

", 404 if __name__ == '__main__': serve(app,host='0.0.0.0', port=8000)