94 lines
3.1 KiB
Python
94 lines
3.1 KiB
Python
from flask import Flask, render_template, request, session, redirect, url_for, make_response
|
|
from translation_manager import init_app, translate, get_current_language, create_language_selector, set_language
|
|
import os
|
|
from datetime import datetime
|
|
from xml.etree import ElementTree as ET
|
|
|
|
app = Flask(__name__)
|
|
app.secret_key = os.environ.get('SECRET_KEY', 'your-secret-key-change-in-production')
|
|
|
|
# Initialize the translation system
|
|
init_app(app)
|
|
|
|
# Context processor to make variables available in templates
|
|
@app.context_processor
|
|
def inject_conf_var():
|
|
return dict(
|
|
translate=translate,
|
|
get_current_language=get_current_language,
|
|
create_language_selector=create_language_selector,
|
|
t=translate, # Short alias
|
|
current_year=datetime.now().year
|
|
)
|
|
|
|
def generate_sitemap():
|
|
"""Generate XML sitemap for the website"""
|
|
root = ET.Element("urlset")
|
|
root.set("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9")
|
|
|
|
# Define the main pages with their priorities and change frequencies
|
|
pages = [
|
|
{'url': '/', 'priority': '1.0', 'changefreq': 'weekly'},
|
|
{'url': '/services', 'priority': '0.9', 'changefreq': 'monthly'},
|
|
{'url': '/about', 'priority': '0.8', 'changefreq': 'monthly'},
|
|
{'url': '/contact', 'priority': '0.7', 'changefreq': 'monthly'},
|
|
{'url': '/portfolio', 'priority': '0.8', 'changefreq': 'weekly'},
|
|
]
|
|
|
|
base_url = "https://kobelly.com" # Change this to your actual domain
|
|
|
|
for page in pages:
|
|
url_elem = ET.SubElement(root, "url")
|
|
loc = ET.SubElement(url_elem, "loc")
|
|
loc.text = base_url + page['url']
|
|
|
|
lastmod = ET.SubElement(url_elem, "lastmod")
|
|
lastmod.text = datetime.now().strftime("%Y-%m-%d")
|
|
|
|
changefreq = ET.SubElement(url_elem, "changefreq")
|
|
changefreq.text = page['changefreq']
|
|
|
|
priority = ET.SubElement(url_elem, "priority")
|
|
priority.text = page['priority']
|
|
|
|
return ET.tostring(root, encoding='unicode', method='xml')
|
|
|
|
@app.route('/sitemap.xml')
|
|
def sitemap():
|
|
"""Serve the XML sitemap"""
|
|
sitemap_xml = generate_sitemap()
|
|
response = make_response(sitemap_xml)
|
|
response.headers["Content-Type"] = "application/xml"
|
|
return response
|
|
|
|
@app.route('/')
|
|
def index():
|
|
print("Current language in index:", get_current_language())
|
|
return render_template('index.html')
|
|
|
|
@app.route('/services')
|
|
def services():
|
|
return render_template('services.html')
|
|
|
|
@app.route('/contact')
|
|
def contact():
|
|
return render_template('contact.html')
|
|
|
|
@app.route('/about')
|
|
def about():
|
|
return render_template('about.html')
|
|
|
|
@app.route('/portfolio')
|
|
def portfolio():
|
|
return render_template('portfolio.html')
|
|
|
|
@app.route('/set_language/<language>')
|
|
def set_language_route(language):
|
|
"""Set the language and redirect back to the previous page"""
|
|
if set_language(language):
|
|
# Redirect back to the referring page or home
|
|
return redirect(request.referrer or url_for('index'))
|
|
return redirect(url_for('index'))
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True, host='0.0.0.0', port=5000) |