diff --git a/voussoir.net/writing/generate_site.py b/voussoir.net/writing/generate_site.py index 6dd67c6..450c36c 100644 --- a/voussoir.net/writing/generate_site.py +++ b/voussoir.net/writing/generate_site.py @@ -64,7 +64,7 @@ def git_repo_for_file(path): folder = folder.parent raise Exception('No Git repo.') -def git_file_edited_date(path) -> str: +def git_file_edited_date(path) -> datetime.datetime: ''' Return the ISO formatted date of the most recent commit that touched this file, ignoring commits marked as "[minor]". @@ -87,7 +87,7 @@ def git_file_edited_date(path) -> str: date = check_output(command) date = dateutil.parser.parse(date) date = date.astimezone(datetime.timezone.utc) - return date.isoformat() + return date def git_file_commit_history(path): ''' @@ -115,7 +115,7 @@ def git_file_commit_history(path): lines = [line.split(' ', 1) for line in lines] return lines -def git_file_published_date(path) -> str: +def git_file_published_date(path) -> datetime.datetime: ''' Return the ISO formatted date of the commit where this file first appeared. ''' @@ -136,7 +136,7 @@ def git_file_published_date(path) -> str: date = check_output(command) date = dateutil.parser.parse(date) date = date.astimezone(datetime.timezone.utc) - return date.isoformat() + return date # SOUP ################################################################################ @@ -200,8 +200,14 @@ class Article: self.md_file = pathclass.Path(md_file) self.html_file = self.md_file.replace_extension('html') self.web_path = self.md_file.parent.relative_to(WRITING_ROOTDIR, simple=True).replace('\\', '/') - self.date = git_file_published_date(self.md_file) + + self.published = git_file_published_date(self.md_file) + self.published_iso = self.published.isoformat() + self.published_date = self.published.strftime('%Y-%m-%d') + self.edited = git_file_edited_date(self.md_file) + self.edited_iso = self.edited.isoformat() + self.edited_date = self.edited.strftime('%Y-%m-%d') repo_path = git_repo_for_file(self.md_file) relative_path = self.md_file.relative_to(repo_path, simple=True).replace('\\', '/') @@ -362,7 +368,7 @@ def make_tag_page(index, path):
    {% for article in articles %}
  1. - {{article.date}} - {{article.title|e}} + {{article.published_date}} - {{article.title|e}}
  2. {% endfor %}
@@ -392,7 +398,7 @@ def make_tag_page(index, path): ''').render( parent=parent, index=index, - articles=sorted(index.articles, key=lambda a: a.date, reverse=True), + articles=sorted(index.articles, key=lambda a: a.published, reverse=True), path=path, children=sorted(tag.name for tag in index.children.keys()), ) @@ -429,7 +435,7 @@ def write_writing_index():
    {% for article in articles %}
  1. - {{article.date}} - {{article.title|e}} + {{article.published_date}} - {{article.title|e}}
  2. {% endfor %}
@@ -442,9 +448,9 @@ def write_writing_index():

Recently edited

    {% for article in articles_edited %} - {% if article.edited and article.edited != article.date %} + {% if article.edited and article.edited != article.published %}
  1. - {{article.edited}} - {{article.title|e}} ({{article.date}}) + {{article.edited_date}} - {{article.title|e}} ({{article.published_date}})
  2. {% endif %} {% endfor %} @@ -460,13 +466,13 @@ def write_writing_index(): ''').render( - articles=sorted(ARTICLES.values(), key=lambda a: a.date, reverse=True), + articles=sorted(ARTICLES.values(), key=lambda a: a.published, reverse=True), articles_edited=sorted(ARTICLES.values(), key=lambda a: a.edited, reverse=True) ) write(WRITING_ROOTDIR.with_child('index.html'), page) def write_atom(): - latest_date = max(article.date for article in ARTICLES_PUBLISHED.values()) + latest_date = max(article.published for article in ARTICLES_PUBLISHED.values()) atom = jinja2.Template(''' @@ -480,7 +486,7 @@ def write_atom(): {{article.publication_id}} {{article.title|e}} - {{article.date}} + {{article.published_iso}} '''.strip()).render( - articles=sorted(ARTICLES_PUBLISHED.values(), key=lambda a: a.date, reverse=True), + articles=sorted(ARTICLES_PUBLISHED.values(), key=lambda a: a.published, reverse=True), latest_date=latest_date, ) write(WRITING_ROOTDIR.with_child('writing.atom'), atom) @@ -509,7 +515,7 @@ def write_rss(): {{article.title|e}} {{article.publication_id}} https://voussoir.net/writing/{{article.web_path}} - {{article.date}} + {{article.published_iso}} - '''.strip()).render(articles=sorted(ARTICLES_PUBLISHED.values(), key=lambda a: a.date, reverse=True)) + '''.strip()).render(articles=sorted(ARTICLES_PUBLISHED.values(), key=lambda a: a.published, reverse=True)) write(WRITING_ROOTDIR.with_child('writing.rss'), rss) # GO