#NEWLINE# def sort_structure( self , structure ) : #NEWLINE# #INDENT# 'Sort index structure in lower-case, alphabetical order\n\n        Compare argument is a key/value structure, if the compare argument is a\n        leaf node, which has `title` key in its value, use the title value,\n        else use the key to compare.\n        ' #NEWLINE# def _cmp( arg1 , arg2 ) : #NEWLINE# #INDENT# arg1 = ( arg1 [ 1 ] [ 'title' ] if ( 'title' in arg1 [ 1 ] ) else arg1 [ 0 ] ) #NEWLINE# arg2 = ( arg2 [ 1 ] [ 'title' ] if ( 'title' in arg2 [ 1 ] ) else arg2 [ 0 ] ) #NEWLINE# cmp = ( lambda x , y : ( ( x > y ) - ( x < y ) ) ) #NEWLINE# return cmp ( arg1 . lower ( ) , arg2 . lower ( ) ) #NEWLINE# #UNINDENT# if is_py2 : #NEWLINE# #INDENT# sorted_opts = { #NEWLINE# #INDENT# 'cmp' : _cmp , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if is_py3 : #NEWLINE# #INDENT# sorted_opts = { #NEWLINE# #INDENT# 'key' : cmp_to_key ( sorted_opts ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# sorted_structure = copy . deepcopy ( structure ) #NEWLINE# for ( k , _ ) in sorted_structure . items ( ) : #NEWLINE# #INDENT# sorted_structure = OrderedDict ( sorted ( sorted_structure . items ( ) , ** sorted_opts ) ) #NEWLINE# if k . endswith ( '.{0}' . format ( self . site_config [ 'default_ext' ] ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# sorted_structure [ k ] = self . sort_structure ( sorted_structure [ k ] ) #NEWLINE# #UNINDENT# return sorted_structure