• 利用python生成gitbook目录文件


    将 summary-generator.py 放在已知根目录下。

    开发环境:

    • macOS
    • python 3

    完整代码:

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    
    import os, sys
    
    path = "."
    result_list = []
    result_str = ""
    flag = "* "
    tab = "  "
    # 定义递归方法
    def find_files(path, n = 0, dir = ""):
        global result_str
        if os.path.isdir(path):
            if path <> "node_modules" and path <> "_book" and path <> ".DS_Store":
                if path <> ".":
                    dir += path + "/"
                # path是文件夹
                if path <> ".":
                    result_list.append(tab * n + flag + "[" + path + "](" + dir + "/README.md" + ")")
                    result_str += tab * n + flag + "[" + path + "](" + dir + "/README.md"  + ")
    "
                    n = n + 1
                else:
                    n = 0
                # 按文件名称排序
                dirs = sorted(os.listdir(path))
                for file in dirs:
                    find_files(file, n, dir)
        else:
            # path是文件
            if path.endswith(".md") and path <> "SUMMARY.md" and path <> "README.md":
                result_list.append(tab * n + flag + "[" + path + "](" + dir + path + ")")
                result_str += tab * n + flag + "[" + path + "](" + dir + path + ")
    "
    find_files(".", 0, "")
    for file in result_list:
        print file
    try:
        f = open('./SUMMARY.md', 'w')
        f.write(result_str)
    finally:
        if f:
            f.close()
    
  • 相关阅读:
    微信JSSDK使用指南
    安装eclipse中html/jsp/xml editor插件以及改动html页面的字体
    OpenLayers 3+Geoserver+PostGIS实现点击查询
    编程算法
    javascript闭包具体解释
    网络安全基本概念
    Android 5.1 Settings源代码简要分析
    Linq 使用注意
    父类引用指向子类对象
    CPU使用率
  • 原文地址:https://www.cnblogs.com/longying2008/p/15068115.html
Copyright © 2020-2023  润新知