Browse Source

Update for 2.x.x

Samy Pessé 9 years ago
parent
commit
5fd0c4f1ae
2 changed files with 51 additions and 101 deletions
  1. 4 62
      README.md
  2. 47 39
      index.js

+ 4 - 62
README.md

@@ -1,21 +1,19 @@
 GitBook Sample Plugin
 ==============
 
-This is a sample plugin for GitBook.
-
-Install it using: ```$ npm install gitbook-plugin```
+This is a model for GitBook plugins.
 
 ## How GitBook plugin works?
 
-A plugin for GitBook is a node package that can be published on [NPM](http://www.npmjs.org).
+A plugin for GitBook is a node package that can be published on [NPM](http://www.npmjs.org). It has to follow the name convention: `gitbook-plugin-*name*`.
 
 ### package.json
 
 #### name
 
-The package name should begin with ```gitbook-plugin-```. And if your plugin is a theme, it should begin with ```gitbook-theme-```.
+The package name should begin with ```gitbook-plugin-```.
 
-Examples: `gitbook-plugin-mixpanel`, `gitbook-plugin-googleanalytics`, `gitbook-theme-dark`
+Examples: `gitbook-plugin-mixpanel`, `gitbook-plugin-googleanalytics`.
 
 #### engine
 
@@ -39,60 +37,4 @@ For example if you want your plugin to supports only GitBook version supperior t
 
 The plugin entry point should return an object with some metadata.
 
-#### "book"
-
-Type: `Object`
-Default value: `{}`
-
-#### "book.assets"
-
-Type: `String`
-Default value: `null`
-
-Path to the assets folder to copy
-
-#### "book.js"
-
-Type: `Array`
-Default value: `[]`
-
-List of javascript file to add to the html pages (relative to the assets folder).
-
-#### "book.css"
-
-Type: `Array`
-Default value: `[]`
-
-List of css file to add to the html pages (relative to the assets folder).
-
-#### "book.html"
-
-Type: `Object`
-Default value: `{}`
-
-Map of position -> code, html snippets to add to each page. The code could be a function.
-
-#### "book.templates"
-
-Type: `Object`
-Default value: `{}`
-
-Templates to override default templates, only use this option if you want to change entirely how the book is rendered.
-
-This object is a map: "name" -> "file", with names:
-
-* "site": page for a file from the `site` format
-* "page": page for the `page` format
-
-#### "hooks"
-
-Type: `Object`
-Default value: `{}`
-
-Map of "name" -> Function that needs to be called during build process. With names:
-
-* "init": just after initialization, before generation
-* "finish": after generation and everything is finished
-
-Each hook can return a promise.
 

+ 47 - 39
index.js

@@ -1,5 +1,6 @@
 module.exports = {
-    book: {
+    // Extend website resources and html
+    website: {
         assets: "./book",
         js: [
             "test.js"
@@ -22,6 +23,51 @@ module.exports = {
             "body:end": "<!-- body:end -->"
         }
     },
+
+    // Extend ebook resources and html
+    website: {
+        assets: "./book",
+        js: [
+            "test.js"
+        ],
+        css: [
+            "test.css"
+        ],
+        html: {
+            "html:start": function() {
+                return "<!-- Start book "+this.options.title+" -->"
+            },
+            "html:end": function() {
+                return "<!-- End of book "+this.options.title+" -->"
+            },
+
+            "head:start": "<!-- head:start -->",
+            "head:end": "<!-- head:end -->",
+
+            "body:start": "<!-- body:start -->",
+            "body:end": "<!-- body:end -->"
+        }
+    },
+
+    // Extend templating blocks
+    blocks: {
+        // Author will be able to write "{% myTag %}World{% endMyTag %}"
+        myTag: {
+            process: function(blk) {
+                return "Hello "+blk.body;
+            }
+        }
+    },
+
+    // Extend templating filters
+    filters: {
+        // Author will be able to write "{{ 'test'|myFilter }}"
+        myFilter: function(s) {
+            return "Hello "+s;
+        }
+    },
+
+    // Hook process during build
     hooks: {
         // For all the hooks, this represent the current generator
 
@@ -33,44 +79,6 @@ module.exports = {
         // This is called after the book generation
         "finish": function() {
             console.log("finish!");
-        },
-
-        // The following hooks are called for each page of the book
-        // and can be used to change page content (html, data or markdown)
-
-
-        // Before parsing markdown
-        "page:before": function(page) {
-            // page.path is the path to the file
-            // page.content is a string with the file markdown content
-
-            // Example:
-            //page.content = "# Title\n" + page.content;
-
-            return page;
-        },
-
-        // Before html generation
-        "page": function(page) {
-            // page.path is the path to the file
-            // page.sections is a list of parsed sections
-
-            // Example:
-            //page.sections.unshift({type: "normal", content: "<h1>Title</h1>"})
-
-            return page;
-        },
-
-        // After html generation
-        "page:after": function(page) {
-            // page.path is the path to the file
-            // page.content is a string with the html output
-
-            // Example:
-            //page.content = "<h1>Title</h1>\n" + page.content;
-            // -> This title will be added before the html tag so not visible in the browser
-
-            return page;
         }
     }
 };