今天把Baidu Sitemap Generator搞到SAE上来了
2011-11-16偶今天花了几分钟,把Wordpress插件Baidu Sitemap Generator搞到了Sina App Engine上边。嘻嘻!
偶的百度站点地图:https://mawenjian.net/sitemap_baidu.xml,。
说下运行过程吧,先让Baidu Sitemap Generator将文件写入到Storage中,然后写个CURL的PHP文件抓取Storage中的sitemap,最后rewrite一下,搞定!
首先下载个Baidu Sitemap Generator插件,猛击这里。
然后,打开sitemap-function文件,找到第229行的IsFileWritable($filename)函数,把所有代码全部屏蔽,直接返回true。
function IsFileWritable($filename) { /* //can we write? if(!is_writable($filename)) { //no we can't. if(!@chmod($filename, 0666)) { $pathtofilename = dirname($filename); //Lets check if parent directory is writable. if(!is_writable($pathtofilename)) { //it's not writeable too. if(!@chmod($pathtoffilename, 0666)) { //darn couldn't fix up parrent directory this hosting is foobar. //Lets error because of the permissions problems. return false; } } } } //we can write, return 1/true/happy dance. */ return true; }
然后打开baidu_sitemap.php文件,找到
file_put_contents("$filename","$baidu_xml");
,替换为
/*file_put_contents("$filename","$baidu_xml"); */ $stor = new SaeStorage(); $stor->write ("wordpress", "sitemap_baidu.xml","$baidu_xml");
。再找到
file_put_contents("$filename_html","$html");
,将其替换为
/*file_put_contents("$filename_html","$html"); */ $stor = new SaeStorage(); $stor->write ("wordpress", "sitemap_baidu.html","$html");
PHP抓取文件代码(sitemap_baidu.php):
<?php header("Content-Type:text/xml "); $f = new SaeFetchurl(); $data = $f->fetch("http://mawenjian-wordpress.stor.sinaapp.com/sitemap_baidu.xml"]); echo $data; ?>
rewrite的代码:
handle: - rewrite:if (path ~ "\/sitemap_baidu.xml$") goto "sitemap_baidu.php" - rewrite:if (!is_file() && !is_dir() && path ~ "^/(.*)") goto "index.php/$1"
搞定定。。。打包文件见这里。
这插件许多年不更新了,物是人非啊