Publish::Bookmark

30分プログラム、その66。http://www.nslabs.jp/bookmark.dtd.htmで出力するプラグイン

はてブの一部をSafariのブックマークに登録したかったので作っていみた。

使いかたはこんな感じ。

- module: RSS::load
  config:
    url: http://b.hatena.ne.jp/mzp/rss?tag=%28about%29
- module: Publish::bookmark
  config:
    filename: about.html
def bookmark(config,data)
  path = config['filename']
  File.open(path,'w+'){|io|
    io.print <<-HTML
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!--This is an automatically generated file.
    It will be read and overwritten.
    Do Not Edit! -->
<HTML>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<Title>Bookmarks</Title>
<H1>Bookmarks</H1>
<DL>
    HTML
    
    io.puts data.map{|item|
      <<-HTML
<DT><A HREF="#{item.link}">#{item.title}</A>
      HTML
    }.join("\n")

    io.puts <<-HTML
</DL>
</HTML>
HTML
  }
  data
end
  • DTの閉じタグがないのは仕様。というかあるとうまく動かない
  • DDがないのも仕様。だった、ul+liでいいじゃん
  • それはさておき、便利便利