Hatena::Groupsubtech

おれ ここ めも かきなぐる おまえ ここ よむ なぐる

 | 

October 03, 2009

完成したところで……

10:31

Google404 ページのカスタマイズURLの候補を教えてくれるウィジェットを提供していたことを知るという……。

なんという徒労感……。

まぁ、どうもあまりうまく動いていないようなので、自作の方を使うんだ!!1きっとうまく動いてないよ!Googleのやつ!!1あとマークアップが嫌!JSONPとかで叩けるAPIで提供しておくれ。

URL提案システム完成した

10:27

URL Suggestion

404の時に近そうなURLと一つ上のディレクトリのURLが提案される。

URL修正作りかけ

04:48

JavaScriptだけで作ってる。大体できたので断片メモ。

  1. location.pathname
  2. decodeURIComponent()
  3. toLowerCase()
  4. replace(/[\s\/]*$/, "")
  5. replace(/^.*\//, "")
  6. replace(/[a-z]/g, function (m) { return String.fromCharCode(m.charCodeAt(0) - 65248); })
  7. replace(/[^a-z]/g, " ")
  8. split(/\s+/)

で単語を切り出して配列に。

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一覧とつき合わせて、簡単な重み付けをしてスコア順に並べ替える。

最もスコアの高かったものを出力!

 |