├── package.json ├── README.md ├── LICENSE └── index.js /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gitbook-plugin-custom-favicon-new", 3 | "version": "1.0.0", 4 | "description": "自定义gitbook图标", 5 | "author": "7iang", 6 | "engines": { 7 | "gitbook": "*" 8 | }, 9 | "gitbook": { 10 | "properties": { 11 | "myConfigKey": { 12 | "type": "string", 13 | "default": "default", 14 | "description": "config" 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gitbook-custom-favicon-new 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 | 9 | ## Install via gitbook 10 | 11 | ### In book.json 12 | 13 | * 添加 `custom-favicon-new` 到 `plugins` 数组中 14 | * 在`pluginsConfig`中配置`favicon`的路径 15 | 16 | #### book.json 17 | ```json 18 | { 19 | "plugins" : ["custom-favicon-new"], 20 | "pluginsConfig" : { 21 | "favicon": "path/favicon.ico", 22 | "appleTouchIconPrecomposed152": "path/logo.png" 23 | } 24 | } 25 | ``` 26 | 27 | ### using gitbook-cli 28 | 29 | ```bash 30 | gitbook install 31 | ``` 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /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. 22 | -------------------------------------------------------------------------------- /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 | }; 34 | --------------------------------------------------------------------------------