Lately I published a node module on npmjs.com:

https://www.npmjs.com/package/epub-gen

It's a nodejs library for generating Epub book in a simpe way. It's quite fast and cost less compute resource. By the way, it can auto download remote images within source html.

Demo Preview:

Sample html from Learning JavaScript Design Patterns - by Addy Osmani

Making a Epub ebook is much easier than mobi ebook, If you want to generate a mobi Ebook, you have several options:

All of them need to install third party library and cost a quite mount cpu and memeries, especialy kindlegen, it sucks.

But up to epub, it's a open document, an Epub file is essentially a zip file. You can extract a epub file with zip software, then you'll get a folder like following files:

  | mimetype
  |--META-INF
  |    container.xml
  \–-OEBPS
      |  content.opf
      |  toc.ncx
      |--images
      |    cover.png
      |    image_1.jpg
      |    image_2.jpg
      \--text
           chapter_1.html
           chapter_2.html
           chapter_3.html
           .....

Oppositely, you can compress a directory comtaining those files in to a .epub file. hover, if you compress zip file with maximum compression option, some ebook reader will fail to open it. It's because of the mimetype file in the root directry shouldn't be compressed, this file should be simply saved into the generated file. So you can compress the direcory in this way:

$ zip -X -0 book.epub mimetype
$ zip -X -9 -r book.epub * -x mimetype

All source file like chapter_1.html and cover.png should be decleared in content.opf with media-type. if you specify the html file type as “application/xhtml+xml”, you may run into some format issues like unclosed tag, because xhtml is a strict file format. to solve this, you can specify html file type as "text/html", so that generated epub file could be rendered correctly in most of the ebook readers. toc.ncx is a optional file used to specify the table of content of the book, so that you can see the index of the book in ebook readers.

That's it, generating an Epub ebook is much easier than a Mobi ebook. I have a kindle(paperwhite), it works. Yes, it just works, but it's not a quite good book reader to me. It's slow and with blank-to-black flash every time I turn a page which contains images. but the iBook on iPad is really good. It smooth and elegant. The only one defect is I can't sync my books in iBook between iPad and Mac automaticly, if you want to sync your books, you have to use the buggy iTunes. However, overlook this issue, iBook on iPad is still a good reader to me. So, throw away your kindle, let's read on ipad.

That's all for this week, have a nice day.

[Updated 2015-3-1:]

The only notable e-reader lacking support for the EPUB format is the Amazon Kindle. http://www.wikiwand.com/en/Comparison_of_e-book_formats#/EPUB


这两天打算重写 Douban-FM-Express , 因为看到以前写的代码觉得惨不忍睹。想重新做一下设计, 重构一下代码, 也是对自己的一个锻炼吧。 期间看到以前写的json代理脚本又觉得不爽,于是重新写了一下, 放到 gist 上, 当作工具备份吧。

功能: 实现json代理转发,解决浏览器端的跨域问题。主要用来调试, 而不是生产项目上。本人不对其安全性负责。

Usage:

node app -d <sampleDomain> -p <listenPort>  

eg:

> node app -d dribbble.com -p 4000
# Proxy started on port 4000, API domain is set to: dribbble.com

Source:

Gist 地址:https://gist.github.com/cyrilis/9644051

这样测试的时候调用 目标网站api 的时候将域名替换为 localhost 加 监听端口, 就可以实现 json 调用了,免去跨域问题。当然项目部署的时候要将域名改回来哟。

Have a nice day!


等了很久的 Ghost 博客程序终于对 公众开放了, 此前一直处于封测阶段, 收到邮件后立马下载本地部署了一下, 虽然还有很多规划中的特性没有实现, 但是已经可以一窥其中的风采了。

下图是博客的编辑界面,自适应屏幕宽带的哦。

ghost-preview

可是。。。 说好的挂件呢? 那些漂亮的 widget 哪儿去了?

看来还是得等正式版了。

程序根目录下的config.js 里面可以自定义网站地址、邮件发送配置、数据库系统、还有服务器地址和端口等一些信息, 默认的数据库是 sqlite3。程序还支持自定义主题, 目前只有一个主题可以选择, 可以看源码了解主题的编写规则。

跟wordpress相比, Ghost的优势在于简洁,轻量,完全专注于博客这一个点。 wordpress太过强大, 都可以用来当作CMS系统了。

Ghost的前景还是很好的, 虽然目前来说还有许多 feature 尚未实现,但已经奠定好了一个不错的基础, 当然, 我现在还是不会选择用它来当自己的博客系统,我还是自己写一个nodejs版的吧。