summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemsen2011-11-05 00:33:33 +0100
committerGravatar Tom Willemsen2011-11-05 00:33:33 +0100
commitfc51d7160df5ce97bfeba64a5af8efe2962223dd (patch)
treef8fa84433ce610574e32fb51939953d22e29b4db
parent3ae51caab712c4c60072f01cd8ce2e09c28300be (diff)
downloaddotfiles-fc51d7160df5ce97bfeba64a5af8efe2962223dd.tar.gz
dotfiles-fc51d7160df5ce97bfeba64a5af8efe2962223dd.zip
Add parse_markdown command
-rw-r--r--local_settings.py.example1
-rw-r--r--pages/management/__init__.py0
-rw-r--r--pages/management/commands/__init__.py0
-rw-r--r--pages/management/commands/parse_markdown.py31
-rw-r--r--templates/.gitignore1
5 files changed, 33 insertions, 0 deletions
diff --git a/local_settings.py.example b/local_settings.py.example
index 6a166a7..fe6c1aa 100644
--- a/local_settings.py.example
+++ b/local_settings.py.example
@@ -1,4 +1,5 @@
DEBUG = False
+MARKDOWN_PATH = ''
DATABASES = {
'default': {
diff --git a/pages/management/__init__.py b/pages/management/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/pages/management/__init__.py
diff --git a/pages/management/commands/__init__.py b/pages/management/commands/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/pages/management/commands/__init__.py
diff --git a/pages/management/commands/parse_markdown.py b/pages/management/commands/parse_markdown.py
new file mode 100644
index 0000000..8c193df
--- /dev/null
+++ b/pages/management/commands/parse_markdown.py
@@ -0,0 +1,31 @@
+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)
+ mdname = '%s/%s' % (subdir, os.path.splitext(file)[0])
+ htmlpath = '%s/templates/html_pages/%s' % (DEPLOY_PATH, mdname)
+ htmlfile = '%s/index.html' % htmlpath
+
+ if os.path.exists(mdfile) and not os.path.exists(htmlfile) \
+ or os.path.getmtime(mdfile) > os.path.getmtime(htmlfile):
+
+ if not os.path.exists(htmlpath):
+ os.makedirs(htmlpath)
+
+ md = markdown.Markdown()
+ print 'Converting ', mdname, '-->', htmlfile,
+ wikiExtension = 'wikilinks(base_url=%s/)' % subdir
+ markdown.markdownFromFile(input=mdfile, output=htmlfile, encoding="utf-8", extensions=[wikiExtension])
+ print ' ... succeeded'
+
diff --git a/templates/.gitignore b/templates/.gitignore
new file mode 100644
index 0000000..c46f106
--- /dev/null
+++ b/templates/.gitignore
@@ -0,0 +1 @@
+html_pages