add BK LuxusLAN news and update NewsPost component to improve image support

This commit was merged in pull request #6.
This commit is contained in:
David Rodenkirchen
2024-11-25 10:27:58 +01:00
parent 93e87b3d67
commit 051c290074
5 changed files with 50 additions and 5 deletions
+22 -4
View File
@@ -1,14 +1,20 @@
from dataclasses import dataclass
from pathlib import Path
from typing import Optional
from dataclasses import dataclass
import rio
@dataclass
class NewsPostImage:
path: Path
link: Optional[str]
class NewsPost(rio.Component):
header: str
date: str
article_text_path_or_text: str | Path
images: list[Path]
images: list[NewsPostImage]
article_text = ""
@rio.event.on_populate
@@ -25,8 +31,20 @@ class NewsPost(rio.Component):
def build(self) -> rio.Component:
image_column = rio.Column(margin=0.5)
for image_path in self.images:
image_column.add(rio.Image(image_path, fill_mode="fit", width=18, height=18, align_x=0.01))
for news_post_image in self.images:
image_obj = rio.Image(
news_post_image.path,
fill_mode="fit",
width=20,
height=20,
align_x=0.01
)
image_column.add(
rio.Link(image_obj,
target_url=news_post_image.link,
open_in_new_tab=True
) if bool(news_post_image.link) else image_obj
)
return rio.Rectangle(
content=rio.Column(
rio.Row(
@@ -47,7 +65,7 @@ class NewsPost(rio.Component):
)
def build_news_post(header: str, article_text_path_or_text: str | Path, date: str, images: Optional[list[Path]] = None) -> NewsPost:
def build_news_post(header: str, article_text_path_or_text: str | Path, date: str, images: Optional[list[NewsPostImage]] = None) -> NewsPost:
if images is None:
images = []
return NewsPost(