-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrss.php
52 lines (43 loc) · 1.6 KB
/
rss.php
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require './assets/tools/feedwriter/Item.php';
require './assets/tools/feedwriter/Feed.php';
require './assets/tools/feedwriter/RSS2.php';
require './assets/tools/feedwriter/simple_html_dom.php';
require './assets/tools/parsedown.php';
require './assets/tools/FrontMatter.php';
require './config.php';
date_default_timezone_set('UTC');
use \FeedWriter\RSS2;
$TestFeed = new RSS2;
$TestFeed
->setTitle($BLOG_TITLE)
->setLink($BLOG_LINK)
->setDescription($BLOG_DESCRIPTION)
->setChannelElement('language', $LANG)
->setSelfLink($BLOG_LINK . 'rss.php')
->setAtomLink($BLOG_LINK . 'rss.php', 'hub')
->addGenerator()
->setImage($BLOG_TITLE, $BLOG_LINK, $BLOG_LINK . 'assets/img/og.png');
$files = glob("posts/*.md");
rsort($files);
foreach ($files as $postFile) {
$link_id = pathinfo($postFile, PATHINFO_FILENAME);
$frontmatter = new FrontMatter($postFile);
$postContent = $frontmatter->fetchContent($postFile);
$Parsedown = new Parsedown();
$newItem = $TestFeed->createNewItem();
$meta = $frontmatter->fetchMeta();
$title = $meta['title'];
$itemDate = !empty($meta['published_date']) ? $meta['published_date'] : filemtime($postFile);
$content = stristr($postContent, "<p>");
$contentFinal = $Parsedown->text($postContent);
$newItem
->setTitle($title)
->setLink($BLOG_LINK . 'single.php?id=' . $link_id)
->setID($BLOG_LINK . 'single.php?id=' . $link_id)
->setDate($itemDate)
->setDescription($contentFinal)
->setAuthor($BLOG_AUTHOR, $AUTHOR_EMAIL);
$TestFeed->addItem($newItem);
}
$TestFeed->printFeed();