mirror of
https://github.com/Oreolek/oreolek.ru.git
synced 2024-05-17 16:38:22 +03:00
Site sitemap
This commit is contained in:
parent
97731124e2
commit
86d9530452
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -31,3 +31,6 @@
|
||||||
[submodule "modules/cache"]
|
[submodule "modules/cache"]
|
||||||
path = modules/cache
|
path = modules/cache
|
||||||
url = git@github.com:Oreolek/cache.git
|
url = git@github.com:Oreolek/cache.git
|
||||||
|
[submodule "modules/sitemap"]
|
||||||
|
path = modules/sitemap
|
||||||
|
url = git@github.com:flody/kohana-sitemap.git
|
||||||
|
|
|
@ -20,4 +20,5 @@ Oreolek.
|
||||||
* Copy `application/config/auth.php.example` to `application/config/auth.php` and edit it.
|
* Copy `application/config/auth.php.example` to `application/config/auth.php` and edit it.
|
||||||
* Import SQL schema from schema.sql (autoinstall currently not working)
|
* Import SQL schema from schema.sql (autoinstall currently not working)
|
||||||
* Open in browser `SERVER_ADDR/install`
|
* Open in browser `SERVER_ADDR/install`
|
||||||
|
* Edit robots.txt with your domain
|
||||||
* Set server variable `KOHANA_ENV` to `production` when you're done hacking
|
* Set server variable `KOHANA_ENV` to `production` when you're done hacking
|
||||||
|
|
|
@ -117,12 +117,20 @@ Kohana::modules(array(
|
||||||
'unittest' => MODPATH.'unittest', // Unit testing
|
'unittest' => MODPATH.'unittest', // Unit testing
|
||||||
'cache' => MODPATH.'cache', // Caching with multiple backends
|
'cache' => MODPATH.'cache', // Caching with multiple backends
|
||||||
// 'codebench' => MODPATH.'codebench', // Benchmarking tool
|
// 'codebench' => MODPATH.'codebench', // Benchmarking tool
|
||||||
|
'sitemap' => MODPATH.'sitemap', // Sitemap generator
|
||||||
));
|
));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the routes. Each route must have a minimum of a name, a URI and a set of
|
* Set the routes. Each route must have a minimum of a name, a URI and a set of
|
||||||
* defaults for the URI.
|
* defaults for the URI.
|
||||||
*/
|
*/
|
||||||
|
Route::set('sitemap_index', 'sitemap.xml(<gzip>)', array('gzip' => '\.gz'))
|
||||||
|
->defaults(array(
|
||||||
|
'controller' => 'Sitemap',
|
||||||
|
'action' => 'index'
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
Route::set('error', 'error/<action>(/<message>)', array('action' => '[0-9]++','message' => '.+'))
|
Route::set('error', 'error/<action>(/<message>)', array('action' => '[0-9]++','message' => '.+'))
|
||||||
->defaults(array(
|
->defaults(array(
|
||||||
'controller' => 'Error',
|
'controller' => 'Error',
|
||||||
|
|
29
application/classes/Controller/Sitemap.php
Normal file
29
application/classes/Controller/Sitemap.php
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?php defined('SYSPATH') or die('No direct script access.');
|
||||||
|
|
||||||
|
class Controller_Sitemap extends Controller {
|
||||||
|
public function action_index() {
|
||||||
|
$sitemap = new Sitemap();
|
||||||
|
if ($this->request->param('gzip'))
|
||||||
|
{
|
||||||
|
$sitemap->gzip = TRUE;
|
||||||
|
}
|
||||||
|
$posts = Model_Post::get_dates();
|
||||||
|
foreach ($posts as $id => $posted_at)
|
||||||
|
{
|
||||||
|
$url = new Sitemap_URL;
|
||||||
|
$url->set_loc(Route::url('default', array('controller' => 'Post', 'action' => 'view', 'id' => $id), TRUE));
|
||||||
|
$url->set_last_mod(strtotime($posted_at));
|
||||||
|
$url->set_change_frequency('weekly'); // new comments
|
||||||
|
$sitemap->add($url);
|
||||||
|
}
|
||||||
|
$pages = Model_Page::get_ids();
|
||||||
|
foreach ($pages as $id)
|
||||||
|
{
|
||||||
|
$url = new Sitemap_URL;
|
||||||
|
$url->set_loc(Route::url('default', array('controller' => 'Page', 'action' => 'view', 'id' => $id), TRUE));
|
||||||
|
$url->set_change_frequency('never');
|
||||||
|
$sitemap->add($url);
|
||||||
|
}
|
||||||
|
$this->response->body($sitemap->render());
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,4 +29,14 @@ class Model_Page extends ORM {
|
||||||
'content' => 'Текст страницы',
|
'content' => 'Текст страницы',
|
||||||
'is_draft' => 'Черновик'
|
'is_draft' => 'Черновик'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns array of ids and posted_at timestamps.
|
||||||
|
* Used in sitemap generation.
|
||||||
|
**/
|
||||||
|
public static function get_ids()
|
||||||
|
{
|
||||||
|
$query = DB::select('id')->from('pages');
|
||||||
|
return $query->execute()->as_array(NULL, 'id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,4 +62,14 @@ class Model_Post extends ORM {
|
||||||
$query = DB::select(array(DB::expr('MAX(`posted_at`)'), 'max_date'))->from('posts');
|
$query = DB::select(array(DB::expr('MAX(`posted_at`)'), 'max_date'))->from('posts');
|
||||||
return $query->execute()->get('max_date');
|
return $query->execute()->get('max_date');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns array of ids and posted_at timestamps.
|
||||||
|
* Used in sitemap generation.
|
||||||
|
**/
|
||||||
|
public static function get_dates()
|
||||||
|
{
|
||||||
|
$query = DB::select('id', 'posted_at')->from('posts');
|
||||||
|
return $query->execute()->as_array('id', 'posted_at');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,9 @@ $config['skip_configs'] = array('database', 'encrypt');
|
||||||
* Disabled routes
|
* Disabled routes
|
||||||
*/
|
*/
|
||||||
$config['excluded_routes'] = array(
|
$config['excluded_routes'] = array(
|
||||||
'docs/media' // Userguide media route
|
'docs/media', // Userguide media route
|
||||||
|
'sitemap', // Sitemaps
|
||||||
|
'sitemap_index' // Main sitemap
|
||||||
);
|
);
|
||||||
|
|
||||||
return $config;
|
return $config;
|
||||||
|
|
1
modules/sitemap
Submodule
1
modules/sitemap
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 7773a61dc857c0bf904003c8cdcfc3b4642aaf31
|
3
robots.txt
Normal file
3
robots.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
User-agent: *
|
||||||
|
Disallow:
|
||||||
|
Sitemap: http://oreolek.ru/sitemap.xml.gz
|
Loading…
Reference in a new issue