@ -14,7 +14,7 @@ def folders (_path,_config):
"""
"""
_content = os . listdir ( _path )
_content = os . listdir ( _path )
return [ _name for _name in _content if os . path . isdir ( os . sep . join ( [ _path , _name ] ) ) if not _name . startswith ( ' _ ' ) ]
return [ _name for _name in _content if os . path . isdir ( os . sep . join ( [ _path , _name ] ) ) if not _name . startswith ( ' _ ' ) ]
def content ( _folder , _config ):
def content ( _folder , _config ,keep = [ ] ):
"""
"""
: content of the folder
: content of the folder
"""
"""
@ -29,13 +29,13 @@ def content(_folder,_config):
_menuItems = list_files ( _folder , _config ) #os.listdir(_folder)
_menuItems = list_files ( _folder , _config ) #os.listdir(_folder)
# return [{'text':_name.split('.')[0].replace('_', ' ').replace('-',' ').strip(),'uri': os.sep.join([_folder,_name])} for _name in os.listdir(_folder) if not _name.startswith('_') and os.path.isfile( os.sep.join([_folder,_name]))]
# return [{'text':_name.split('.')[0].replace('_', ' ').replace('-',' ').strip(),'uri': os.sep.join([_folder,_name])} for _name in os.listdir(_folder) if not _name.startswith('_') and os.path.isfile( os.sep.join([_folder,_name]))]
return [ { ' text ' : _name . split ( ' . ' ) [ 0 ] . replace ( ' _ ' , ' ' ) . replace ( ' - ' , ' ' ) . strip ( ) , ' uri ' : os . sep . join ( [ _path , _name ] ) } for _name in os . listdir ( _folder ) if not _name [ 0 ] in [ ' . ' , ' _ ' ] and os . path . isfile ( os . sep . join ( [ _folder , _name ] ) ) ]
return [ { ' text ' : _name . split ( ' . ' ) [ 0 ] . replace ( ' _ ' , ' ' ) . replace ( ' - ' , ' ' ) . strip ( ) , ' uri ' : os . sep . join ( [ _path , _name ] ) } for _name in os . listdir ( _folder ) if not _name [ 0 ] in [ ' . ' , ' _ ' ] and os . path . isfile ( os . sep . join ( [ _folder , _name ] ) ) and _name . split ( ' . ' ) [ - 1 ] in [ ' html ' , ' md ' ] ]
else :
else :
return [ ]
return [ ]
def list_files ( _folder , _config ):
def list_files ( _folder , _config , keep = [ ] ):
return [ name for name in os . listdir ( _folder ) if name [ 0 ] not in [ ' . ' , ' _ ' ] ]
return [ name for name in os . listdir ( _folder ) if name [ 0 ] not in [ ' . ' , ' _ ' ] ]
def build ( _config ): #(_path,_content):
def build ( _config , keep = [ ] ): #(_path,_content):
"""
"""
building the menu for the site given the content is on disk
building the menu for the site given the content is on disk
: path path of the files on disk
: path path of the files on disk
@ -47,7 +47,8 @@ def build (_config): #(_path,_content):
_path = _realpath ( _path , _config )
_path = _realpath ( _path , _config )
# print (_path)
# print (_path)
_items = folders ( _path , _config )
_items = folders ( _path , _config )
_subItems = [ content ( os . sep . join ( [ _path , _name ] ) , _config ) for _name in _items ]
_subItems = [ content ( os . sep . join ( [ _path , _name ] ) , _config ) for _name in _items ]
_r = { }
_r = { }
for _name in _items :
for _name in _items :
_index = _items . index ( _name )
_index = _items . index ( _name )
@ -85,7 +86,6 @@ def read (**_args):
_uri = request . args [ ' uri ' ] # if 'location' in _layout :
_uri = request . args [ ' uri ' ] # if 'location' in _layout :
# _uri = os.sep.join([_layout['location'],_uri])
# _uri = os.sep.join([_layout['location'],_uri])
_uri = _realpath ( _uri , _args [ ' config ' ] )
_uri = _realpath ( _uri , _args [ ' config ' ] )
if os . path . exists ( _uri ) :
if os . path . exists ( _uri ) :
f = open ( _uri , mode = ' rb ' )
f = open ( _uri , mode = ' rb ' )
_stream = f . read ( )
_stream = f . read ( )
@ -103,12 +103,15 @@ def exists(**_args):
def html ( _uri , _config ) :
def html ( _uri , _config ) :
# _html = (open(uri)).read()
# _html = (open(uri)).read()
_path = _realpath ( _uri , _config )
_path = _realpath ( _uri , _config )
_context = _config [ ' system ' ] [ ' context ' ]
_html = ( open ( _path ) ) . read ( )
_html = ( open ( _path ) ) . read ( )
_layout = _config [ ' layout ' ]
_layout = _config [ ' layout ' ]
if ' location ' in _layout :
if ' location ' in _layout :
if not _config :
_api = os . sep . join ( [ ' api/disk/read?uri= ' , _layout [ ' root ' ] ] )
_api = os . sep . join ( [ ' api/disk/read?uri= ' , _layout [ ' root ' ] ] )
else :
_api = os . sep . join ( [ f ' { _context } /api/disk/read?uri= ' , _layout [ ' root ' ] ] )
_html = _html . replace ( _layout [ ' root ' ] , _api )
_html = _html . replace ( _layout [ ' root ' ] , _api )
_html = markdown ( _html ) if _uri [ - 2 : ] in [ ' md ' , ' MD ' , ' Md ' , ' mD ' ] else _html
_html = markdown ( _html ) if _uri [ - 2 : ] in [ ' md ' , ' MD ' , ' Md ' , ' mD ' ] else _html
return _html
return _html
@ -118,15 +121,23 @@ def plugins (**_args):
: path path of the files
: path path of the files
: name name of the module
: name name of the module
"""
"""
_context = _args [ ' context ' ]
if ' path ' not in _args :
if ' path ' not in _args :
return { ' api/disk/read ' : read }
key = ' api/disk/read '
if _context :
key = f ' { _context } / { key } '
return { key : read }
_path = _args [ ' path ' ] #os.sep.join([_args['root'],'plugin'])
_path = _args [ ' path ' ] #os.sep.join([_args['root'],'plugin'])
if os . path . isdir ( _path ) :
if os . path . isdir ( _path ) :
files = os . listdir ( _path )
files = os . listdir ( _path )
if files :
if files :
files = [ name for name in files if name . endswith ( ' .py ' ) ]
files = [ name for name in files if name . endswith ( ' .py ' ) ]
if files :
if files :
_path = os . sep . join ( [ _path , files [ 0 ] ] )
_uri = [ _path , files [ 0 ] ]
if _context :
_uri = [ _context ] + _uri
_path = os . sep . join ( _uri )
else :
else :
return None
return None
else :
else :