Skip to content

Commit

Permalink
Add ellipse to text.
Browse files Browse the repository at this point in the history
Add Read full story link to the end of the description.
Update styles.
  • Loading branch information
emerham committed Dec 9, 2022
1 parent cf50fdd commit 8f8f90f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
11 changes: 9 additions & 2 deletions css/live_feeds_news.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,22 @@
.live-feeds-news .news-item .news-item__image {
clear: left;
float: left;
margin-right: 10px;
margin-right: .5rem;
margin-top: .5rem;
}

.live-feeds-news .news-item .news-item__image img {
aspect-ratio: 1 / 1;
border-radius: .25rem;
object-fit: cover;
width: 75px;
}

.live-feeds-news .news-item .news-item__date {
color: #565656;
display: inline;
font-size: 0.93em;
font-style: italic;
text-wrap: avoid;
white-space: nowrap;
}

Expand Down
4 changes: 2 additions & 2 deletions src/LiveFeedsSmartTrim.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public static function trustedCallbacks() {
public function liveFeedsLimit($stringBig, $wordLimit) {
$string = explode(' ', $stringBig);
if (count($string) > $wordLimit) {
return implode(' ', array_slice($string, 0, $wordLimit)) . " ...";
return implode(' ', array_slice($string, 0, $wordLimit)) . " …";
}
return implode(' ', $string) . " ...";
return implode(' ', $string) . " …";
}

}
8 changes: 5 additions & 3 deletions src/Plugin/Block/LiveFeedsNews.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,19 @@ public function build() {
$body = $html->getElementsByTagName('div')->item(1)->nodeValue;
$pub_date = $this->apStyleDateFormatter->formatTimestamp(strtotime($date_text), ['always_display_year' => TRUE]);

$build['#live_feeds_news_data']['#' . $items]['#news_thumb']['#markup'] = '<img src="' . $thumb . '" width="75" height="75" alt="OSU News Release" />';
$build['#live_feeds_news_data']['#' . $items]['#news_thumb']['#markup'] = '<img src="' . $thumb . '" width="75" alt="OSU News Release" />';
$url = Url::fromUri($story->link);
$read_more_link = Link::fromTextAndUrl($this->t('Read full story'), $url)
->toString();
$build['#live_feeds_news_data']['#' . $items]['#news_story_link'] = Link::fromTextAndUrl($story->title, $url);
$build['#live_feeds_news_data']['#' . $items]['#news_date'] = $pub_date;

// Display teaser if there is one, else truncate body.
if (isset($teaser) && $word_limit > 20) {
$build['#live_feeds_news_data']['#' . $items]['#news_teaser']['#markup'] = $teaser;
$build['#live_feeds_news_data']['#' . $items]['#news_teaser']['#markup'] = $teaser . $read_more_link;
}
else {
$build['#live_feeds_news_data']['#' . $items]['#news_teaser']['#markup'] = $this->liveFeedsSmartTrim->liveFeedsLimit(trim($body), $word_limit);
$build['#live_feeds_news_data']['#' . $items]['#news_teaser']['#markup'] = $this->liveFeedsSmartTrim->liveFeedsLimit(trim($body), $word_limit) . ' ' . $read_more_link;
}
}
libxml_clear_errors();
Expand Down

0 comments on commit 8f8f90f

Please sign in to comment.