diff --git a/robots.txt b/robots.txt
index bd761f4..6534f66 100644
--- a/robots.txt
+++ b/robots.txt
@@ -29,6 +29,4 @@ Disallow: /composer.json
Disallow: /composer.lock
Disallow: /composer.phar
# Paths
-Disallow: /search/
-
-Sitemap: /feed/sitemap
\ No newline at end of file
+Disallow: /search/
\ No newline at end of file
diff --git a/system/config.ini b/system/config.ini
index 57f6d67..6b58432 100644
--- a/system/config.ini
+++ b/system/config.ini
@@ -33,8 +33,8 @@ posts.perpage = "5"
tag.perpage = "10"
archive.perpage = "10"
search.perpage = "10"
-profile.perpage = "30"
-rss.count = "30"
+profile.perpage = "10"
+rss.count = "10"
json.count = "10"
; Related posts
diff --git a/system/htmly.php b/system/htmly.php
index 6c6f65f..adb50fd 100644
--- a/system/htmly.php
+++ b/system/htmly.php
@@ -203,6 +203,32 @@ get('/search/:keyword', function($keyword){
// The static page
get('/:static', function($static){
+ if($static === 'sitemap.xml' || $static === 'sitemap.base.xml' || $static === 'sitemap.post.xml' || $static === 'sitemap.static.xml' || $static === 'sitemap.tag.xml' || $static === 'sitemap.archive.xml') {
+
+ header('Content-Type: text/xml');
+
+ if ($static === 'sitemap.xml') {
+ generate_sitemap('index');
+ }
+ else if ($static === 'sitemap.base.xml') {
+ generate_sitemap('base');
+ }
+ else if ($static === 'sitemap.post.xml') {
+ generate_sitemap('post');
+ }
+ else if ($static === 'sitemap.static.xml') {
+ generate_sitemap('static');
+ }
+ else if ($static === 'sitemap.tag.xml') {
+ generate_sitemap('tag');
+ }
+ else if ($static === 'sitemap.archive.xml') {
+ generate_sitemap('archive');
+ }
+
+ die;
+ }
+
$post = get_static_post($static);
if(!$post){
@@ -279,15 +305,6 @@ get('/feed/rss',function(){
echo generate_rss(get_posts(null, 1, config('rss.count')));
});
-// Show the RSS feed for sitemap
-get('/feed/sitemap',function(){
-
- header('Content-Type: application/rss+xml');
-
- // Generate RSS feed for all blog posts
- echo generate_sitemap(get_posts(null, null, null));
-});
-
// Generate OPML file
get('/feed/opml',function(){
diff --git a/system/includes/functions.php b/system/includes/functions.php
index a63c43e..6907316 100644
--- a/system/includes/functions.php
+++ b/system/includes/functions.php
@@ -504,7 +504,7 @@ function archive_list() {
echo '
';
# Sort the months
- ksort($months);
+ krsort($months);
$by_month = array_count_values($months);
foreach ($by_month as $month => $count){
$name = date('F', mktime(0,0,0,$month,1,2010));
@@ -815,7 +815,6 @@ EOF;
}
}
-
// The not found error
function not_found(){
error(404, render('404', null, false));
@@ -847,27 +846,172 @@ function generate_rss($posts){
echo $feed;
}
-// Turn an array of posts into an RSS feed for sitemap
-function generate_sitemap($posts){
+// Return post, tag, archive url.
+function get_path(){
+
+ $posts = get_post_sorted();
- $feed = new Feed();
- $channel = new Channel();
+ $tmp = array();
- $channel
- ->title(config('blog.title'))
- ->description(config('blog.description'))
- ->url(site_url())
- ->appendTo($feed);
+ foreach($posts as $index => $v){
- foreach($posts as $p){
- $item = new Item();
- $item
- ->title($p->title)
- ->url($p->url)
- ->appendTo($channel);
+ $post = new stdClass;
+
+ $filepath = $v['dirname'] . '/' . $v['basename'];
+
+ // Extract the date
+ $arr = explode('_', $filepath);
+
+ // Replaced string
+ $replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/';
+
+ // Author string
+ $str = explode('/', $replaced);
+ $author = $str[count($str)-3];
+
+ $post->authorurl = site_url() . 'author/' . $author;
+
+ // The post date
+ $post->date = strtotime(str_replace($replaced,'',$arr[0]));
+
+ // The archive per day
+ $post->archiveday = site_url(). 'archive/' . date('Y-m-d', $post->date) ;
+
+ // The archive per day
+ $post->archivemonth = site_url(). 'archive/' . date('Y-m', $post->date) ;
+
+ // The archive per day
+ $post->archiveyear = site_url(). 'archive/' . date('Y', $post->date) ;
+
+ // The post URL
+ $post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]);
+
+ // The post tag url
+ $post->tagurl = site_url(). 'tag/' . $arr[1];
+
+ $tmp[] = $post;
+ }
+
+ return $tmp;
+}
+
+// Return static page path.
+function get_static_path(){
+
+ $posts = get_static_pages();
+
+ $tmp = array();
+
+ // Create a new instance of the markdown parser
+ $md = new MarkdownParser();
+
+ foreach($posts as $index => $v){
+
+ $post = new stdClass;
+
+ // Replaced string
+ $replaced = substr($v, 0, strrpos($v, '/')) . '/';
+
+ // The static page URL
+ $url = str_replace($replaced,'',$v);
+ $post->url = site_url() . str_replace('.md','',$url);
+
+ $tmp[] = $post;
+
+ }
+
+ return $tmp;
+}
+
+// Generate sitemap.xml.
+function generate_sitemap($str){
+
+ echo '';
+
+ if ($str == 'index') {
+ echo '';
+ echo '' . site_url() . 'sitemap.base.xml';
+ echo '' . site_url() . 'sitemap.post.xml';
+ echo '' . site_url() . 'sitemap.static.xml';
+ echo '' . site_url() . 'sitemap.tag.xml';
+ echo '' . site_url() . 'sitemap.archive.xml';
+ echo '';
+ }
+ elseif ($str == 'base') {
+ echo '';
+ echo '' . site_url() . 'hourly1.0';
+ echo '';
+ }
+ elseif ($str == 'post') {
+
+ $posts = get_path();
+
+ echo '';
+ foreach($posts as $p) {
+ echo '' . $p->url . 'monthly0.5';
+ }
+ echo '';
+ }
+ elseif ($str == 'static') {
+
+ $posts = get_static_path();
+
+ echo '';
+ foreach($posts as $p) {
+ echo '' . $p->url . 'monthly0.5';
+ }
+ echo '';
+ }
+ elseif ($str == 'tag') {
+
+ $posts = get_path();
+ $tag = array();
+ foreach($posts as $p) {
+ $tag[] = $p->tagurl;
+ }
+ $tag = array_unique($tag, SORT_REGULAR);
+
+ echo '';
+ foreach($tag as $t) {
+ echo '' . $t . 'weekly0.5';
+ }
+ echo '';
+ }
+ elseif ($str == 'archive') {
+
+ $posts = get_path();
+ $day = array();
+ $month = array();
+ $year = array();
+
+ foreach($posts as $p) {
+ $day[] = $p->archiveday;
+ $month[] = $p->archivemonth;
+ $year[] = $p->archiveyear;
+
+ }
+
+ $day = array_unique($day, SORT_REGULAR);
+ $month = array_unique($month, SORT_REGULAR);
+ $year = array_unique($year, SORT_REGULAR);
+
+ echo '';
+
+ foreach($day as $d) {
+ echo '' . $d . 'monthly0.5';
+ }
+
+ foreach($month as $m) {
+ echo '' . $m . 'monthly0.5';
+ }
+
+ foreach($year as $y) {
+ echo '' . $y . 'monthly0.5';
+ }
+
+ echo '';
}
- echo $feed;
}
// Function to generate OPML file