aboutsummaryrefslogtreecommitdiff
path: root/handler/RSS.php
blob: 08a21363b6aa747d7d04ded7e7da8f9daeacb148 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php

namespace handler;
use posts;
use Response;
use SkinContext;

class RSS extends \RequestHandler {

    public function get(): Response {
        global $config;

        $items = array_map(fn(\Post $post) => [
            'title' => $post->title,
            'link' => $post->getUrl(),
            'pub_date' => date(DATE_RSS, $post->ts),
            'description' => $post->getDescriptionPreview(500),
        ], posts::getPosts(0, 20));

        $ctx = new SkinContext('\\skin\\rss');
        $body = $ctx->atom(
            title: ($this->lang)('site_title'),
            link: 'https://'.$config['domain'],
            rss_link: 'https://'.$config['domain'].'/feed.rss',
            items: $items);

        $response = new Response(200, $body);
        $response->addHeader('Content-Type: application/rss+xml; charset=utf-8');
        return $response;
    }

}