2011-11-05 00:33:33 +01:00
|
|
|
import os
|
|
|
|
import markdown
|
|
|
|
|
|
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
|
|
|
|
|
|
from settings import MARKDOWN_PATH, DEPLOY_PATH
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = 'Parse markdown files in %s' % MARKDOWN_PATH
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
for root, dirs, files in os.walk(MARKDOWN_PATH):
|
|
|
|
for file in files:
|
|
|
|
subdir = root.replace(MARKDOWN_PATH, "")
|
|
|
|
mdfile = '%s/%s' % (root, file)
|
2011-11-05 02:17:51 +01:00
|
|
|
mdtuple = os.path.splitext(file)
|
|
|
|
mdname = '%s/%s' % (subdir, mdtuple[0])
|
2011-11-05 00:33:33 +01:00
|
|
|
htmlpath = '%s/templates/html_pages/%s' % (DEPLOY_PATH, mdname)
|
|
|
|
htmlfile = '%s/index.html' % htmlpath
|
|
|
|
|
2011-11-05 02:23:26 +01:00
|
|
|
if mdtuple[1] == '.mdwn' and os.path.exists(mdfile) \
|
|
|
|
and (not os.path.exists(htmlfile) \
|
|
|
|
or os.path.getmtime(mdfile) > os.path.getmtime(htmlfile)):
|
2011-11-05 00:33:33 +01:00
|
|
|
|
|
|
|
if not os.path.exists(htmlpath):
|
|
|
|
os.makedirs(htmlpath)
|
|
|
|
|
|
|
|
md = markdown.Markdown()
|
|
|
|
print 'Converting ', mdname, '-->', htmlfile,
|
|
|
|
wikiExtension = 'wikilinks(base_url=%s/)' % subdir
|
2011-11-05 02:23:26 +01:00
|
|
|
markdown.markdownFromFile(input=mdfile, output=htmlfile, encoding="utf-8",
|
2011-11-05 02:17:51 +01:00
|
|
|
extensions=[wikiExtension])
|
2011-11-05 00:33:33 +01:00
|
|
|
print ' ... succeeded'
|
|
|
|
|