最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】gitbook中book.json中能否把公共部分提取出来

gitbook crifan 2910浏览 0评论

现在已有gitbook的环境和配置:

而且有多个gitbook

其中的book.json中的很多配置都是相同的

而此处更新了其中一个,比如换了hint的插件:

【记录】gitbook换用更好看的hint callout提示

导致其他的gitbook的book.json都要更新,很是麻烦和不智能。

现在在想要:

看看此处的book.json的公共部分,比如

plugins

可以提取出去

或者说,json文件是否可以包含include其他的json

总之希望实现把公共部分提取出去的效果就好。

json include other json

php – how to include one JSON into another JSON? – Stack Overflow

好像没有直接json中直接内部include other json的

实在不行,考虑去:

把共有的,共同部分的book.json弄出一个book_template.json

然后保存共有部分,

每个gitbook只填写自己的部分

然后用其他工具处理合并成最终的book.json

然后再去执行gitook的其他命令

此过程,或许可以基于现有的makefile中:

调用其他工具,最好是js代码,去实现

xml – Include a json file in an another json file only with json – Stack Overflow

How to set reference of one JSON object to another in JSON file – Stack Overflow

或许可以:

makefile中,执行python脚本,实现上面的步骤?

makefile中,执行js脚本?

【已解决】Makefile中运行Python脚本文件

至此,已经基本上清楚处理过程了:

  • 提取出book_common.json

  • 整理出单独的gitbook的自己的book_current.json

  • 写python脚本merge_book_json.py处理生成book.json

  • Makefile中调用python脚本

剩下的就是:

抽空把book.json的公共部分的提取,和之前要做的,gitbook的makefile的公共部分的提取,放在一起,一次性搞定就好

而公共部分的Makefile的提取,则大概是:

  • 提取出公共的Makefile,放在所有的gitbook的父目录

  • 每个gitbook目录中的Makefile写自己的部分,调用公共的Makefile

不过,此处先去完成book.json的提取和合并处理的部分。

先去弄出来:

/Users/crifan/GitBook/Library/Import/book_common.json

<code>{
  "title": "Gitbook的书名",
  "description": "gitbook书的描述",
  "author": "Crifan Li &lt;[email protected]&gt;",
  "language": "zh-hans",
  "gitbook": "3.2.3",
  "root": "./src",
  "links": {
    "sidebar": {
      "主页": "https://www.crifan.com"
    }
  },
  "plugins": [
    "theme-comscore",
    "-lunr",
    "-search",
    "search-plus",
    "disqus",
    "-highlight",
    "prism",
    "prism-themes",
    "github-buttons",
    "splitter",
    "-sharing",
    "sharing-plus",
    "tbfed-pagefooter",
    "expandable-chapters-small",
    "ga",
    "donate",
    "sitemap-general",
    "copy-code-button",
    "-alerts",
    "-bootstrap-callout",
    "callouts",
    "toolbar-button"
  ],
  "pluginsConfig": {
    "callouts": {
      "showTypeInHeader": false
        },
    "theme-default": {
        "showLevel": true
    },
    "disqus": {
      "shortName": "crifan"
    },
    "prism": {
      "css": [
        "prism-themes/themes/prism-atom-dark.css"
      ]
    },
    "github-buttons": {
      "buttons": [
        {
          "user": "crifan",
          "repo": "gitbook_name",
          "type": "star",
          "count": true,
          "size": "small"
        }, {
          "user": "crifan",
          "type": "follow",
          "width": "120",
          "count": false,
          "size": "small"
        }
      ]
    },
    "sharing": {
      "douban": false,
      "facebook": true,
      "google": false,
      "hatenaBookmark": false,
      "instapaper": false,
      "line": false,
      "linkedin": false,
      "messenger": false,
      "pocket": false,
      "qq": true,
      "qzone": false,
      "stumbleupon": false,
      "twitter": true,
      "viber": false,
      "vk": false,
      "weibo": true,
      "whatsapp": false,
      "all": [
        "douban",
        "facebook",
        "google",
        "instapaper",
        "line",
        "linkedin",
        "messenger",
        "pocket",
        "qq",
        "qzone",
        "stumbleupon",
        "twitter",
        "viber",
        "vk",
        "weibo",
        "whatsapp"
      ]
    },
    "tbfed-pagefooter": {
      "copyright": "crifan.com,使用&lt;a href='https://creativecommons.org/licenses/by-sa/4.0/deed.zh'&gt;知识署名-相同方式共享4.0协议&lt;/a&gt;发布",
      "modify_label": "该文件修订时间:",
      "modify_format": "YYYY-MM-DD HH:mm:ss"
    },
    "ga": {
      "token": "UA-28297199-1"
    },
    "donate": {
      "wechat": "https://www.crifan.com/files/res/crifan_com/crifan_wechat_pay.jpg",
      "alipay": "https://www.crifan.com/files/res/crifan_com/crifan_alipay_pay.jpg",
      "title": "",
      "button": "打赏",
      "alipayText": "支付宝打赏给Crifan",
      "wechatText": "微信打赏给Crifan"
    },
    "sitemap-general": {
      "prefix": "https://book.crifan.com/gitbook/gitbook_name/website/"
    },
    "toolbar-button": {
      "icon": "fa-file-pdf-o",
      "label": "下载PDF",
      "url": "http://book.crifan.com/books/gitbook_name/pdf/gitbook_name.pdf"
    }
  }
}
</code>

以及:

/Users/crifan/GitBook/Library/Import/youdao_note_summary/book_current.json

<code>{
  "title": "有道云笔记和云协作使用总结",
  "description": "总结之前使用过有道云笔记和有道云协作的心得供参考",
  "pluginsConfig": {
    "github-buttons": {
      "buttons": [
        {
          "repo": "youdao_note_summary"
        }
      ]
    },
    "sitemap-general": {
      "prefix": "https://book.crifan.com/gitbook/youdao_note_summary/website/"
    },
    "toolbar-button": {
      "url": "http://book.crifan.com/books/youdao_note_summary/pdf/youdao_note_summary.pdf"
    }
  }
}
</code>

希望写Python可以把后者book_current.json的内容,合并到book_common.json中,生成完整的:

book.json:

然后去:

【记录】用VSCode开发和调试Python

【总结】

虽然原理上用OrderedDict,实现了保持之前的json的字段顺序,但是由于两个json的dict合并后,字段顺序不是所希望的,所以最后放弃,还是用之前的顺序了。

最后,用:

<code>#!/usr/bin/python
# -*- coding: utf-8 -*-

CurrentGitbookName = "youdao_note_summary"
BookJsonTemplateFilename = "book_common.json"
BookJsonCurrentFilename = "book_current.json"
BookJsonOutputFilename = "book.json"
# BookJsonTemplateFilename = "a.json"
# BookJsonCurrentFilename = "b.json"
# BookJsonOutputFilename = "c.json"

import os
import json
from pprint import pprint
import sys
import copy
import codecs
# from collections import OrderedDict

################################################################################
# Internal Function
################################################################################


def recursiveMergeDict(aDict, bDict):
    """
    Recursively merge dict a to b, return merged dict b
    Note: Sub dict and sub list's won't be overwritten but also updated/merged

    example:
(1) input and output example:
input:
{
  "keyStr": "strValueA",
  "keyInt": 1,
  "keyBool": true,
  "keyList": [
    {
      "index0Item1": "index0Item1",
      "index0Item2": "index0Item2"
    },
    {
      "index1Item1": "index1Item1"
    },
    {
      "index2Item1": "index2Item1"
    }
  ]
}

and

{
  "keyStr": "strValueB",
  "keyInt": 2,
  "keyList": [
    {
      "index0Item1": "index0Item1_b"
    },
    {
      "index1Item1": "index1Item1_b"
    }
  ]
}

output:

{
  "keyStr": "strValueB", 
  "keyBool": true, 
  "keyInt": 2,
  "keyList": [
    {
      "index0Item1": "index0Item1_b", 
      "index0Item2": "index0Item2"
    }, 
    {
      "index1Item1": "index1Item1_b"
    }, 
    {
      "index2Item1": "index2Item1"
    }
  ]
}

(2) code usage example:
import copy
cDict = recursiveMergeDict(aDict, copy.deepcopy(bDict))

Note:
bDict should use deepcopy, otherwise will be altered after call this function !!!

    """
    aDictItems = None
    if (sys.version_info[0] == 2): # is python 2
      aDictItems = aDict.iteritems()
    else: # is python 3
      aDictItems = aDict.items()

    for aKey, aValue in aDictItems:
      # print("------ [%s]=%s" % (aKey, aValue))
      if aKey not in bDict:
        bDict[aKey] = aValue
      else:
        bValue = bDict[aKey]
        # print("aValue=%s" % aValue)
        # print("bValue=%s" % bValue)
        if isinstance(aValue, dict):
          recursiveMergeDict(aValue, bValue)
        elif isinstance(aValue, list):
          aValueListLen = len(aValue)
          bValueListLen = len(bValue)
          bValueListMaxIdx = bValueListLen - 1
          for aListIdx in range(aValueListLen):
            # print("---[%d]" % aListIdx)
            aListItem = aValue[aListIdx]
            # print("aListItem=%s" % aListItem)
            if aListIdx &lt;= bValueListMaxIdx:
              bListItem = bValue[aListIdx]
              # print("bListItem=%s" % bListItem)
              recursiveMergeDict(aListItem, bListItem)
            else:
              # print("bDict=%s" % bDict)
              # print("aKey=%s" % aKey)
              # print("aListItem=%s" % aListItem)
              bDict[aKey].append(aListItem)

    return bDict


def saveJsonToFile(jsonDict, fullFilename, indent=2, fileEncoding="utf-8"):
  """
    save dict json into file
    for non-ascii string, output encoded string, without \uxxxx
  """
  with codecs.open(fullFilename, 'w', encoding="utf-8") as outputFp:
      json.dump(jsonDict, outputFp, indent=indent, ensure_ascii=False)

################################################################################
# Main Part
################################################################################

templateJson = {}
currentJson = {}

currPath = os.getcwd()
print("currPath=%s" % currPath)

bookJsonTemplateFullPath = os.path.join(currPath, BookJsonTemplateFilename)
print("bookJsonTemplateFullPath=%s" % bookJsonTemplateFullPath)
# /Users/crifan/GitBook/Library/Import/book_common.json
with open(bookJsonTemplateFullPath) as templateJsonFp:
    templateJson = json.load(templateJsonFp, encoding="utf-8")
    # templateJson = json.load(templateJsonFp, encoding="utf-8", object_pairs_hook=OrderedDict)
    # templateJson = OrderedDict(templateJson)
    # print("type(templateJson)=%s" % (type(templateJson))) #type(templateJson)=&lt;class 'collections.OrderedDict'&gt;

bookJsonCurrentFullPath = os.path.join(currPath, CurrentGitbookName, BookJsonCurrentFilename)
print("bookJsonCurrentFullPath=%s" % bookJsonCurrentFullPath)
with open(bookJsonCurrentFullPath) as currentJsonFp:
    currentJson = json.load(currentJsonFp, encoding="utf-8")
    # currentJson = json.load(currentJsonFp, encoding="utf-8", object_pairs_hook=OrderedDict)
    # currentJson = OrderedDict(currentJson)

pprint("/"*80)
pprint(templateJson)
pprint("/"*80)
pprint(currentJson)

pprint("/"*80)
bookJson = recursiveMergeDict(templateJson, copy.deepcopy(currentJson))

pprint("-a"*40)
pprint(templateJson)
pprint("-b"*40)
pprint(currentJson)
pprint("-c"*40)
pprint(bookJson)
# print("type(templateJson)=%s" % (type(templateJson)))
# print("type(currentJson)=%s" % (type(currentJson)))
# print("type(bookJson)=%s" % (type(bookJson)))

bookJsonFullPath = os.path.join(currPath, CurrentGitbookName, BookJsonOutputFilename)
print("bookJsonFullPath=%s" % bookJsonFullPath)
saveJsonToFile(bookJson, bookJsonFullPath)
</code>

输出log:

<code>➜  Import cd /Users/crifan/GitBook/Library/Import ; env "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1" /usr/bin/python /Users/crifan/.vscode/extensions/ms-python.python-2018.5.0/pythonFiles/PythonTools/visualstudio_py_launcher.py /Users/crifan/GitBook/Library/Import 57813 34806ad9-833a-4524-8cd6-18ca4aa74f14 RedirectOutput,RedirectOutput /Users/crifan/GitBook/Library/Import/generateBookJson.py
currPath=/Users/crifan/GitBook/Library/Import
bookJsonTemplateFullPath=/Users/crifan/GitBook/Library/Import/book_common.json
bookJsonCurrentFullPath=/Users/crifan/GitBook/Library/Import/youdao_note_summary/book_current.json
'////////////////////////////////////////////////////////////////////////////////'
{u'author': u'Crifan Li &lt;[email protected]&gt;',
 u'description': u'gitbook\u4e66\u7684\u63cf\u8ff0',
 u'gitbook': u'3.2.3',
 u'language': u'zh-hans',
 u'links': {u'sidebar': {u'\u4e3b\u9875': u'https://www.crifan.com'}},
 u'plugins': [u'theme-comscore',
              u'-lunr',
              u'-search',
              u'search-plus',
              u'disqus',
              u'-highlight',
              u'prism',
              u'prism-themes',
              u'github-buttons',
              u'splitter',
              u'-sharing',
              u'sharing-plus',
              u'tbfed-pagefooter',
              u'expandable-chapters-small',
              u'ga',
              u'donate',
              u'sitemap-general',
              u'copy-code-button',
              u'-alerts',
              u'-bootstrap-callout',
              u'callouts',
              u'toolbar-button'],
 u'pluginsConfig': {u'callouts': {u'showTypeInHeader': False},
                    u'disqus': {u'shortName': u'crifan'},
                    u'donate': {u'alipay': u'https://www.crifan.com/files/res/crifan_com/crifan_alipay_pay.jpg',
                                u'alipayText': u'\u652f\u4ed8\u5b9d\u6253\u8d4f\u7ed9Crifan',
                                u'button': u'\u6253\u8d4f',
                                u'title': u'',
                                u'wechat': u'https://www.crifan.com/files/res/crifan_com/crifan_wechat_pay.jpg',
                                u'wechatText': u'\u5fae\u4fe1\u6253\u8d4f\u7ed9Crifan'},
                    u'ga': {u'token': u'UA-28297199-1'},
                    u'github-buttons': {u'buttons': [{u'count': True,
                                                      u'repo': u'gitbook_name',
                                                      u'size': u'small',
                                                      u'type': u'star',
                                                      u'user': u'crifan'},
                                                     {u'count': False,
                                                      u'size': u'small',
                                                      u'type': u'follow',
                                                      u'user': u'crifan',
                                                      u'width': u'120'}]},
                    u'prism': {u'css': [u'prism-themes/themes/prism-atom-dark.css']},
                    u'sharing': {u'all': [u'douban',
                                          u'facebook',
                                          u'google',
                                          u'instapaper',
                                          u'line',
                                          u'linkedin',
                                          u'messenger',
                                          u'pocket',
                                          u'qq',
                                          u'qzone',
                                          u'stumbleupon',
                                          u'twitter',
                                          u'viber',
                                          u'vk',
                                          u'weibo',
                                          u'whatsapp'],
                                 u'douban': False,
                                 u'facebook': True,
                                 u'google': False,
                                 u'hatenaBookmark': False,
                                 u'instapaper': False,
                                 u'line': False,
                                 u'linkedin': False,
                                 u'messenger': False,
                                 u'pocket': False,
                                 u'qq': True,
                                 u'qzone': False,
                                 u'stumbleupon': False,
                                 u'twitter': True,
                                 u'viber': False,
                                 u'vk': False,
                                 u'weibo': True,
                                 u'whatsapp': False},
                    u'sitemap-general': {u'prefix': u'https://book.crifan.com/gitbook/gitbook_name/website/'},
                    u'tbfed-pagefooter': {u'copyright': u"crifan.com\uff0c\u4f7f\u7528&lt;a href='https://creativecommons.org/licenses/by-sa/4.0/deed.zh'&gt;\u77e5\u8bc6\u7f72\u540d-\u76f8\u540c\u65b9\u5f0f\u5171\u4eab4.0\u534f\u8bae&lt;/a&gt;\u53d1\u5e03",
                                          u'modify_format': u'YYYY-MM-DD HH:mm:ss',
                                          u'modify_label': u'\u8be5\u6587\u4ef6\u4fee\u8ba2\u65f6\u95f4\uff1a'},
                    u'theme-default': {u'showLevel': True},
                    u'toolbar-button': {u'icon': u'fa-file-pdf-o',
                                        u'label': u'\u4e0b\u8f7dPDF',
                                        u'url': u'http://book.crifan.com/books/gitbook_name/pdf/gitbook_name.pdf'}},
 u'root': u'./src',
 u'title': u'Gitbook\u7684\u4e66\u540d'}
'////////////////////////////////////////////////////////////////////////////////'
{u'description': u'\u603b\u7ed3\u4e4b\u524d\u4f7f\u7528\u8fc7\u6709\u9053\u4e91\u7b14\u8bb0\u548c\u6709\u9053\u4e91\u534f\u4f5c\u7684\u5fc3\u5f97\u4f9b\u53c2\u8003',
 u'pluginsConfig': {u'github-buttons': {u'buttons': [{u'repo': u'youdao_note_summary'}]},
                    u'sitemap-general': {u'prefix': u'https://book.crifan.com/gitbook/youdao_note_summary/website/'},
                    u'toolbar-button': {u'url': u'http://book.crifan.com/books/youdao_note_summary/pdf/youdao_note_summary.pdf'}},
 u'title': u'\u6709\u9053\u4e91\u7b14\u8bb0\u548c\u4e91\u534f\u4f5c\u4f7f\u7528\u603b\u7ed3'}
'////////////////////////////////////////////////////////////////////////////////'
'-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a'
{u'author': u'Crifan Li &lt;[email protected]&gt;',
 u'description': u'gitbook\u4e66\u7684\u63cf\u8ff0',
 u'gitbook': u'3.2.3',
 u'language': u'zh-hans',
 u'links': {u'sidebar': {u'\u4e3b\u9875': u'https://www.crifan.com'}},
 u'plugins': [u'theme-comscore',
              u'-lunr',
              u'-search',
              u'search-plus',
              u'disqus',
              u'-highlight',
              u'prism',
              u'prism-themes',
              u'github-buttons',
              u'splitter',
              u'-sharing',
              u'sharing-plus',
              u'tbfed-pagefooter',
              u'expandable-chapters-small',
              u'ga',
              u'donate',
              u'sitemap-general',
              u'copy-code-button',
              u'-alerts',
              u'-bootstrap-callout',
              u'callouts',
              u'toolbar-button'],
 u'pluginsConfig': {u'callouts': {u'showTypeInHeader': False},
                    u'disqus': {u'shortName': u'crifan'},
                    u'donate': {u'alipay': u'https://www.crifan.com/files/res/crifan_com/crifan_alipay_pay.jpg',
                                u'alipayText': u'\u652f\u4ed8\u5b9d\u6253\u8d4f\u7ed9Crifan',
                                u'button': u'\u6253\u8d4f',
                                u'title': u'',
                                u'wechat': u'https://www.crifan.com/files/res/crifan_com/crifan_wechat_pay.jpg',
                                u'wechatText': u'\u5fae\u4fe1\u6253\u8d4f\u7ed9Crifan'},
                    u'ga': {u'token': u'UA-28297199-1'},
                    u'github-buttons': {u'buttons': [{u'count': True,
                                                      u'repo': u'gitbook_name',
                                                      u'size': u'small',
                                                      u'type': u'star',
                                                      u'user': u'crifan'},
                                                     {u'count': False,
                                                      u'size': u'small',
                                                      u'type': u'follow',
                                                      u'user': u'crifan',
                                                      u'width': u'120'}]},
                    u'prism': {u'css': [u'prism-themes/themes/prism-atom-dark.css']},
                    u'sharing': {u'all': [u'douban',
                                          u'facebook',
                                          u'google',
                                          u'instapaper',
                                          u'line',
                                          u'linkedin',
                                          u'messenger',
                                          u'pocket',
                                          u'qq',
                                          u'qzone',
                                          u'stumbleupon',
                                          u'twitter',
                                          u'viber',
                                          u'vk',
                                          u'weibo',
                                          u'whatsapp'],
                                 u'douban': False,
                                 u'facebook': True,
                                 u'google': False,
                                 u'hatenaBookmark': False,
                                 u'instapaper': False,
                                 u'line': False,
                                 u'linkedin': False,
                                 u'messenger': False,
                                 u'pocket': False,
                                 u'qq': True,
                                 u'qzone': False,
                                 u'stumbleupon': False,
                                 u'twitter': True,
                                 u'viber': False,
                                 u'vk': False,
                                 u'weibo': True,
                                 u'whatsapp': False},
                    u'sitemap-general': {u'prefix': u'https://book.crifan.com/gitbook/gitbook_name/website/'},
                    u'tbfed-pagefooter': {u'copyright': u"crifan.com\uff0c\u4f7f\u7528&lt;a href='https://creativecommons.org/licenses/by-sa/4.0/deed.zh'&gt;\u77e5\u8bc6\u7f72\u540d-\u76f8\u540c\u65b9\u5f0f\u5171\u4eab4.0\u534f\u8bae&lt;/a&gt;\u53d1\u5e03",
                                          u'modify_format': u'YYYY-MM-DD HH:mm:ss',
                                          u'modify_label': u'\u8be5\u6587\u4ef6\u4fee\u8ba2\u65f6\u95f4\uff1a'},
                    u'theme-default': {u'showLevel': True},
                    u'toolbar-button': {u'icon': u'fa-file-pdf-o',
                                        u'label': u'\u4e0b\u8f7dPDF',
                                        u'url': u'http://book.crifan.com/books/gitbook_name/pdf/gitbook_name.pdf'}},
 u'root': u'./src',
 u'title': u'Gitbook\u7684\u4e66\u540d'}
'-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b'
{u'description': u'\u603b\u7ed3\u4e4b\u524d\u4f7f\u7528\u8fc7\u6709\u9053\u4e91\u7b14\u8bb0\u548c\u6709\u9053\u4e91\u534f\u4f5c\u7684\u5fc3\u5f97\u4f9b\u53c2\u8003',
 u'pluginsConfig': {u'github-buttons': {u'buttons': [{u'repo': u'youdao_note_summary'}]},
                    u'sitemap-general': {u'prefix': u'https://book.crifan.com/gitbook/youdao_note_summary/website/'},
                    u'toolbar-button': {u'url': u'http://book.crifan.com/books/youdao_note_summary/pdf/youdao_note_summary.pdf'}},
 u'title': u'\u6709\u9053\u4e91\u7b14\u8bb0\u548c\u4e91\u534f\u4f5c\u4f7f\u7528\u603b\u7ed3'}
'-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c-c'
{u'author': u'Crifan Li &lt;[email protected]&gt;',
 u'description': u'\u603b\u7ed3\u4e4b\u524d\u4f7f\u7528\u8fc7\u6709\u9053\u4e91\u7b14\u8bb0\u548c\u6709\u9053\u4e91\u534f\u4f5c\u7684\u5fc3\u5f97\u4f9b\u53c2\u8003',
 u'gitbook': u'3.2.3',
 u'language': u'zh-hans',
 u'links': {u'sidebar': {u'\u4e3b\u9875': u'https://www.crifan.com'}},
 u'plugins': [u'theme-comscore',
              u'-lunr',
              u'-search',
              u'search-plus',
              u'disqus',
              u'-highlight',
              u'prism',
              u'prism-themes',
              u'github-buttons',
              u'splitter',
              u'-sharing',
              u'sharing-plus',
              u'tbfed-pagefooter',
              u'expandable-chapters-small',
              u'ga',
              u'donate',
              u'sitemap-general',
              u'copy-code-button',
              u'-alerts',
              u'-bootstrap-callout',
              u'callouts',
              u'toolbar-button'],
 u'pluginsConfig': {u'callouts': {u'showTypeInHeader': False},
                    u'disqus': {u'shortName': u'crifan'},
                    u'donate': {u'alipay': u'https://www.crifan.com/files/res/crifan_com/crifan_alipay_pay.jpg',
                                u'alipayText': u'\u652f\u4ed8\u5b9d\u6253\u8d4f\u7ed9Crifan',
                                u'button': u'\u6253\u8d4f',
                                u'title': u'',
                                u'wechat': u'https://www.crifan.com/files/res/crifan_com/crifan_wechat_pay.jpg',
                                u'wechatText': u'\u5fae\u4fe1\u6253\u8d4f\u7ed9Crifan'},
                    u'ga': {u'token': u'UA-28297199-1'},
                    u'github-buttons': {u'buttons': [{u'count': True,
                                                      u'repo': u'youdao_note_summary',
                                                      u'size': u'small',
                                                      u'type': u'star',
                                                      u'user': u'crifan'},
                                                     {u'count': False,
                                                      u'size': u'small',
                                                      u'type': u'follow',
                                                      u'user': u'crifan',
                                                      u'width': u'120'}]},
                    u'prism': {u'css': [u'prism-themes/themes/prism-atom-dark.css']},
                    u'sharing': {u'all': [u'douban',
                                          u'facebook',
                                          u'google',
                                          u'instapaper',
                                          u'line',
                                          u'linkedin',
                                          u'messenger',
                                          u'pocket',
                                          u'qq',
                                          u'qzone',
                                          u'stumbleupon',
                                          u'twitter',
                                          u'viber',
                                          u'vk',
                                          u'weibo',
                                          u'whatsapp'],
                                 u'douban': False,
                                 u'facebook': True,
                                 u'google': False,
                                 u'hatenaBookmark': False,
                                 u'instapaper': False,
                                 u'line': False,
                                 u'linkedin': False,
                                 u'messenger': False,
                                 u'pocket': False,
                                 u'qq': True,
                                 u'qzone': False,
                                 u'stumbleupon': False,
                                 u'twitter': True,
                                 u'viber': False,
                                 u'vk': False,
                                 u'weibo': True,
                                 u'whatsapp': False},
                    u'sitemap-general': {u'prefix': u'https://book.crifan.com/gitbook/youdao_note_summary/website/'},
                    u'tbfed-pagefooter': {u'copyright': u"crifan.com\uff0c\u4f7f\u7528&lt;a href='https://creativecommons.org/licenses/by-sa/4.0/deed.zh'&gt;\u77e5\u8bc6\u7f72\u540d-\u76f8\u540c\u65b9\u5f0f\u5171\u4eab4.0\u534f\u8bae&lt;/a&gt;\u53d1\u5e03",
                                          u'modify_format': u'YYYY-MM-DD HH:mm:ss',
                                          u'modify_label': u'\u8be5\u6587\u4ef6\u4fee\u8ba2\u65f6\u95f4\uff1a'},
                    u'theme-default': {u'showLevel': True},
                    u'toolbar-button': {u'icon': u'fa-file-pdf-o',
                                        u'label': u'\u4e0b\u8f7dPDF',
                                        u'url': u'http://book.crifan.com/books/youdao_note_summary/pdf/youdao_note_summary.pdf'}},
 u'root': u'./src',
 u'title': u'\u6709\u9053\u4e91\u7b14\u8bb0\u548c\u4e91\u534f\u4f5c\u4f7f\u7528\u603b\u7ed3'}
bookJsonFullPath=/Users/crifan/GitBook/Library/Import/youdao_note_summary/book.json
➜  Import
</code>

输出book.json文件:

<code>{
  "description": "总结之前使用过有道云笔记和有道云协作的心得供参考", 
  "links": {
    "sidebar": {
      "主页": "https://www.crifan.com"
    }
  }, 
  "author": "Crifan Li &lt;[email protected]&gt;", 
  "title": "有道云笔记和云协作使用总结", 
  "gitbook": "3.2.3", 
  "language": "zh-hans", 
  "plugins": [
    "theme-comscore", 
    "-lunr", 
    "-search", 
    "search-plus", 
    "disqus", 
    "-highlight", 
    "prism", 
    "prism-themes", 
    "github-buttons", 
    "splitter", 
    "-sharing", 
    "sharing-plus", 
    "tbfed-pagefooter", 
    "expandable-chapters-small", 
    "ga", 
    "donate", 
    "sitemap-general", 
    "copy-code-button", 
    "-alerts", 
    "-bootstrap-callout", 
    "callouts", 
    "toolbar-button"
  ], 
  "pluginsConfig": {
    "toolbar-button": {
      "url": "http://book.crifan.com/books/youdao_note_summary/pdf/youdao_note_summary.pdf", 
      "icon": "fa-file-pdf-o", 
      "label": "下载PDF"
    }, 
    "sitemap-general": {
      "prefix": "https://book.crifan.com/gitbook/youdao_note_summary/website/"
    }, 
    "sharing": {
      "qq": true, 
      "douban": false, 
      "all": [
        "douban", 
        "facebook", 
        "google", 
        "instapaper", 
        "line", 
        "linkedin", 
        "messenger", 
        "pocket", 
        "qq", 
        "qzone", 
        "stumbleupon", 
        "twitter", 
        "viber", 
        "vk", 
        "weibo", 
        "whatsapp"
      ], 
      "google": false, 
      "stumbleupon": false, 
      "hatenaBookmark": false, 
      "twitter": true, 
      "vk": false, 
      "linkedin": false, 
      "instapaper": false, 
      "pocket": false, 
      "weibo": true, 
      "viber": false, 
      "facebook": true, 
      "qzone": false, 
      "messenger": false, 
      "line": false, 
      "whatsapp": false
    }, 
    "tbfed-pagefooter": {
      "modify_format": "YYYY-MM-DD HH:mm:ss", 
      "modify_label": "该文件修订时间:", 
      "copyright": "crifan.com,使用&lt;a href='https://creativecommons.org/licenses/by-sa/4.0/deed.zh'&gt;知识署名-相同方式共享4.0协议&lt;/a&gt;发布"
    }, 
    "github-buttons": {
      "buttons": [
        {
          "repo": "youdao_note_summary", 
          "count": true, 
          "type": "star", 
          "user": "crifan", 
          "size": "small"
        }, 
        {
          "count": false, 
          "width": "120", 
          "type": "follow", 
          "user": "crifan", 
          "size": "small"
        }
      ]
    }, 
    "disqus": {
      "shortName": "crifan"
    }, 
    "prism": {
      "css": [
        "prism-themes/themes/prism-atom-dark.css"
      ]
    }, 
    "ga": {
      "token": "UA-28297199-1"
    }, 
    "theme-default": {
      "showLevel": true
    }, 
    "donate": {
      "alipay": "https://www.crifan.com/files/res/crifan_com/crifan_alipay_pay.jpg", 
      "title": "", 
      "alipayText": "支付宝打赏给Crifan", 
      "button": "打赏", 
      "wechatText": "微信打赏给Crifan", 
      "wechat": "https://www.crifan.com/files/res/crifan_com/crifan_wechat_pay.jpg"
    }, 
    "callouts": {
      "showTypeInHeader": false
    }
  }, 
  "root": "./src"
}
</code>

基本上满足了:

从book_common.json和book_current.json两个json文件中,合并dict数据,输出到book.json中的目的。

转载请注明:在路上 » 【已解决】gitbook中book.json中能否把公共部分提取出来

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.170 seconds, using 22.21MB memory