目次

Sitemap

sitemap generators

googleのサイトマップ自動生成スクリプト。 これを利用して毎日サイトマップを自動更新するようにする。

sitemap_genのダウンロード

下記サイトからsitemap_gen_1.5.tar.gzをダウンロード

sitemap-generators http://code.google.com/p/sitemap-generators/

解凍した物の中にある、下記の3つのファイルを利用する

example_config.xmlのファイル名は適当に変更しておく

設定

example_config.xmlを編集する。

ファイルのurl取得方法はいくつかあるがdirectoryタグを使って ディレクトリ内のファイルを一括登録してくれる方法を使う。
cronで扱い易いのとsitemap_gen1.5からこの方法でも最終更新日、 優先順位を指定してくれるようになったため。

xmlの構成としては

<site>
 <directory />
 <filter />
</site>

となる

siteタグ

directoryタグ

filterタグ

example

directoryで/var/wwwの中にあるファイルを一括取得するようになっている
filterでmt、バージョン管理の中にあるファイルは対象に含めないようにしている

<site
  base_url="http://xxx.yyy.jp/"
  store_into="/var/www/sitemap.xml"
  verbose="1"
  sitemap_type="web"
>
 
 <directory
   path="/var/www"
   url="http://xxx.yyy.jp/"
   default_file="index.html"
   remove_empty_directories="false"
 />
 
 <filter action="drop" type="wildcard" pattern="*mt/*" />
 <filter action="drop" type="wildcard" pattern="*MT/*" />
 <filter action="drop" type="wildcard" pattern="*.svn/*" />
 <filter action="drop" type="wildcard" pattern="*.hg/*" />
 <filter action="drop" type="wildcard" pattern="*.git/*" /> 
 <filter action="pass" type="regexp" pattern=".*¥.htm$" />
 <filter action="pass" type="regexp" pattern=".*¥.html$" />
 <filter action="pass" type="regexp" pattern=".*cgi$" />
 <filter action="pass" type="regexp" pattern=".*¥.php$" />
 <filter action="drop" type="wildcard" pattern="*" />
 
</site>

テスト

テストは3つのファイルを同じディレクトリにおき、 siteタグにsuppress_search_engine_notify=1を追加、下記コマンドを実行する。

python  ./sitemap_gen.py --config=example_config.xml --testing

こうするとgoogleにpingを送信しないので正しくファイルが生成されているかだけを 確認できる

サーバーに設置、設定

下記3つのファイルを同じディレクトリに置く

これをcronで動作させるためのシェルスクリプトを用意

sitemap.sh

#!/bin/sh
 
cd /var/sitemap_gen
/usr/bin/python  ./sitemap_gen.py --config=example_config.xml

んでcronに適当に登録。下の場合毎日3時10分にサイトマップ生成するように。

$ crontab -e
 
10 03 * * * /var/sitemap_gen/sitemap.sh