Publish::Kindleでmobiファイルを生成するときに画像を含める
Plaggerで朝日新聞のFeedを取得してKindleで閲覧する - mteramotoの日記で書いたPublish::Kindleだけだと、生成したmobiファイルに画像が含まれなくて寂しい。そこで、Filter::RewriteBodyURLを書いた。
このプラグインは、entry->bodyに含まれるURLのうちenclosure->urlに一致するものを、enclosure->local_pathに置き換える。Filter::FindEnclosures、Filter::FetchEnclosureと組み合わせれば、画像へのリンクがlocal_pathになるのでkindlegenがmobiファイルを生成するときに画像を同梱してくれるという仕組み。
こんなyamlを書くと、メールでmobiファイルが送られてきて、Kindleで閲覧したときに画像が表示される。ほかのFilterプラグインはお好みで追加すべし。
global: timezone: Asia/Tokyo assets_path: /path/to/plagger/assets log: level: debug plugins: - module: Subscription::Config config: feed: - url: http://www3.asahi.com/rss/index.rdf - module: Filter::EntryFullText - module: Filter::StripRSSAd - module: Filter::FindEnclosures - module: Filter::FetchEnclosure config: dir: /path/to/work - module: Filter::RewriteBodyURL - module: Publish::Kindle config: title: asahi.com work: /path/to/work kindlegen: /path/to/kindlegen mailto: なんとか@free.kindle.net mailfrom: hogehoge@example.com mailroute: via: smtp_tls host: smtp.gmail.com:587 username: Gmailのユーザ名 password: Gmailのパスワード