config
This commit is contained in:
2
config.cfg
Normal file
2
config.cfg
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
pages_root: '/mnt/data'
|
||||||
|
pages_reload: True
|
||||||
21
cont.py
21
cont.py
@@ -3,22 +3,23 @@ from flask import Flask, render_template, send_from_directory
|
|||||||
from flask_flatpages import FlatPages, pygments_style_defs
|
from flask_flatpages import FlatPages, pygments_style_defs
|
||||||
from flask_frozen import Freezer
|
from flask_frozen import Freezer
|
||||||
from config import Config
|
from config import Config
|
||||||
from os import listdir
|
|
||||||
import os
|
import os
|
||||||
from os.path import isfile, join
|
|
||||||
DEBUG = True
|
|
||||||
FLATPAGES_AUTO_RELOAD = DEBUG
|
|
||||||
FLATPAGES_EXTENSION = '.md'
|
|
||||||
FLATPAGES_ROOT = '/mnt/data'
|
|
||||||
POST_DIR = 'posts'
|
|
||||||
import re
|
import re
|
||||||
|
from os.path import isfile, join
|
||||||
|
|
||||||
|
cfg = Config(file('config.cfg'))
|
||||||
|
|
||||||
|
FLATPAGES_AUTO_RELOAD = cfg.pages_reload
|
||||||
|
FLATPAGES_EXTENSION = '.md'
|
||||||
|
FLATPAGES_ROOT = cfg.pages_root
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
flatpages = FlatPages(app)
|
flatpages = FlatPages(app)
|
||||||
freezer = Freezer(app)
|
freezer = Freezer(app)
|
||||||
app.config.from_object(__name__)
|
app.config.from_object(__name__)
|
||||||
|
|
||||||
def list_dir(mypath):
|
def list_dir(mypath):
|
||||||
return [f for f in listdir(mypath) if isfile(join(mypath, f)) and re.match('.*\.md.*',f) is None]
|
return [f for f in os.listdir(mypath) if isfile(join(mypath, f)) and re.match('.*\.md.*',f) is None]
|
||||||
|
|
||||||
def get_sub_pages(path, page):
|
def get_sub_pages(path, page):
|
||||||
ppath=page.path
|
ppath=page.path
|
||||||
@@ -46,11 +47,11 @@ def get_flatpage(path):
|
|||||||
else:
|
else:
|
||||||
page=flatpages.get(path)
|
page=flatpages.get(path)
|
||||||
return (is_index, path, page)
|
return (is_index, path, page)
|
||||||
@app.route('/')
|
|
||||||
@app.route('/<path:name>/')
|
@app.route('/<path:name>/')
|
||||||
def post(name='index'):
|
def post(name='index'):
|
||||||
is_index, path, page = get_flatpage(name)
|
is_index, path, page = get_flatpage(name)
|
||||||
|
app.logger.debug(name)
|
||||||
if is_index == True and not page is None:
|
if is_index == True and not page is None:
|
||||||
path2 = '{}/{}'.format(FLATPAGES_ROOT,path)
|
path2 = '{}/{}'.format(FLATPAGES_ROOT,path)
|
||||||
ld=list_dir(path2)
|
ld=list_dir(path2)
|
||||||
|
|||||||
Reference in New Issue
Block a user