Oops, fix dates on the writing index page to not have times.

This commit is contained in:
voussoir 2022-04-06 15:41:16 -07:00
parent 1523fbbd3e
commit 38a8751666
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -64,7 +64,7 @@ def git_repo_for_file(path):
folder = folder.parent folder = folder.parent
raise Exception('No Git repo.') 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 Return the ISO formatted date of the most recent commit that touched this
file, ignoring commits marked as "[minor]". file, ignoring commits marked as "[minor]".
@ -87,7 +87,7 @@ def git_file_edited_date(path) -> str:
date = check_output(command) date = check_output(command)
date = dateutil.parser.parse(date) date = dateutil.parser.parse(date)
date = date.astimezone(datetime.timezone.utc) date = date.astimezone(datetime.timezone.utc)
return date.isoformat() return date
def git_file_commit_history(path): def git_file_commit_history(path):
''' '''
@ -115,7 +115,7 @@ def git_file_commit_history(path):
lines = [line.split(' ', 1) for line in lines] lines = [line.split(' ', 1) for line in lines]
return 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. 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 = check_output(command)
date = dateutil.parser.parse(date) date = dateutil.parser.parse(date)
date = date.astimezone(datetime.timezone.utc) date = date.astimezone(datetime.timezone.utc)
return date.isoformat() return date
# SOUP # SOUP
################################################################################ ################################################################################
@ -200,8 +200,14 @@ class Article:
self.md_file = pathclass.Path(md_file) self.md_file = pathclass.Path(md_file)
self.html_file = self.md_file.replace_extension('html') self.html_file = self.md_file.replace_extension('html')
self.web_path = self.md_file.parent.relative_to(WRITING_ROOTDIR, simple=True).replace('\\', '/') 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 = 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) repo_path = git_repo_for_file(self.md_file)
relative_path = self.md_file.relative_to(repo_path, simple=True).replace('\\', '/') relative_path = self.md_file.relative_to(repo_path, simple=True).replace('\\', '/')
@ -362,7 +368,7 @@ def make_tag_page(index, path):
<ol class="article_list"> <ol class="article_list">
{% for article in articles %} {% for article in articles %}
<li> <li>
<a href="/writing/{{article.web_path}}">{{article.date}} - {{article.title|e}}</a> <a href="/writing/{{article.web_path}}">{{article.published_date}} - {{article.title|e}}</a>
</li> </li>
{% endfor %} {% endfor %}
</ol> </ol>
@ -392,7 +398,7 @@ def make_tag_page(index, path):
''').render( ''').render(
parent=parent, parent=parent,
index=index, 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, path=path,
children=sorted(tag.name for tag in index.children.keys()), children=sorted(tag.name for tag in index.children.keys()),
) )
@ -429,7 +435,7 @@ def write_writing_index():
<ol class="article_list"> <ol class="article_list">
{% for article in articles %} {% for article in articles %}
<li> <li>
<a href="{{article.web_path}}">{{article.date}} - {{article.title|e}}</a> <a href="{{article.web_path}}">{{article.published_date}} - {{article.title|e}}</a>
</li> </li>
{% endfor %} {% endfor %}
</ol> </ol>
@ -442,9 +448,9 @@ def write_writing_index():
<h2>Recently edited</h2> <h2>Recently edited</h2>
<ol class="article_list"> <ol class="article_list">
{% for article in articles_edited %} {% for article in articles_edited %}
{% if article.edited and article.edited != article.date %} {% if article.edited and article.edited != article.published %}
<li> <li>
<a href="{{article.web_path}}">{{article.edited}} - {{article.title|e}} ({{article.date}})</a> <a href="{{article.web_path}}">{{article.edited_date}} - {{article.title|e}} ({{article.published_date}})</a>
</li> </li>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -460,13 +466,13 @@ def write_writing_index():
</body> </body>
</html> </html>
''').render( ''').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) articles_edited=sorted(ARTICLES.values(), key=lambda a: a.edited, reverse=True)
) )
write(WRITING_ROOTDIR.with_child('index.html'), page) write(WRITING_ROOTDIR.with_child('index.html'), page)
def write_atom(): 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(''' atom = jinja2.Template('''
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"> <feed xmlns="http://www.w3.org/2005/Atom">
@ -480,7 +486,7 @@ def write_atom():
<id>{{article.publication_id}}</id> <id>{{article.publication_id}}</id>
<title>{{article.title|e}}</title> <title>{{article.title|e}}</title>
<link rel="alternate" type="text/html" href="https://voussoir.net/writing/{{article.web_path}}"/> <link rel="alternate" type="text/html" href="https://voussoir.net/writing/{{article.web_path}}"/>
<updated>{{article.date}}</updated> <updated>{{article.published_iso}}</updated>
<content type="html"> <content type="html">
<![CDATA[ <![CDATA[
{{article.soup.article}} {{article.soup.article}}
@ -490,7 +496,7 @@ def write_atom():
{% endfor %} {% endfor %}
</feed> </feed>
'''.strip()).render( '''.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, latest_date=latest_date,
) )
write(WRITING_ROOTDIR.with_child('writing.atom'), atom) write(WRITING_ROOTDIR.with_child('writing.atom'), atom)
@ -509,7 +515,7 @@ def write_rss():
<title>{{article.title|e}}</title> <title>{{article.title|e}}</title>
<guid isPermalink="false">{{article.publication_id}}</guid> <guid isPermalink="false">{{article.publication_id}}</guid>
<link>https://voussoir.net/writing/{{article.web_path}}</link> <link>https://voussoir.net/writing/{{article.web_path}}</link>
<pubDate>{{article.date}}</pubDate> <pubDate>{{article.published_iso}}</pubDate>
<description> <description>
<![CDATA[ <![CDATA[
{{article.soup.article}} {{article.soup.article}}
@ -519,7 +525,7 @@ def write_rss():
{% endfor %} {% endfor %}
</channel> </channel>
</rss> </rss>
'''.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) write(WRITING_ROOTDIR.with_child('writing.rss'), rss)
# GO # GO