from flask import Flask, render_template_string import subprocess import os import re import datetime pocelo = datetime.datetime.now() app = Flask(__name__) visits = 0 navbar = """ """ # Putanje do HTML datoteka 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') } # Putanja do fajla sa brojem posjeta visit_file = os.path.join(base_dir, 'visits.txt') # Git commit info git_commit = result = subprocess.run( ['git', 'log', '-1', '--pretty=%B'], capture_output=True, text=True, check=True ).stdout.splitlines()[0] # MOTD (Message of the Day) motd = "Dobrodošli na našu stranicu!" # Funkcija za broj posjeta # Funkcija za zamjenu placeholder-a u HTML sadržaju 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 # Ruta za početnu stranicu @app.route('/') def home(): # Učitavanje index.html i zamjena placeholder-a print(html_files) content = replace_placeholders(html_files['index.html']) return content # Ruta za druge stranice (projects, contribute) @app.route('/') def other_pages(page): # Provjera ako stranica postoji u mapiranju if page in html_files: content = replace_placeholders(html_files[page]) return content else: return "

Stranica nije pronađena

", 404 if __name__ == '__main__': app.run(debug=True, host='0.0.0.0', port=8000)