#NEWLINE# def begin_site( self ) : #NEWLINE# #INDENT# '\n        Replace the content_url method in the site object with a custom method\n        that cleans urls based on the given configuration.\n        ' #NEWLINE# config = self . site . config #NEWLINE# if ( not hasattr ( settings , 'urlcleaner' ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if hasattr ( Site , '___url_cleaner_patched___' ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# settings = config . urlcleaner #NEWLINE# def clean_url( urlgetter ) : #NEWLINE# #INDENT# @ wraps ( urlgetter ) #NEWLINE# def wrapper( site , path , safe = None ) : #NEWLINE# #INDENT# url = urlgetter ( site , path , safe ) #NEWLINE# index_file_names = getattr ( settings , 'index_file_names' , [ 'index.html' ] ) #NEWLINE# rep = File ( url ) #NEWLINE# if ( rep . name in index_file_names ) : #NEWLINE# #INDENT# url = rep . parent . path . rstrip ( '/' ) #NEWLINE# if ( hasattr ( settings , 'append_slash' ) and settings . append_slash ) : #NEWLINE# #INDENT# url += '/' #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if hasattr ( settings , 'strip_extensions' ) : #NEWLINE# #INDENT# if ( rep . kind in settings . strip_extensions ) : #NEWLINE# #INDENT# url = rep . parent . child ( rep . name_without_extension ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ( url or '/' ) #NEWLINE# #UNINDENT# return wrapper #NEWLINE# #UNINDENT# Site . ___url_cleaner_patched___ = True #NEWLINE# Site . content_url = clean_url ( Site . content_url )