X-Git-Url: http://git.subgeniuskitty.com/cmless/.git/blobdiff_plain/1debf0347ff8e74bd56e18970fc43c4c8336462c..73c5dba96df5b81d7e05ec9a75e81306c709883b:/bin/template.py diff --git a/bin/template.py b/bin/template.py index cdc7fe7..5950cdf 100644 --- a/bin/template.py +++ b/bin/template.py @@ -10,17 +10,77 @@ import config, misc def add_delimiter(keyword): return config.template_delimiter + keyword + config.template_delimiter +def menu_top_level(template): + """Generate a menu based on the directories contained in config.site_data_prefix. + + Only top level directories are included, i.e. no recursion. The root + directory '.' is included with the menu name "Home". All other directories + use the directory name as the menu name. Each entry is wrapped in an HTML + tag for direct use as a menu. + """ + keyword = add_delimiter("top_level_menu") + + dir_list = [["Home","/"]] + + for entry in os.listdir(config.site_data_prefix): + if os.path.isdir(os.path.join(config.site_data_prefix, entry)): + dir_list.append([entry,os.path.join("/", entry, "")]) + + menu_text = "" + + for entry in dir_list: + # Since we highlight (adding class=thisSite) whenever we are inside one + # of these menu directories it is necessary to test for the "Home" or + # "/" entry separately as every page on the site is inside that + # directory. + if ((entry[1] == "/" and os.path.dirname(os.environ['REQUEST_URI']) == "/") + or (entry[1] != "/" and entry[1] == os.environ['REQUEST_URI'][:len(entry[1])])): + menu_text += '' + entry[0] + '\n' + else: + menu_text += '' + entry[0] + '\n' + + return template.replace(keyword,menu_text) + +def menu_current_dir(template): + """Generate a menu based files in the currently requested directory. + + Files are only included in the menu if they have valid menu_text metadata entries. + """ + keyword = add_delimiter("current_dir_menu") + + menu_text = "" + + current_path = os.path.dirname(os.path.join(config.site_data_prefix, + os.environ['REQUEST_URI'][1:])) + for entry in os.listdir(current_path): + # We exclude files without valid menu_text metadata (i.e. equal to an + # empty string) so that we can create pages which do not appear in the menu. + # + # TODO: Should this implicit behavior be made explicit by addition of a + # metadata tag like "visible_in_menu"? + if (entry[-3:] == config.markup_file_extension + and misc.lookup_file_metadata("menu_text",os.path.join(current_path,entry)) != ""): + menu_text += ('
  • ' + + misc.lookup_file_metadata("menu_text",os.path.join(current_path,entry)) + + '
  • \n') + + return template.replace(keyword,menu_text) + def head_meta_description(template): keyword = add_delimiter("meta_description") - return template.replace(keyword,'') + return template.replace(keyword,'') def head_meta_keywords(template): keyword = add_delimiter("meta_keywords") - return template.replace(keyword,'') + return template.replace(keyword,'') def page_title(template): keyword = add_delimiter("page_title") - return template.replace(keyword, config.site_name + " - " + misc.lookup_page_metadata("page_title")) + return template.replace(keyword, config.site_name + " - " + + misc.lookup_current_metadata("page_title")) def site_title(template): keyword = add_delimiter("site_title")