Googleが404 ページのカスタマイズでURLの候補を教えてくれるウィジェットを提供していたことを知るという……。
なんという徒労感……。
まぁ、どうもあまりうまく動いていないようなので、自作の方を使うんだ!!1きっとうまく動いてないよ!Googleのやつ!!1あとマークアップが嫌!JSONPとかで叩けるAPIで提供しておくれ。
JavaScriptだけで作ってる。大体できたので断片メモ。
で単語を切り出して配列に。
Array.prototype.unique = function () { var hash = new Object(); for (i = 0; i < this.length; i++) { hash[this[i]] = true; } var array = new Array(); for (value in hash) { array.push(value); } return array; };
でユニークに。
var stop_words = "a about above above across (略) would yet you your yours yourself yourselves"; var site_words = "hail2u net archives blog documents htm html"; stop_words = " " + stop_words + " " + site_words + " "; words = $.grep(words, function (m) { if (stop_words.indexOf(" " + m + " ") < 0) { return true; } else { return false; } });
Stop WordsとサイトのURLで多い単語を削除する。htmとhtmlの扱いもここで削除して誤魔化す。
(ここでスペル修正したい)
最後にSitemaps(XMLだからAJAXですね!!1)から取り出したURL一覧とつき合わせて、簡単な重み付けをしてスコア順に並べ替える。
最もスコアの高かったものを出力!