1 Star 0 Fork 0

xtdumpling/developer-center

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
new.py 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
张磊 提交于 2015-07-16 11:54 +08:00 . add system operation guide
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import locale
meta = '''Title: My Document
Summary: A brief description of my document.
Authors: Waylan Limberg
Date: October 2, 2007
'''
def usage():
help = u'''Use new.py like:
new.py category title path-to-file
example:
new.py 深度截图 入门指南 deepin-shot/guide.md
it will create a file at "docs/deepin-shot/guide.md" with this content:
title:
category:首页
'''
print(help)
if __name__=="__main__":
if len(sys.argv)!= 4:
usage()
sys.exit(1)
encoding = locale.getdefaultlocale()[1]
meta = {}
category = sys.argv[1].decode(encoding, 'ignore')
title = sys.argv[2].decode(encoding, 'ignore')
file = sys.argv[3]
if not file.endswith(".md"):
print ("path-to-file must end with .md\n")
usage()
sys.exit(2)
meta["category"]=category
meta["title"]=title
mdmeta = "<!--Meta\n"
for k, v in meta.items():
mdmeta += k+":"+v+"\n"
mdmeta += "DO NOT Delete Meta Above -->\n"
path = "docs/" + file
try:
dir, name = os.path.split(path)
os.makedirs(dir)
except:
pass
fp = open(path, "w")
fp.writelines(mdmeta.encode('utf8', 'ignore'))
fp.close()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
CSS
1
https://gitee.com/xtdumpling/developer-center.git
git@gitee.com:xtdumpling/developer-center.git
xtdumpling
developer-center
developer-center
master

搜索帮助