Ejemplo n.º 1
0
def make_listing_page(subdir):
	'''Main function to create a directory listing page.'''
	#
	# look if there is a -listing- page
	# preprocess that page
	listing_page_md=get_listing_page(subdir)
	
	if listing_page_md != '':
		infile=os.path.join(config.CONTENT_DIR, subdir, listing_page_md)
		opts=[]
		
		# adding title block extraction here
		# (using them only for the final output below, atm)
		listing_page_body, title_block_vals=extract_title_block(infile, config.REGULAR_TB_LINES)
		
		listing_body_doctype=scan_doctype(listing_page_body)
	
	else:
		title_block_vals=[]
		listing_page_body=''
		listing_body_doctype='strict'
	
	# (debug-print)
	#print('Listing Page Body:', listing_page_body)
	
	# make the content listing
	listing_table_entries_str=gen_listing_table_entries(subdir, listing_page_md)
	
	# (debug-info)
	#print('Listing_table:', listing_table)
	
	# get/set the parent dir (for the path line)
	# this should go in a separate funtion, but it doesn't work
	#getset_parent_dir(subdir)
	# --> now using import config, this could probably be improved ...
	if config.LISTING_PARENT_DIR == '' :
		config.LISTING_PARENT_DIR=subdir
	elif config.LISTING_PARENT_DIR in subdir:
		pass
	else: config.LISTING_PARENT_DIR=subdir
	# (debug-info)
	#print('Subdir:', subdir)
	#print('Parent dir:', LISTING_PARENT_DIR)
	parent_dir=config.LISTING_PARENT_DIR
	
	# generate the path line
	listing_path_items=gen_listing_path_items(subdir, parent_dir, listing_page_md)
	
	# generate the main menu
	main_menu=generate_main_menu(subdir, listing_page_md)
	
	# prepare for output
	final_opts, out_filepath=prepare_final_listing(subdir, listing_path_items, listing_table_entries_str, main_menu, title_block_vals, listing_body_doctype)
	
	# final pandoc processing
	final_html=pandoc_pipe(listing_page_body, final_opts)
	
	# write out
	write_out(final_html, out_filepath)
Ejemplo n.º 2
0
def make_regular_pages(pages_struct, subdir):
	'''Main function to create regular pages.'''
	for page_group in pages_struct:
		# (info-prints)
		print("Page: ", os.path.join(subdir, page_group[0]))
		#print('Preprocessing:', page_group[0])
		#for subcontent in page_group[1:]:
		#	print(' Subcontent:', subcontent)
		#print('Page group:', page_group)
		
		# Preprocess page
		main_page_body_subst, plugin_blocks, plugin_blocks_pdf, main_page_tb_vals=preprocess_page_group(subdir, page_group)
		
		# (scan doctype)
		body_doctype=scan_doctype(main_page_body_subst)
		
		# Preprocess math content
		if config.PROCESS_MATH:
			main_page_body_subst_m = handle_math(subdir, page_group[0], main_page_body_subst)
		else:
			main_page_body_subst_m = main_page_body_subst
		
		# Generate the menus
		#
		# main menu
		# (info-prints)
		#print('Generate main menu.')
		#print('Subdir:', subdir, 'Page group [0]:', page_group[0])
		main_menu=generate_main_menu(subdir, page_group[0])
		
		# section menu
		# (info-prints)
		#print('Generate section menu.')
		section_menu_list=generate_section_menu(subdir, page_group[0])
		
		# Finalize this page
		# prepare for final output
		final_opts, out_filepath=prepare_final(subdir, page_group, main_page_tb_vals, main_menu, section_menu_list, body_doctype)
		
		# (debug-print)
		#print("main page body subst: ", main_page_body_subst)
		
		# final pandoc processing
		final_html_subst=pandoc_pipe(main_page_body_subst_m, final_opts)
		
		# (debug-print)
		#print("final html subst: ", final_html_subst)
		
		# back substitute
		if plugin_blocks != []:
			final_html=back_substitute(final_html_subst, plugin_blocks)
		else:
			final_html=final_html_subst
		
		# write out
		# (info-print)
		print('Writing:', out_filepath)
		write_out(final_html, out_filepath)
		
		# PDF production
		if config.PRODUCE_PDF:
			# (info-print)
			print("Produce a PDF.")
			# (plugins must provide blocks for pdf's)
			generate_pdf(subdir, page_group[0], main_page_body_subst, plugin_blocks_pdf, main_page_tb_vals)