Exemplo n.º 1
0
def md2html_all(mdp, template, root_path):
    import shutil
    if root_path == '':
        des = 'html'
    else:
        des = 'html_test'

    pwd = os.getcwd()
    _pwd = os.path.join(pwd, des)
    if not os.path.exists(_pwd):
        os.makedirs(_pwd)
    if not os.path.exists(os.path.join(_pwd, "source")):
        shutil.copytree("source", os.path.join(_pwd, "source"))
    dist = {}

    for md_pwd in get_post_list(os.path.join(pwd, "post")):
        args = md2html(md_pwd, mdp, template, root_path, des)
        url = args['shortcut']
        title = args['title'] 
        categories = args['categories']
        if categories in dist.keys():
            dist[categories].append((url,title))
        else:
            dist[categories] = []
            dist[categories].append((url,title))
    if 'draft' in dist.keys():
        del dist['draft']
    try:
        template = open('template/index.html','r').read()
    except:
        tool.log('error')('index template not found')

    html = Environment().from_string(template).render(dist=dist, root_path=root_path) 
    f = open( des + '/index.html', 'w')
    f.write(html)
Exemplo n.º 2
0
def md2html(md_pwd, mdp, template, root_path, des):
    try:
        template = open('template/'+template+'.html','r').read()
        utils = open('template/utils.html').read()
        md = open(md_pwd, 'r').read()
    except:
        tool.log('error')('file not found')
        return 
    mdp.renderer.reset_toc()
    args, md = meta.parse(md)
    if args['categories'] == 'draft':
        return args
    md = Environment().from_string(utils+md).render()
    content = mdp(md) 
    args['content'] = content
    args['root_path'] = root_path
    args['meta'] = generate_meta(args)
    args['this_href'] = "blog.septicmk.com/" +  args['categories'] + '/' + args['shortcut'] + '.html'
    html = Environment().from_string(template).render(**args)
    try:
        _pwd = os.path.join(des, args['categories'], args['shortcut']+'.html')
        _dir = os.path.dirname(_pwd)
        if not os.path.exists(_dir):
            os.makedirs(_dir)
        f = open(_pwd,'w')
        f.write(html)
        return args
    except:
        tool.log('error')('html dir not found')