Merge branch 'markdown-powered'
This commit is contained in:
commit
cb59bfad71
12 changed files with 69 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
MARKDOWN_PATH = ''
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
|
|
0
pages/__init__.py
Normal file
0
pages/__init__.py
Normal file
0
pages/management/__init__.py
Normal file
0
pages/management/__init__.py
Normal file
0
pages/management/commands/__init__.py
Normal file
0
pages/management/commands/__init__.py
Normal file
31
pages/management/commands/parse_markdown.py
Normal file
31
pages/management/commands/parse_markdown.py
Normal file
|
@ -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'
|
||||||
|
|
3
pages/models.py
Normal file
3
pages/models.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
5
pages/urls.py
Normal file
5
pages/urls.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.conf.urls.defaults import *
|
||||||
|
|
||||||
|
urlpatterns = patterns('pages.views',
|
||||||
|
(r'^(?P<page>.+)/$', 'index'),
|
||||||
|
)
|
18
pages/views.py
Normal file
18
pages/views.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import os.path
|
||||||
|
|
||||||
|
from django.http import Http404
|
||||||
|
from django.views.generic.simple import direct_to_template
|
||||||
|
|
||||||
|
from settings import DEPLOY_PATH
|
||||||
|
|
||||||
|
def index(request, page):
|
||||||
|
|
||||||
|
template = 'html_pages/%s/index.html' % page
|
||||||
|
if not os.path.exists('%s/templates/%s' % (DEPLOY_PATH, template)):
|
||||||
|
raise Http404
|
||||||
|
|
||||||
|
c = {
|
||||||
|
"page": template,
|
||||||
|
}
|
||||||
|
|
||||||
|
return direct_to_template(request, "pages/index.html", c)
|
|
@ -87,4 +87,5 @@ INSTALLED_APPS = (
|
||||||
'main',
|
'main',
|
||||||
'blog',
|
'blog',
|
||||||
'projects',
|
'projects',
|
||||||
|
'pages',
|
||||||
)
|
)
|
||||||
|
|
1
templates/.gitignore
vendored
Normal file
1
templates/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
html_pages
|
5
templates/pages/index.html
Normal file
5
templates/pages/index.html
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% include page %}
|
||||||
|
{% endblock %}
|
4
urls.py
4
urls.py
|
@ -15,4 +15,8 @@ urlpatterns = patterns('',
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
urlpatterns += patterns('',
|
urlpatterns += patterns('',
|
||||||
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '%s/static' % DEPLOY_PATH})
|
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '%s/static' % DEPLOY_PATH})
|
||||||
|
)
|
||||||
|
|
||||||
|
urlpatterns += patterns('',
|
||||||
|
(r'^', include("pages.urls"))
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue