From 2495b97b0ba33f3e7bf96e09d4a6c8dc7ac5107e Mon Sep 17 00:00:00 2001 From: mjfernez Date: Sun, 24 Dec 2023 12:41:02 -0500 Subject: Update SEO, grab meta descriptions from .desc Keyword tags are outdated so those have been removed. Descriptions are more important that SEO. The description of the parent directory is used --- templates/base.html | 10 +--------- view_functions.py | 9 +++++++++ views.py | 13 ++++++++++--- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/templates/base.html b/templates/base.html index d1d0c08..a4e8a5d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -4,15 +4,7 @@ - - + diff --git a/view_functions.py b/view_functions.py index 4163c2e..b2e0720 100644 --- a/view_functions.py +++ b/view_functions.py @@ -81,3 +81,12 @@ def is_hidden_path(path): if d.startswith('.'): return True return False + + +def load_description(parent_dir): + description = None + description_file = parent_dir + '/' + siteconfig.DESC_FILE + if os.path.isfile(description_file): + with open(description_file, "r") as f: + description = f.read().strip() + return description diff --git a/views.py b/views.py index fda6152..aabe2a8 100644 --- a/views.py +++ b/views.py @@ -29,7 +29,11 @@ def home(): """ context = default_context() context.update( - {'title': app.config['HOME_TITLE'], 'parent_dir': None} + { + 'title': app.config['HOME_TITLE'], + 'parent_dir': None, + 'description': load_description(siteconfig.BASE_DIR) + } ) return render_template("site/home.html", **context) @@ -49,13 +53,16 @@ def render_file(path): abort(404) abs_path = siteconfig.BASE_DIR + path + parent_dir = '/' + '/'.join(path.split('/')[:-1]) context = default_context() if os.path.isfile(abs_path): + description = load_description(siteconfig.BASE_DIR + parent_dir) context.update( { 'title': path.split('.')[0].upper(), - 'parent_dir': '/' + '/'.join(path.split('/')[:-1]), + 'parent_dir': parent_dir, 'last_update': file_last_modified(path), + 'description': description } ) if abs_path.endswith('.html'): @@ -81,7 +88,7 @@ def render_file(path): context.update( { 'title': path.split('.')[0].upper(), - 'parent_dir': '/' + '/'.join(path.split('/')[:-1]), + 'parent_dir': parent_dir, 'cur_path': path, 'cur_dir': path.split('/')[-1] + '/', 'dirs': dirs, -- cgit v1.2.3