mirror of
https://github.com/danpros/htmly.git
synced 2026-04-19 12:06:22 +05:30
Add limit RSS length
Add option to limit rss length.
This commit is contained in:
parent
7a6e19624f
commit
b47cf3e363
5 changed files with 43 additions and 23 deletions
|
|
@ -34,7 +34,6 @@ tag.perpage = "10"
|
|||
archive.perpage = "10"
|
||||
search.perpage = "10"
|
||||
profile.perpage = "10"
|
||||
rss.count = "10"
|
||||
json.count = "10"
|
||||
|
||||
; Related posts
|
||||
|
|
@ -49,6 +48,12 @@ teaser.char = "200"
|
|||
; Description char count
|
||||
description.char = "150"
|
||||
|
||||
;RSS feed count
|
||||
rss.count = "10"
|
||||
|
||||
;RSS feed description length. If left empty we will use full page.
|
||||
rss.char = ""
|
||||
|
||||
; Enable image thumbnail on teaser, the options is "true" and "false". If set to "true", you can specify the default thumbnail also.
|
||||
img.thumbnail = "true"
|
||||
default.thumbnail = ""
|
||||
|
|
|
|||
|
|
@ -27,8 +27,15 @@ get('/index', function () {
|
|||
$total = '';
|
||||
|
||||
if(empty($posts) || $page < 1){
|
||||
|
||||
// a non-existing page
|
||||
welcome_page();
|
||||
render('no-posts',array(
|
||||
'title' => config('blog.title'),
|
||||
'canonical' => site_url(),
|
||||
'description' => config('blog.description'),
|
||||
'bodyclass' => 'noposts',
|
||||
));
|
||||
|
||||
die;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -961,6 +961,7 @@ function generate_rss($posts){
|
|||
|
||||
$feed = new Feed();
|
||||
$channel = new Channel();
|
||||
$rssLength = config('rss.char');
|
||||
|
||||
$channel
|
||||
->title(config('blog.title'))
|
||||
|
|
@ -969,6 +970,23 @@ function generate_rss($posts){
|
|||
->appendTo($feed);
|
||||
|
||||
foreach($posts as $p){
|
||||
|
||||
if(!empty($rssLength)) {
|
||||
if (strlen(strip_tags($p->body)) < config('rss.char')) {
|
||||
$string = preg_replace('/\s\s+/', ' ', strip_tags($p->body));
|
||||
$body = $string . '...' . ' <a class="readmore" href="' . $p->url . '#more">more</a>' ;
|
||||
}
|
||||
else {
|
||||
$string = preg_replace('/\s\s+/', ' ', strip_tags($p->body));
|
||||
$string = substr($string, 0, config('rss.char'));
|
||||
$string = substr($string, 0, strrpos($string, ' '));
|
||||
$body = $string . '...' . ' <a class="readmore" href="' . $p->url . '#more">more</a>' ;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$body = $p->body;
|
||||
}
|
||||
|
||||
$item = new Item();
|
||||
$tags = explode(',', str_replace(' ', '', strip_tags($p->tag)));
|
||||
foreach($tags as $tag) {
|
||||
|
|
@ -978,7 +996,7 @@ function generate_rss($posts){
|
|||
$item
|
||||
->title($p->title)
|
||||
->pubDate($p->date)
|
||||
->description($p->body)
|
||||
->description($body)
|
||||
->url($p->url)
|
||||
->appendTo($channel);
|
||||
}
|
||||
|
|
@ -1087,7 +1105,7 @@ function generate_sitemap($str){
|
|||
elseif ($str == 'base') {
|
||||
|
||||
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
|
||||
echo '<url><loc>' . site_url() . '</loc><changefreq>hourly</changefreq><priority>1.0</priority></url>';
|
||||
echo '<url><loc>' . site_url() . '</loc><priority>1.0</priority></url>';
|
||||
echo '</urlset>';
|
||||
|
||||
}
|
||||
|
|
@ -1098,7 +1116,7 @@ function generate_sitemap($str){
|
|||
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
|
||||
|
||||
foreach($posts as $p) {
|
||||
echo '<url><loc>' . $p->url . '</loc><changefreq>monthly</changefreq><priority>0.5</priority></url>';
|
||||
echo '<url><loc>' . $p->url . '</loc><priority>0.5</priority></url>';
|
||||
}
|
||||
|
||||
echo '</urlset>';
|
||||
|
|
@ -1113,7 +1131,7 @@ function generate_sitemap($str){
|
|||
if(!empty($posts)) {
|
||||
|
||||
foreach($posts as $p) {
|
||||
echo '<url><loc>' . $p->url . '</loc><changefreq>monthly</changefreq><priority>0.5</priority></url>';
|
||||
echo '<url><loc>' . $p->url . '</loc><priority>0.5</priority></url>';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1149,7 +1167,7 @@ function generate_sitemap($str){
|
|||
$tag = array_unique($tag, SORT_REGULAR);
|
||||
|
||||
foreach($tag as $t) {
|
||||
echo '<url><loc>' . $t . '</loc><changefreq>weekly</changefreq><priority>0.5</priority></url>';
|
||||
echo '<url><loc>' . $t . '</loc><priority>0.5</priority></url>';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1178,15 +1196,15 @@ function generate_sitemap($str){
|
|||
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
|
||||
|
||||
foreach($day as $d) {
|
||||
echo '<url><loc>' . $d . '</loc><changefreq>monthly</changefreq><priority>0.5</priority></url>';
|
||||
echo '<url><loc>' . $d . '</loc><priority>0.5</priority></url>';
|
||||
}
|
||||
|
||||
foreach($month as $m) {
|
||||
echo '<url><loc>' . $m . '</loc><changefreq>monthly</changefreq><priority>0.5</priority></url>';
|
||||
echo '<url><loc>' . $m . '</loc><priority>0.5</priority></url>';
|
||||
}
|
||||
|
||||
foreach($year as $y) {
|
||||
echo '<url><loc>' . $y . '</loc><changefreq>monthly</changefreq><priority>0.5</priority></url>';
|
||||
echo '<url><loc>' . $y . '</loc><priority>0.5</priority></url>';
|
||||
}
|
||||
|
||||
echo '</urlset>';
|
||||
|
|
@ -1206,7 +1224,7 @@ function generate_sitemap($str){
|
|||
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
|
||||
|
||||
foreach($author as $a) {
|
||||
echo '<url><loc>' . $a . '</loc><changefreq>daily</changefreq><priority>0.5</priority></url>';
|
||||
echo '<url><loc>' . $a . '</loc><priority>0.5</priority></url>';
|
||||
}
|
||||
|
||||
echo '</urlset>';
|
||||
|
|
@ -1245,16 +1263,4 @@ function generate_opml(){
|
|||
// Turn an array of posts into a JSON
|
||||
function generate_json($posts){
|
||||
return json_encode($posts);
|
||||
}
|
||||
|
||||
function welcome_page() {
|
||||
echo <<<EOF
|
||||
<div style="font-size:20px;text-align:center;padding:50px 20px;">
|
||||
<h1>Welcome to your new HTMLy-powered blog.</h1>
|
||||
<p>The next thing you will need to do is creating the first account. Please create <strong><em>YourUsername.ini</em></strong> inside <strong><em>config/users</em></strong> folder and write down your password there:</p>
|
||||
<pre><code>password = YourPassword</code></pre>
|
||||
<p>Login to your blog admin panel at <strong><em>www.example.com/admin</em></strong> to creating your first post.</p>
|
||||
<p>This welcome message will disappear after your first post published.</p>
|
||||
</div>
|
||||
EOF;
|
||||
}
|
||||
1
themes/clean/no-posts.html.php
Normal file
1
themes/clean/no-posts.html.php
Normal file
|
|
@ -0,0 +1 @@
|
|||
<h1>No posts found!</h1>
|
||||
1
themes/default/no-posts.html.php
Normal file
1
themes/default/no-posts.html.php
Normal file
|
|
@ -0,0 +1 @@
|
|||
<h1>No posts found!</h1>
|
||||
Loading…
Add table
Add a link
Reference in a new issue