Преглед изворни кода

Add logo information and display it in the UI

jherve пре 1 година
родитељ
комит
3501a02749

+ 3 - 0
src/de_quoi_parle_le_monde/article.py

@@ -79,6 +79,9 @@ class ArchiveCollection:
     name: str
     url: str
     MainPageClass: type[MainPage]
+    logo_background_color: str
+    logo_src: str | None = None
+    logo_content: str | None = None
 
 
 def to_text(soup: BeautifulSoup, selector: str) -> str:

Разлика између датотеке није приказан због своје велике величине
+ 17 - 3
src/de_quoi_parle_le_monde/medias/__init__.py


+ 13 - 1
src/de_quoi_parle_le_monde/web.py

@@ -33,9 +33,21 @@ def add_date_processing(_any):
     }
 
 
+def add_logos(_any):
+    return {
+        "logos_info": {m.name: {
+            "background_color": m.logo_background_color,
+            "content": m.logo_content,
+            "src": m.logo_src,
+        } for m in media_collection.values()}
+    }
+
+
 app = FastAPI()
 app.mount("/static", StaticFiles(directory="static"), name="static")
-templates = Jinja2Templates(directory="templates", context_processors=[add_date_processing])
+templates = Jinja2Templates(
+    directory="templates", context_processors=[add_date_processing, add_logos]
+)
 
 
 async def get_db():

+ 10 - 0
static/style.css

@@ -17,6 +17,16 @@ h1, h2, h3, h4 {
     grid-template-rows: 1fr 3fr 1fr;
 }
 
+.site_logo {
+    display: inline-block;
+    padding: 0.1em;
+    width: 100px;
+}
+.site_logo svg,
+.site_logo img {
+    width: 100px;
+}
+
 #article_browser a {
     text-decoration: none;
 }

+ 3 - 1
templates/index.html

@@ -1,3 +1,5 @@
+{% import 'ui.html' as ui with context %}
+
 <html>
 <head>
     <title>Hello</title>
@@ -9,7 +11,7 @@
 
     <ul>
         {% for s in sites %}
-            <li><a href="{{ url_for('site_main_article_snapshot', id=s['id']) }}">{{ s["name"] }}</a></li>
+            <li><a href="{{ url_for('site_main_article_snapshot', id=s['id']) }}">{{ ui.logo(s["name"]) }}</a></li>
         {% endfor %}
     </ul>
 </body>

+ 7 - 4
templates/site_main_article_detail.html

@@ -1,18 +1,20 @@
+{% import 'ui.html' as ui with context %}
+
 <html>
 <head>
     <title>Hello</title>
     <link href="{{ url_for('static', path='/style.css') }}" rel="stylesheet">
 </head>
 <body>
-    <a href="{{ url_for('index') }}">Homepage</a>
-    <h1>{{ focused["site_name"] }}</h1>
-
     {% macro article(a) -%}
         <a href="{{ url_for('site_main_article_snapshot', id=a['site_id'], snapshot_id=a['featured_article_snapshot_id']) }}">
-            [{{ a["site_name"] }}] {{ a["title"] }}
+            {{ ui.logo(a["site_name"]) }} {{ a["title"] }}
         </a>
     {%- endmacro %}
 
+    <a href="{{ url_for('index') }}">Homepage</a>
+    <h1>{{ ui.logo(focused["site_name"]) }}</h1>
+
     <div id="article_browser">
         <div class="up">
             <ul>
@@ -24,6 +26,7 @@
         <div class="focused">
             <a href="{{ focused['url_article'] }}"><h2>{{ focused["title"] }} <img src="{{ url_for('static', path='/external-link.svg') }}" height="30px"></h2></a>
             <time datetime="{{ focused['timestamp_virtual'] }}">{{ absolute_datetime(focused["timestamp_virtual"]) }}</time>
+            {{ ui.logo(focused["site_name"]) }}
             <div class="similar">
                 <h3>Articles similaires</h3>
                 <ul>

+ 11 - 0
templates/ui.html

@@ -0,0 +1,11 @@
+{% macro logo(site_name) -%}
+    {% set logo_info = logos_info[site_name] %}
+
+    <span class="site_logo" style="background-color: {{ logo_info['background_color'] }};">
+        {% if logo_info['content'] %}
+            {{ logo_info['content'] | safe }}
+        {% else %}
+            <img src="{{ logo_info['src'] }}" />
+        {% endif %}
+    </span>
+{%- endmacro %}