├── package.json ├── README.md ├── LICENSE └── index.js /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gitbook-plugin-favicon-custom", 3 | "version": "1.0.0", 4 | "description": "This is GitBook plugin for custom favicon", 5 | "engines": { 6 | "gitbook": ">0.0.1" 7 | }, 8 | "gitbook": { 9 | "properties": { 10 | "favicon": { 11 | "type": "string", 12 | "default": "./favicon.ico", 13 | "description": "path to favicon" 14 | }, 15 | "appleTouchIconPrecomposed152": { 16 | "type": "string", 17 | "default": "./favicon.ico", 18 | "description": "path to apple-touch-icon-precomposed-152" 19 | } 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gitbook-plugin-favicon-custom 2 | 3 | 将自己的图标添加到gitbook主题。 4 | favicon.ico和apple-touch-icon-precomposed-152.png 5 | 6 | 插件删除位于`"_book/gitbook/images/favicon.ico"`的gitbook favicon,用自己的favicon代替。apple-touch-icon-precomposed-152.png同理 7 | 8 | ## Install via gitbook 9 | 10 | ### In book.json 11 | 12 | * 添加 `plugin-favicon-custom` 到 `plugins` 数组中 13 | * 在`pluginsConfig`中配置`favicon`的路径 14 | 15 | #### book.json 16 | ```json 17 | { 18 | "plugins" : ["favicon-custom"], 19 | "pluginsConfig" : { 20 | "favicon": "path/favicon.ico", 21 | "appleTouchIconPrecomposed152": "path/logo.png" 22 | } 23 | } 24 | ``` 25 | 26 | ### using gitbook-cli 27 | 28 | ```bash 29 | gitbook install 30 | ``` -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Daniel Tolbert 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | 4 | 5 | module.exports = { 6 | // Map of hooks 7 | hooks: { 8 | 9 | "finish": function () { 10 | var pathFile = this.options.pluginsConfig && this.options.pluginsConfig.favicon; 11 | var favicon = path.join(process.cwd(), pathFile); 12 | var gitbookFaviconPath = path.join(process.cwd(), '_book', 'gitbook', 'images', 'favicon.ico'); 13 | if (pathFile && fs.existsSync(pathFile) && fs.existsSync(gitbookFaviconPath)) { 14 | fs.unlinkSync(gitbookFaviconPath); 15 | fs.createReadStream(favicon).pipe(fs.createWriteStream(gitbookFaviconPath)); 16 | } 17 | 18 | var pathFile = this.options.pluginsConfig && this.options.pluginsConfig.appleTouchIconPrecomposed152; 19 | var appleTouchIconPrecomposed152 = path.join(process.cwd(), pathFile); 20 | var gitbookAppleTouchPath = path.join(process.cwd(), '_book', 'gitbook', 'images', 'apple-touch-icon-precomposed-152.png'); 21 | if (pathFile && fs.existsSync(pathFile) && fs.existsSync(gitbookAppleTouchPath)) { 22 | fs.unlinkSync(gitbookAppleTouchPath); 23 | fs.createReadStream(appleTouchIconPrecomposed152).pipe(fs.createWriteStream(gitbookAppleTouchPath)); 24 | } 25 | } 26 | }, 27 | 28 | // Map of new blocks 29 | blocks: {}, 30 | 31 | // Map of new filters 32 | filters: {} 33 | }; --------------------------------------------------------------------------------