tomblooでtumblrにpostする時、自動でタグ付けするパッチ
tomblooでtumblrへpostする時、条件により自動的にタグ付けしてタグへのリンクをpostに付加します。
こんな感じ。下の朝日、newsってのがタグへのリンクになります。動作サンプル→ http://zaknak.tumblr.com/
参考にさせていただいた記事
- 僕がtombloo/scriptに入れているもの - cxxの日記 - たんぶら部 - Tumblove -
- Tombloo Patch、はてなブックマークでタイトルを修正しないようにする、アスペクト - 戦争
- Tomblooパッチ、GoogleBookmarksでポストするときに必ず特定のタグを付加する - 戦争
- Tombloo、抽出結果フォーマット - 戦争
addAround(Tumblr,'post', function(proceed, args, target, methodName){ var ps = args[0] = update({}, args[0]); var tagList = [ { //タグは配列にすれば複数付加します pageUrl : '^http://www.?\\.asahi\\.com/', tag : ['%u671D%u65E5','news'] }, { pageUrl : '^http://sankei\\.jp\\.msn\\.com/', tag : 'sankei' }, { //ページ名に '五輪'が含まれていた時、五輪タグを付ける page : '%u4E94%u8F2A', tag : '%u4E94%u8F2A' }, ] var addTag = function(tag){ ps.tags = ps.tags || []; ps.tags.push(tag); } tagList.forEach(function(tL){ if( (tL.pageUrl && ps.pageUrl.match(tL.pageUrl)) || (tL.itemUrl && ps.itemUrl.match(tL.itemUrl)) || (tL.page && ps.page.match(unescape(tL.page))) ){ if(isArrayLike(tL.tag)){ tL.tag.forEach(function(tag){ addTag(unescape(tag)); }); }else{ addTag(unescape(tL.tag)); } } if( tL.autoTag && ps.pageUrl.match(tL.pageUrl) && ps.page.match(tL.autoTag)){ addTag(RegExp.$1); } }); //タグへのリンクを付加する処理。要らなければ削って return proceed(args); return Tumblr.getCurrentId().addCallback(function(id){ if(id && ps.tags){ var taggedUrl = 'http://' + id + '.tumblr.com/tagged/'; var tagLink = ''; ps.tags.forEach(function(tag){ tagLink += '<a href="' + taggedUrl + encodeURI(tag) + '">' + tag + '</a> '; }); ps.description = ps.description || ''; ps.description += '<p id="tag">' + tagLink + '</p>'; } return proceed(args); }); });
タグ付けまでで、タグへのリンクは要らない気もしてきた。post の type を考慮してないので不都合があるかも。