add news 060624
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
import rio
|
||||
|
||||
@@ -7,6 +8,7 @@ class NewsPost(rio.Component):
|
||||
header: str
|
||||
date: str
|
||||
article_text_path_or_text: str | Path
|
||||
images: list[Path]
|
||||
article_text = ""
|
||||
|
||||
@rio.event.on_populate
|
||||
@@ -22,6 +24,9 @@ class NewsPost(rio.Component):
|
||||
self.article_text = f.read()
|
||||
|
||||
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))
|
||||
return rio.Rectangle(
|
||||
content=rio.Column(
|
||||
rio.Row(
|
||||
@@ -31,7 +36,8 @@ class NewsPost(rio.Component):
|
||||
),
|
||||
rio.Column(
|
||||
rio.Markdown(self.article_text, margin=1)
|
||||
)
|
||||
),
|
||||
image_column
|
||||
),
|
||||
fill=self.session.theme.neutral_color,
|
||||
corner_radius=self.session.theme.corner_radius_medium,
|
||||
@@ -41,10 +47,13 @@ class NewsPost(rio.Component):
|
||||
)
|
||||
|
||||
|
||||
def build_news_post(header: str, article_text_path_or_text: str | Path, date: str) -> NewsPost:
|
||||
def build_news_post(header: str, article_text_path_or_text: str | Path, date: str, images: Optional[list[Path]] = None) -> NewsPost:
|
||||
if images is None:
|
||||
images = []
|
||||
return NewsPost(
|
||||
header=header,
|
||||
article_text_path_or_text=article_text_path_or_text,
|
||||
images=images,
|
||||
date=date,
|
||||
align_y=0,
|
||||
margin_top=0,
|
||||
|
||||
Reference in New Issue
Block a user