Coder Social home page Coder Social logo

gitbook-summary's Introduction

Gitbook Summary

npm version Build Status Dependencies Status Coverage Status

A command line tool to generate a SUMMARY.MD from a folder。Demo 中文文档

EBooks

More Gitbooks : https://www.gitbook.com/@imfly

Features

  • Generate SUMMARY.md by using a CLI with some options
  • Setting with book.json
  • Link README.md to the parent directory
  • Only get '.md' files
  • Order by alphabet or numbers
  • ...

CoC (Convention over Configuration)

Source directory:

sources
├── 1-FirstChapter   // The first chapter,format: {orderNumber or alphabet}-{chapterName}.md
├────── 1-FirstDocument.md
├────── 5-SecondDocument.md  // concentrating solely on the order, not the numbers.
├── 3-SecondChapter                     // Focus only on the order, not the numbers.
├────── 1-FirstDocumentOfSecondChapter.md
├────── 2-SecondDocumentOfSecondChapter.md  
├── 7-ThirdChapter
├── FourthChapter  // May have no order
├── README.md // In addition to readme.md, not to put other markdown documents
└── book.json     // Set up the book

Install

npm install -g gitbook-summary

Using

1> Generate a SUMMARY.md Simply

$ cd /path/to/your/book/
$ book sm

or, For example:

$ book sm -r ../sailsjs-docs-gitbook/en -i 0home -u 'myApp' -c 'concepts, reference, userguides' -n "Sails.js 官方文档(中英合辑)"

To see the command line options:

$ book sm --help

  Usage: summary|sm [options]

  Generate a `SUMMARY.md` from a folder

  Options:

    -h, --help                    output usage information
    -r, --root [string]           root folder, default is `.`
    -t, --title [string]          book title, default is `Your Book Title`.
    -c, --catalog [list]          catalog folders included book files, default is `all`.
    -i, --ignores [list]          ignore folders that be excluded, default is `[]`.
    -u, --unchanged [list]        unchanged catalog like `request.js`, default is `[]`.
    -o, --outputfile [string]     output file, defaut is `./SUMMARY.md`
    -s, --sortedBy [string]       sorted by sortedBy, for example: `num-`, defaut is sorted by characters
    -d, --disableTitleFormatting  don't convert filename/folder name to start case (for example: `JavaScript` to `Java Script`), default is `false`

Notes

  • The article title is taken from title property in the articles front-matter. If this property is not available, the articles filename will be used as title for the summary.
  • The option -s or --sortedBy can not be given - as argument, because commander.js will parse it an option. But you can set it in book.json as follows.
  • set up the sortedBy and if there are any summaries missing the order, look at the example below and follow,
    for example, you have summaries like this 01-elementry-school, 02-middle-school, 03-university, ...
    you realized high school was missing, then You can make correct order in the following way
    eg. 01-elementry-school, 02-middle-school, 02a-high-school, 03-university, ...
    not 01-elementry-school, 02-middle-school, 03-high-school, 04-university, ...

2> Create a book.json in the book`s root folder

for example:

// test/books/config-json/book.json
{
    "title": "json-config-name",
    "outputfile": "test.md",
    "catalog": "all",  // or [chapter1,chapter2, ...]
    "ignores": [],  //Default: '.*', '_book'...
    "unchanged": [], // for example: ['myApp'] -> `myApp` not `My App`
    "sortedBy": "-",
    "disableTitleFormatting": true // default: false
}

then, you can do:

$ book sm

You will get a test.md file:

test.md.jpg

3> Get a markdown artical from a html file or a remote url

$ book md -l "http://book.btcnodejs.com/index.html" -s "div.className"

You will get the 'index.html' and 'index.md'.

4> Get convert between zh and zh-tw, zh-hk, or zh-sg

$ book cv -f ./test/language/test.md -l zh-tw -t "./test/language/test2.md"

Development

npm install
npm link

Test

npm test

Todo

  • Convert articals between Simplified and Traditional Chinese.
  • Generate eBooks(html, pdf, etc) by extending gitbook;

Contribute

We love pull requests! You can fork it and commit a pr

License

The MIT License

gitbook-summary's People

Contributors

abeggchr avatar andineck avatar andrii-bodnar avatar garyng avatar imfly avatar perfectacle2 avatar shadowbq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gitbook-summary's Issues

Feature request --「 ignore title 」

Feature request --「 ignore title 」

Cool tool ! "gitbook-summary" helps me a lot. Thanks !

book.json file is useful, help me shorten my command line.

Recently, I want to remove the 'title' from my blog's navigation (note.tianyongwei.com).
but likely gitbook-summary can't do it.

I try modify the source code ,and found this:

var root,
      title, // todo: don`t use `name`?
      outputFile,
      catalog,
      ignores,
      unchanged,
...

is the feature (dont use name`) a todo feature?

在book.jason中排除无关文件,运行book sm 提示失败

Hi:

感谢你的共享的插件。我在部署的过程中,因为默认book sm会把node module 和_book的都收录到目录里面,想要把这两个目录排除,因此我在book.json中增加了如下代码:

{
    "bookname": "json-config-name",
    "outputfile": "test.md",
    "catalog": "all",  // 如 [chapter1,chapter2, ...]
    "ignores": [_drafts,_books],
    "unchanged": [] // 如: ['myApp'] -> `myApp` not `My App`
}

但是再次运行book sm的时候,提示以下错误:

module.js:593
    throw err;
    ^

SyntaxError: /Users/aban/Documents/半撇私塾课程/BPteach-EDU-Chanllenger/book.json: Unexpected token / in JSON at position 173
    at JSON.parse (<anonymous>)
    at Object.Module._extensions..json (module.js:590:27)
    at Module.load (module.js:490:32)
    at tryModuleLoad (module.js:449:12)
    at Function.Module._load (module.js:441:3)
    at Module.require (module.js:500:17)
    at require (internal/module.js:20:19)
    at BookConfig (/Users/aban/.nvm/versions/node/v7.1.0/lib/node_modules/gitbook-summary/lib/bookJson.js:10:18)
    at init (/Users/aban/.nvm/versions/node/v7.1.0/lib/node_modules/gitbook-summary/lib/summary/index.js:29:22)
    at Array.init (/Users/aban/.nvm/versions/node/v7.1.0/lib/node_modules/gitbook-summary/lib/summary/index.js:51:13)

相关的配置信息:

  • Mac
  • Node版本:7.1.0
  • npm版本:3.10.9
  • Gitbook CLI 版本: 2.3.2

front-matters在README.md中不起作用

如题,其他情况工作都良好,在README中使用front-matters时不起作用。但是,当front-matters中title的值为README时,front-matters就会起作用,生成出来的SUMMARY中会将章节名设置为README.

---
title: README
author: xxx
date: 2020-11-15 06:01:25
last_author: xxx
last_edit_time: 2020-11-21 14:07:08
---

Gulp Task

Hi,
Can you please help me with building a gulp task for the automization of the summary file?

有2个优化建议,看能否实现,谢谢。

1.目前的SUMMARY目录是根据文件夹及文件名生成的,有时一个MD文档写得比较长,于是分了很多段落,能否在目录中显示MD文档的大纲级别。
就是:如果有2个文件,那么目前生成的目录就是2个文件名形成的目录。
能否改进,通过加参数控制(控制是否显示段落标题),把文件里面的段落标题,也显示在SUMMARY目录中。

2.目前根目录的README.md没有添加进目录,gitbook启动后会自带一个叫introduction的标题对应README.md文件。能否加配置可以自定义这个introduction名字,让这个readme.md在左边显示为自定义的标题。

SUMMARY.md does not skip hidden files

I have a template file .runbook-template.md which is being shown in the summary.md after being built. However, in the index.js file for summary, I see:

// Ignore hidden files, for example `.git`
if (/^[\.]|'_book'|'node_modules'/.test(key)) {
    ignores.push(key);
}

I have also tried to use the ignores in book.json as well,

"ignores": ["runbook-template"],

Any ideas on how to have these files hidden?

Ignores should support wildcards or regular expressions

The documentation suggests, that you can use wildcards in the "ignores" configuration. As a matter of fact, the values in this array are compared on a 1:1 basis. No regex included.

Feature request: Ignores configuration should support wildcards or regular expressions.

please update npm module

If I intstall with npm repository, summary didn't use file property in front-matter,
please update!!

sortedBy 不能正常工作

01是文件,02是目录,book sm -s '_'

02_test1
   README.md
01_test2.md

生成的summary:

- [test1](02_test1/README.md)
* [test2](01_test2.md)

排序没有起作用

标题

当前解析的标题名字,都是文件名吧,可不可以解析一下文件,取第一行,作为标题呢 ?

have you any plan support for non-ascii title

I live in non-ascii lang country
so my post title in front-matter is non-ascii
but book sm isn't support non-ascii title...
result is

[](programming/functional-paradigm-example.md)

it has no title...

简化命令

现在来看,book sm g 感觉太累赘了,g完全没有必要,因为对一个目录来说,这里没有其他操作要做了,计划将其删除掉。

意外生成多余的Pages目录

如图,这个Pages不知是从哪来的,我本地还有你的程序里都没这个,很奇怪
刚开始没装Gitbook时是没有这个问题的

这个是book.json

book sm orders differently if .git folder is not present

I have book.json with "sortedBy": "_", and several folders setup like:

2_Top
└── README.md
3_Mid
└── README.md
4_Mid2
└── README.md
5_Mid3
└── README.md
9_Last
├── 2_Top
│   └── README.md
├── 3_Mid
│   └── README.md
├── 9_Last
│   └── 3_Mid
│       └── README.md
└── README.md

My production deployment downloaded github's master.zip download link (e.g. like this link, but for my private repo), which doesn't have the .git folder in it, and ran book sm before starting gitbook serve. I noticed the ordering was not being obeyed the same as when the .git folder is present...any ideas why?

Here is an example SUMMARY.md output based off the above directory structure. The problem only presents itself when nesting data in the last sorted directory...

SUMMARY.md before git init of a repo:

- [Top](2_Top/README.md)
- [Mid 2](4_Mid2/README.md)
- [Mid 3](5_Mid3/README.md)
- [Last](9_Last/README.md)
  - [Top](9_Last/2_Top/README.md)
  - [Mid](9_Last/3_Mid/README.md)
  - Last
    - [Mid](9_Last/9_Last/3_Mid/README.md)
- [Mid](3_Mid/README.md)

after git init and add/commiting all the files...book sm results in:

- [Top](2_Top/README.md)
- [Mid](3_Mid/README.md)
- [Mid 2](4_Mid2/README.md)
- [Mid 3](5_Mid3/README.md)
- [Last](9_Last/README.md)
  - [Top](9_Last/2_Top/README.md)
  - [Mid](9_Last/3_Mid/README.md)
  - Last
    - [Mid](9_Last/9_Last/3_Mid/README.md)

I've worked around the issue by swithcing to a git clone --depth 1 so I have .git data...but I thought it was an odd bug worth reporting still.

优化排序方法

默认是按照字符进行排序的,如果给了参数sortedBy,那么用户可以选择使用NUM-aZ-等前缀设定排序方法。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.