Skip to content

Commit

Permalink
minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
jirikuchta committed Apr 15, 2024
1 parent 7f36c8f commit 18090d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions static/less/articles.less
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ rr-item-articles {
gap: 8px;
}

.text {
> div {
overflow: hidden;
flex: 1 1 calc(100% - var(--picture-width) - var(--h-gap));
}

.picture {
picture {
width: 120px;
height: 80px;
text-align: right;
Expand Down
20 changes: 6 additions & 14 deletions static/ts/ui/articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ class Item extends HTMLElement {
this.read = this.data.read;

this.append(buildHeader(this.data), buildText(this.data));

let img = buildImage(this.data);
img && this.append(img);
if (this.data.image_url && settings.getItem("showImages")) {
this.append(buildPicture(this.data.image_url));
}

pubsub.subscribe("articles-updated", this);
}
Expand Down Expand Up @@ -227,7 +227,6 @@ function buildHeader(article: types.Article) {

function buildText(article: types.Article) {
let node = document.createElement("div");
node.className = "text";

let title = document.createElement("h3");
title.textContent = article.title;
Expand All @@ -240,19 +239,12 @@ function buildText(article: types.Article) {
return node;
}

function buildImage(article: types.Article) {
if (!article.image_url) { return; }
if (!settings.getItem("showImages")) { return; }

let node = document.createElement("div");
node.className = "picture";

function buildPicture(image_url: string) {
let node = document.createElement("picture");
let img = new Image();
img.src = article.image_url;
img.src = image_url;
img.loading = "lazy";

node.append(img);

return node;
}

Expand Down
8 changes: 7 additions & 1 deletion static/ts/ui/detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const BODY_CSS = `
height: auto !important;
}
iframe, video {
width: 100%;
aspect-ratio: 16/9;
}
br { display: none; }
`;

Expand All @@ -31,7 +36,7 @@ export default class Detail extends HTMLElement {
set article(data: types.Article) {
let article = new Article(data);
this.replaceChildren(article, new Tools(article), buildCloseButton(this.app));
await articles.markRead([data.id]);
articles.markRead([data.id]);
}
}

Expand Down Expand Up @@ -151,6 +156,7 @@ function buildBody(article: types.Article, content?: string) {
shadow.querySelectorAll("img").forEach(elm => elm.loading = "lazy");
shadow.querySelectorAll("a").forEach(elm => elm.target = "_blank");
shadow.querySelectorAll("[style]").forEach(elm => elm.removeAttribute("style"));
shadow.querySelectorAll("[class]").forEach(elm => elm.removeAttribute("class"));

return node;
}
Expand Down

0 comments on commit 18090d4

Please sign in to comment.