mirror of
				https://github.com/kevinveenbirkenbach/homepage.veen.world.git
				synced 2025-11-04 01:18:09 +00:00 
			
		
		
		
	Added include svgs
This commit is contained in:
		
							
								
								
									
										14
									
								
								app/app.py
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								app/app.py
									
									
									
									
									
								
							@@ -11,6 +11,8 @@ FLASK_ENV = os.getenv("FLASK_ENV", "production")
 | 
			
		||||
FLASK_PORT = int(os.getenv("PORT", 5000))
 | 
			
		||||
print(f"🔧 Starting app on port {FLASK_PORT}, FLASK_ENV={FLASK_ENV}")
 | 
			
		||||
 | 
			
		||||
from flask import Flask, render_template, current_app
 | 
			
		||||
from markupsafe import Markup
 | 
			
		||||
 | 
			
		||||
# Initialize the CacheManager
 | 
			
		||||
cache_manager = CacheManager()
 | 
			
		||||
@@ -48,6 +50,18 @@ app = Flask(__name__)
 | 
			
		||||
load_config(app)
 | 
			
		||||
cache_icons_and_logos(app)
 | 
			
		||||
 | 
			
		||||
@app.context_processor
 | 
			
		||||
def utility_processor():
 | 
			
		||||
    def include_svg(path):
 | 
			
		||||
        full_path = os.path.join(current_app.root_path, 'static', path)
 | 
			
		||||
        try:
 | 
			
		||||
            with open(full_path, 'r', encoding='utf-8') as f:
 | 
			
		||||
                svg = f.read()
 | 
			
		||||
            return Markup(svg)
 | 
			
		||||
        except IOError:
 | 
			
		||||
            return Markup(f'<!-- SVG not found: {path} -->')
 | 
			
		||||
    return dict(include_svg=include_svg)
 | 
			
		||||
 | 
			
		||||
@app.before_request
 | 
			
		||||
def reload_config_in_dev():
 | 
			
		||||
    """Reload config and recache icons before each request in development mode."""
 | 
			
		||||
 
 | 
			
		||||
@@ -96,9 +96,11 @@ h3.footer-title {
 | 
			
		||||
  font-size: 1.3em;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.card-img-top i, .card-img-top object{
 | 
			
		||||
.card-img-top i, .card-img-top svg{
 | 
			
		||||
  font-size: 100px;
 | 
			
		||||
  fill: currentColor;
 | 
			
		||||
  width: 100px;
 | 
			
		||||
  height: auto;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
div#navbarNavheader li.nav-item {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,25 +2,16 @@
 | 
			
		||||
  <div class="card h-100 d-flex flex-column">
 | 
			
		||||
    <div class="card-body d-flex flex-column">
 | 
			
		||||
      <div class="card-img-top">
 | 
			
		||||
        {% if card.icon.cache %}
 | 
			
		||||
          {% if card.icon.cache.endswith('.svg') %}
 | 
			
		||||
            <object
 | 
			
		||||
              type="image/svg+xml"
 | 
			
		||||
              data="{{ url_for('static', filename=card.icon.cache) }}"
 | 
			
		||||
              style="width:100px; height:auto;">
 | 
			
		||||
              {% if card.icon.class %}
 | 
			
		||||
                <i class="{{ card.icon.class }}"></i>
 | 
			
		||||
              {% endif %}
 | 
			
		||||
            </object>
 | 
			
		||||
          {% else %}
 | 
			
		||||
            <img
 | 
			
		||||
              src="{{ url_for('static', filename=card.icon.cache) }}"
 | 
			
		||||
              alt="{{ card.title }}"
 | 
			
		||||
              style="width:100px; height:auto;"
 | 
			
		||||
              onerror="this.style.display='none'; this.nextElementSibling?.style.display='inline-block';">
 | 
			
		||||
            {% if card.icon.class %}
 | 
			
		||||
              <i class="{{ card.icon.class }}" style="display:none;"></i>
 | 
			
		||||
            {% endif %}
 | 
			
		||||
        {% if card.icon.cache and card.icon.cache.endswith('.svg') %}
 | 
			
		||||
          {{ include_svg(card.icon.cache) }}
 | 
			
		||||
        {% elif card.icon.cache %}
 | 
			
		||||
          <img
 | 
			
		||||
            src="{{ url_for('static', filename=card.icon.cache) }}"
 | 
			
		||||
            alt="{{ card.title }}"
 | 
			
		||||
            style="width:100px; height:auto;"
 | 
			
		||||
            onerror="this.style.display='none'; this.nextElementSibling?.style.display='inline-block';">
 | 
			
		||||
          {% if card.icon.class %}
 | 
			
		||||
            <i class="{{ card.icon.class }}" style="display:none;"></i>
 | 
			
		||||
          {% endif %}
 | 
			
		||||
        {% elif card.icon.class %}
 | 
			
		||||
          <i class="{{ card.icon.class }}"></i>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user