def generate_custom_pages(rel_dir_path='.'): """ Generate custom pages """ dir_path = os.path.join('pages', rel_dir_path) os.makedirs(os.path.join(_deploy_dir, rel_dir_path), exist_ok=True) for file in os.listdir(dir_path): if file.startswith('.'): # is hidden file continue if os.path.isdir(os.path.join(dir_path, file)): generate_custom_pages(os.path.join(rel_dir_path, file)) continue rel_file_path = os.path.join(rel_dir_path, file) filename, ext = os.path.splitext(rel_file_path) if ext == '.md' or ext == '.markdown': # is markdown file, need render rel_file_path = '.'.join((filename, 'html')) with open(os.path.join(_deploy_dir, rel_file_path), 'w', encoding='utf-8') as f: f.write( handler.custom_page('/'.join(os.path.split(rel_file_path)).replace('./', ''))) else: # is common static file, just copy shutil.copy(os.path.join('pages', rel_file_path), os.path.join(_deploy_dir, rel_file_path))
def custom_page(custom_page_path): return handler.custom_page(custom_page_path)