diff options
author | mjfernez <mjf@mjfer.net> | 2022-03-13 15:21:11 -0400 |
---|---|---|
committer | mjfernez <mjf@mjfer.net> | 2022-03-13 15:21:11 -0400 |
commit | 94f71d6f8fc7301dfd470ccf2fee27e078321a78 (patch) | |
tree | 4a6864a043f764dd01e9d5c288ebb70b9be45abb | |
parent | 150b9695fdb0ebfeca0f8d5b268249bea46ea3f3 (diff) | |
download | ezcms-94f71d6f8fc7301dfd470ccf2fee27e078321a78.tar.gz |
Pull changes from mjfer.net
This commit adds the changes from the mjfer.net which enable using git
as the file last update tracker
-rw-r--r-- | config.py | 2 | ||||
-rw-r--r-- | rss_generator.py | 18 | ||||
-rw-r--r-- | siteconfig.py | 17 | ||||
-rw-r--r-- | templates/base.html | 18 | ||||
-rw-r--r-- | view_functions.py | 17 | ||||
-rw-r--r-- | views.py | 4 |
6 files changed, 53 insertions, 23 deletions
@@ -1,5 +1,6 @@ import os + class config: # BACKGROUND SETTINGS # # These don't need to be changed @@ -30,4 +31,3 @@ class config: DEFAULT_SITE_DIRS.append(x) GENERATED_SECRET_KEY = os.urandom(32) - diff --git a/rss_generator.py b/rss_generator.py index bde4645..05a8b39 100644 --- a/rss_generator.py +++ b/rss_generator.py @@ -1,5 +1,6 @@ import os -from time import strftime, strptime +from datetime import datetime +from dateutil import parser from siteconfig import siteconfig from view_functions import is_hidden_path, file_last_modified @@ -12,6 +13,7 @@ class RSS_Item: Item data is generated from a given file path """ + PARAGRAPHS = siteconfig.rss_channel_config['DESCRIPTION_LENGTH'] class NotAFile(Exception): @@ -19,6 +21,7 @@ class RSS_Item: Throws an exception if an RSS_Item is made out of a directory or invalid file """ + def __init__(self, path: str): self.path = path self.message = f"{path} not a file" @@ -32,8 +35,8 @@ class RSS_Item: self.TITLE = path.rsplit('.', 1)[0].split('/')[-1] self.FILE_TYPE = path.rsplit('.', 1)[1] self.DESCRIPTION = self.parse_file() - self.LAST_UPDATE = self.last_updated() self.URI = self.get_uri() + self.LAST_UPDATE = self.last_updated() self.LINK = siteconfig.rss_channel_config['LINK'] + self.URI def __str__(self): @@ -42,7 +45,10 @@ class RSS_Item: ) def short_timestamp(self): - return strftime("%Y-%m-%d %H:%M", strptime(self.LAST_UPDATE)) + if self.LAST_UPDATE is None: + return "" + dt_update = parser.parse(self.LAST_UPDATE) + return datetime.strftime(dt_update, "%Y-%m-%d %H:%M") def parse_file(self): """ @@ -76,11 +82,11 @@ class RSS_Item: return ''.join(description) def last_updated(self): - return file_last_modified(self.FULL_PATH) + return file_last_modified(self.URI) def get_uri(self): - # return everything after "./templates/" - return '/'.join(self.FULL_PATH.split('/')[2:]) + # return everything after "./templates/site" + return '/'.join(self.FULL_PATH.split('/')[3:]) def get_rss_channel(): diff --git a/siteconfig.py b/siteconfig.py index 4a653d4..0f4f66c 100644 --- a/siteconfig.py +++ b/siteconfig.py @@ -5,10 +5,11 @@ siteconfig.py - user editable configuration file # this file from config import config + class siteconfig(config): # REQUIRED SETTINGS # - DOMAIN = "example.net" # Your site here! + DOMAIN = "mjfer.net" # Your site here! HOME_TITLE = "WELCOME" LINKS_FILE = ".links" # ".lnx" if you like DESC_FILE = ".description" # ".desc" @@ -28,7 +29,9 @@ class siteconfig(config): # Set a custom secret key. If not set, it will be generated # Most of the time, you don't need to set this! - SECRET_KEY = config.GENERATED_SECRET_KEY # replace with random number. + SECRET_KEY = ( + config.GENERATED_SECRET_KEY + ) # replace with random number. # Options for Flask Compress # see here https://pypi.org/project/Flask-Compress/ @@ -36,16 +39,16 @@ class siteconfig(config): # RSS Settings rss_channel_config = { - 'TITLE': "RSS Feed for example.net", - 'LINK': "http://127.0.0.1:5000/", - 'DESCRIPTION': "My example feed", + 'TITLE': "RSS Feed for mjfer.net", + 'LINK': "https://mjfer.net/", + 'DESCRIPTION': "", 'LANGUAGE': "en-us", 'PUBDATE': "", 'LASTBUILDDATE': "", 'DOCS': "https://git.mjfer.net/ezcms.git/", 'GENERATOR': "EZCMS", - 'AUTHOR': "editor@example.net", - 'WEBMASTER': "webmaster@example.net", + 'AUTHOR': "mjf@mjfer.net", + 'WEBMASTER': "mjf@mjfer.net", # Max amount of paragraphs to print in each description 'DESCRIPTION_LENGTH': 3, # File extensions to include in RSS updates diff --git a/templates/base.html b/templates/base.html index c280184..5424505 100644 --- a/templates/base.html +++ b/templates/base.html @@ -3,9 +3,19 @@ <title>{{ domain }}/{{ title }}</title> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> + <meta name="description" content="a homepage run by an idiot, + full of sound and fury, signifying nothing."/> + <meta name="keywords" content="HTML, web, servers, linux, bsd, + hacking, forensics, tor, anonymity, internet, society, luddite, + futurism, lulz, fun, poetry, games, vidya, thoughts, random, + homepage, email server, web server, sound, fury, shakespeare, + nothing, writing, audio, classical music, video game music, + mjfernez, mjfernet, mike, fernez, mikefernez, michael"/> + <meta name="author" content="mjfernez"> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> {% block css%} <link rel="stylesheet" type="text/css" href="/static/main.css"> + <link rel="icon" href="/favicon.ico"> {% endblock %} </head> <body><center> @@ -17,16 +27,16 @@ <b> <a href="/{{ dir }}">{{ dir }}/</a> |</b> {% endfor %} <!-- Add icons here --> - <a href="/feed.xml"target="_blank" rel="noopener noreferrer"> - <img src="https://icons.getbootstrap.com/assets/icons/rss-fill.svg"> - </a> + <a href="/feed.xml" target="_blank" rel="noopener noreferrer"> + <img class="icon" src="/static/rss.svg"></a> + <a href="mailto:mjf@mjfer.net"><img class="icon" src="/static/email.svg"></a> </div> <h2 class="center">{{ title }}</h2> <div class="content"> {% block content %} {% endblock %} <h3 class="center">{{ errors }}</h3> - {% if parent_dir %} + {% if parent_dir %} <h3 class="center"><a href="{{ parent_dir }}">Go up to parent folder ({{ parent_dir }})</a></h3> {% endif %} </div> diff --git a/view_functions.py b/view_functions.py index 3de8687..4163c2e 100644 --- a/view_functions.py +++ b/view_functions.py @@ -3,8 +3,8 @@ view_functions.py - defines functions called by views to display the correct dat about files and paths. """ import os -from time import ctime -from siteconfig import siteconfig +import subprocess +from siteconfig import siteconfig, config def default_context(): @@ -20,7 +20,18 @@ def default_context(): def file_last_modified(path): - return ctime(os.stat(path).st_mtime) + git_time = f"git log -n1 --pretty=%aD {path}".split() + try: + mod_time = subprocess.check_output( + git_time, cwd=config.BASE_DIR + ) + except: + # File is not in the git log, no biggie, just blank the date + return None + + # Git outputs in RFC2822 format + return mod_time.decode('ascii').strip() + def index_dir(path): """ @@ -55,7 +55,7 @@ def render_file(path): { 'title': path.split('.')[0].upper(), 'parent_dir': '/' + '/'.join(path.split('/')[:-1]), - 'last_update': file_last_modified(abs_path) + 'last_update': file_last_modified(path), } ) if abs_path.endswith('.html'): @@ -134,6 +134,6 @@ def render_rss_feed(): feed = render_template("feed.xml", **context) response = make_response(feed) response.headers['Content-Type'] = str( - siteconfig.MIMETYPES.get(".xml") + siteconfig.MIMETYPES.get(".xml") ) return response |