{"id":21967056,"url":"https://github.com/barretlee/kindlebookmaker","last_synced_at":"2025-04-05T17:02:56.588Z","repository":{"id":43951758,"uuid":"59134514","full_name":"barretlee/kindleBookMaker","owner":"barretlee","description":"Kindle Book Maker with KindleGen, Make Book from RSS/single URL/directory and so on.","archived":false,"fork":false,"pushed_at":"2022-02-13T09:26:00.000Z","size":23936,"stargazers_count":408,"open_issues_count":1,"forks_count":60,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-03-29T16:05:51.398Z","etag":null,"topics":["book-generator","kindle","kindlegen","rss","spider"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/barretlee.png","metadata":{"files":{"readme":"README-zh.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-18T16:50:19.000Z","updated_at":"2025-03-23T03:41:30.000Z","dependencies_parsed_at":"2022-09-24T20:00:28.349Z","dependency_job_id":null,"html_url":"https://github.com/barretlee/kindleBookMaker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barretlee%2FkindleBookMaker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barretlee%2FkindleBookMaker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barretlee%2FkindleBookMaker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barretlee%2FkindleBookMaker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/barretlee","download_url":"https://codeload.github.com/barretlee/kindleBookMaker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247369950,"owners_count":20927928,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["book-generator","kindle","kindlegen","rss","spider"],"created_at":"2024-11-29T13:20:15.974Z","updated_at":"2025-04-05T17:02:56.557Z","avatar_url":"https://github.com/barretlee.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Kindle 电子书生成工具\n---\n\n[Document in English](./README.md)\n\n\u003e 花了两个晚上把 OPF 和 epub 格式整明白了，准备把订阅的 RSS 内容抓取下来做成电子书推到 kindle 中阅读。后续也会把自己博客整成电子书，提供给习惯 kindle 阅读的朋友。研究这些东西目的还是想回到比较纯粹的阅读设备上，毕竟手机屏小干扰多，看久了眼睛也有点不舒服。\n\n本项目旨在写一个 Kindle 电子书的构建工具，从互联网上抓取数据，合并整合都生成一本小巧的 `.mobi` 电子书。而使用这个工具，你只需要编辑下配置文件，或者直接运行命令行工具。\n\n### 项目结构\n\n数据的这么几个来源：\n\n- 通过抓取单个 uri 的内容，配合 title 和 content DOM 选择器，获取文章的标题和内容\n- 通过抓取 RSS 源获取内容\n- 使用本地数据，比如 hexo build 目录下的 html 文件\n\n下图为该工具的一个结构图： \n\n![Kindle Book Maker](http://img.alicdn.com/tfs/TB1B_rJJVXXXXcvXXXXXXXXXXXX-809-584.png)\n\n抓到数据后，工具会帮助分析过滤数据，尤其对 hexo 生成的文件做了特殊的处理，后续也会添加几个扩展功能（比如之间转换 markdown 文件），如果 html 中包含了远程内容——CSS、图片等——程序会全部抓取过来。\n\n最后，使用官方提供了 [kindleGen](http://www.amazon.com/gp/feature.html?docId=1000765211) 工具构建，我已经把这个文件放到了 [/bin/kindlegen](/bin/kindlegen) 下，大约 28M，有点大。\n\n### 使用方法\n\n首先，Unix/Linux 系统添加下执行权限：\n\n```bash\nchmod +x bin/**/kindlegen\n```\n\n可以下载代码之后，尝试运行下已经提供了一个 DEMO（封面图片就懒得换了，是我自己的头像）：\n\n```bash\ngit clone https://github.com/barretlee/kindleBookMaker.git;\ncd kindleBookMaker;\nnpm install;\nnode index;\nopen build/*.mobi;\n```\n\n提供了很多方法可以调用，不过都通过命令行的方式简化了：\n\n- 从 RSS 源构建：\n```bash\nnode index --rss http://barretlee.com/rss2.xml\n# node index -r http://barretlee.com/rss2.xml\n```\n- 从单个 URI 构建，`-u URL titleQuery ContentQuery FilterRegExp`， 其中 titleQuery 为文章标题的 css query，ContentQuery 为文章主要内容的 css query，FilterRegExp 为正则过滤：\n```bash\nnode index --uri \\\n    http://www.barretlee.com/blog/2016/04/28/mini-query/ \\\n    .post-title \\\n    .post-content \\\n    /\u003cdiv class=\"shit-spider\"[\\s\\S]+?\u003c\\/div\u003e/\n```\n- 从本地构建\n```bash\nnode index --dirctory ./src/demo/\n# node index -d ./src/demo/\n```\n\n还有另外三个参数：\n\n- `--verbose`, `-v`, 查看 kindle 构建的详细细节，因为编译也可能出错\n- `--help`, `-h`, 帮助说明\n- `-push2kindle`, `-p`, 将构建的 `.mobi` 文件推送你设定的 kindle 账户上\n\n### 配置\n\n```javascript\nvar moment = require('moment');\n\nmodule.exports = {\n  // entry: './src/KF8-Demo',\n  entry: {\n    base: './src/KF8-Demo',\n    list: []\n  },\n  bookInfo: {\n    title: \"Barret Lee's Personal Website\",\n    lang: \"zh\",\n    creator: \"Barret Lee\",\n    copyright: \"Barret Lee\",\n    publisher: \"\",\n    coverImage: 'coverImage.png'\n  },\n  /*option*/\n  output: {\n    base: './build',\n    format: '[name]-' + moment().format('YYYYMMDD')\n  },\n  /*option for uri*/\n  singlePage: {\n    title: 'div.title',\n    description: 'div.content',\n    reg: function(data) {\n      return data.replace(/\u003cdiv class=\"shit-spider\"[\\s\\S]+?\u003c\\/div\u003e/, '');\n    }\n  },\n  /*option*/\n  push2kindle: {\n    email: 'barret.china@gmail.com',\n    password: 'your-email-password',\n    kindle: 'barretlee.com@kindle.cn'\n  }\n};\n```\n\n- `entry`, 可以为一个 String 或者 Object\n  - `base`, 入口地址，下载的文件都会放在这里\n  - `list`, list 参数，会影响最后生成的电子书的文章排序\n- `bookInfo`, 注意设置 `coverImage`，它为书籍封面图片\n- `ouput`, 可选参数, 默认值为 `./build` 和 `[name]`\n- `singlePage`, 可选参数, 从 URI 爬取数据时会用到\n- `push2kindle`, 可选参数, `kindle` 参数为你设备对应的推送邮箱, 可以在 [这里](https://www.amazon.cn/mn/dcw/myx.html/ref=kinw_myk_redirect#/home/settings/payment) 设置\n\n\n### Todo\n\n- [ ] 直接从 Markdown 文件生成内容\n- [ ] 找到 kindle 帐号偶尔不接受我推送 `.mobi` 文件的原因，意思就是有的时候推送未成功\n\n### 参考文献\n\n- http://www.idpf.org/epub/30/spec/epub30-publications.html#sec-item-property-values\n- http://www.idpf.org/epub/20/spec/OPF_2.0.1_draft.htm\n- http://www.aliciaramirez.com/2014/05/how-to-make-a-kindle-ebook-from-scratch/\n\n### 贡献者\n\n- [小胡子哥(Barret Lee)](https://github.com/barretlee)\n- [hillwah](https://github.com/hillwah)\n\n### LICENSE\n\nThe MIT License (MIT)\n\nCopyright (c) 2016 小胡子哥","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarretlee%2Fkindlebookmaker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarretlee%2Fkindlebookmaker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarretlee%2Fkindlebookmaker/lists"}