commit 15af59a9f0e856633d8e6a85509f3bc566539995
parent e1a391fdbf809ac78f44a00f6d85c9d1bf3ca286
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Tue, 29 Sep 2026 20:14:12 +0200
feat: sort and construct news items in PHP
Diffstat:
| M | index.tt | | | 106 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------- |
| M | perlanetrc.yaml | | | 5 | ++++- |
2 files changed, 82 insertions(+), 29 deletions(-)
diff --git a/index.tt b/index.tt
@@ -51,37 +51,87 @@
<main>
- <!-- Content Entries -->
+ <?php
+
+ $news = array();
[% FOREACH entry IN feed.entries %]
- <section>
- <!-- Headline -->
- <h4 style="margin-bottom:5px;">
- <a href="[% entry.link | url | html %]"
- target="_blank"
- rel="nofollow ugc"
- >
- [% entry.title | html %]
- </a>
- </h3>
- <!-- Information -->
- <div style="width:100%;margin-bottom:1em;">
- [% IF entry.issued %]
- <em style="margin-left:0.25em;color:var(--border);">
- [% entry.issued | html %]
- </em>
- [% END %]
- </div>
- <!-- Content -->
- <div class="article_content">
- [% IF entry.summary.body %]
- <!--start-->[% entry.summary.body %]<!--end-->
- [% ELSE %]
- <!--start-->[% entry.content.body %]<!--end-->
- [% END %]
- </div>
- </section>
+ array_push(
+ $news,
+ array(
+ "title" => "[%entry.title | html %]",
+ "url" => "[% entry.link | url %]",
+ "date" => strtotime("[% entry.issued | html %]"),
+ "content" => "[% IF entry.summary.body %][% entry.summary.body | html %][% ELSE %][% entry.content.body | html %][% END %]"
+ )
+ );
[% END %]
+ // Sort News item by time stamp
+ function compare(array $a, array $b) {
+ return $b["date"] - $a["date"];
+ }
+ usort($news, "compare");
+
+ ?>
+
+ <!-- Content Entries -->
+ <?php
+ $counter = 0;
+ foreach ($news as $entry) {
+
+ $counter++;
+ if ($counter > 24) {
+ continue;
+ }
+
+ if ($entry["date"] < strtotime("-24 hours")) {
+ continue;
+ }
+ if ($entry["content"] == "" || $entry["content"] == $entry["title"]) {
+ continue;
+ }
+
+ $entry["content"] = preg_replace(
+ '/<[^>]+>/',
+ '',
+ html_entity_decode($entry["content"])
+ );
+ $entry["domain"] = preg_replace(
+ '/^http(s)*:\/\/([^\/]+)\/.*$/',
+ '${2}',
+ $entry["url"]
+ );
+
+ ?>
+ <section>
+ <!-- Headline -->
+ <h4 style="margin-bottom:5px;">
+ <a href="<?php echo $entry["url"]; ?>"
+ target="_blank"
+ rel="nofollow ugc"
+ >
+ <?php echo $counter . ". " . $entry["title"]; ?>
+ </a>
+ </h3>
+ <!-- Information -->
+ <div style="width:100%;margin-bottom:1em;">
+ <em style="margin-left:0.25em;color:var(--border);">
+ <?php echo date("Y-m-d, H:i", $entry["date"]); ?>
+ </em>
+ <em style="margin-left:0.25em;color:var(--border);">
+ <?php echo $entry["domain"]; ?>
+ </em>
+ </div>
+ <!-- Content -->
+ <div class="article_content">
+ <?php echo $entry["content"]; ?>
+ </div>
+ </section>
+
+ <?php
+ }
+ ?>
+
</main>
<footer>
diff --git a/perlanetrc.yaml b/perlanetrc.yaml
@@ -6,7 +6,7 @@ entries: 500
entries_per_feed: 5
entries_sort_order: "modified"
page:
- file: index.html
+ file: index.php
template: index.tt
feed:
file: /dev/null
@@ -15,6 +15,9 @@ feeds:
- title: Tagesschau - Startseite
url: https://www.tagesschau.de/index~rss2.xml
web: https://www.tagesschau.de/
+ - title: DW _ Top Stories
+ url: https://rss.dw.com/atom/rss-de-top
+ web: https://www.dw.com/de/
- title: Zeit - Wichtigste Nachrichten
url: https://newsfeed.zeit.de/news/nachrichten
web: https://www.zeit.de/news/nachrichten