Created
August 22, 2018 03:57
-
-
Save theand/3f3d387836dae039b5b72a158f8be1d1 to your computer and use it in GitHub Desktop.
TIL에서 index.md 를 만들기 위한 수동 코드.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
## 사용법 : til 디렉토리에서 python build.py 를 실행하면 index.md 파일을 생성합니다. | |
## index.md에는 .md 확장자를 가진 파일들의 목록이 디렉토리별로 들어갑니다. | |
from __future__ import unicode_literals | |
from __future__ import print_function | |
import os | |
import os.path | |
import shutil | |
dicts = {} | |
# get directory | |
for dirpath, dirnames, filenames in os.walk('.'): | |
# pass ., .git | |
if dirpath == "." or dirpath.startswith('.git') or dirpath.startswith('./.git'): | |
continue | |
category = os.path.basename( dirpath ).title() | |
dicts[category] = {} | |
# get .md filelist | |
for filename in filenames: | |
name, ext = os.path.splitext(filename) | |
title = name.title().replace('_', ' ').replace('-', ' ') | |
if ext.lower() != ".md": | |
continue | |
dicts[category][title] = os.path.join(dirpath, filename) | |
indexfile = open("index.md", "w") | |
# print out to index.md | |
for category in dicts: | |
print(category, file=indexfile) | |
print('====', file=indexfile) | |
print('', file=indexfile) | |
for title in dicts[category]: | |
print("* [%s](%s)" %( title , dicts[category][title]), file=indexfile) | |
print('', file=indexfile) | |
indexfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/jungcollin/TIL/blob/master/index.md
요런 식으로 결과가 나옴.