Draw the commit chain at the end of the article.
This commit is contained in:
parent
601ece3b50
commit
30672d0405
1 changed files with 32 additions and 0 deletions
|
@ -3,6 +3,7 @@ import etiquette
|
||||||
import jinja2
|
import jinja2
|
||||||
import os
|
import os
|
||||||
import pprint
|
import pprint
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import vmarkdown
|
import vmarkdown
|
||||||
|
|
||||||
|
@ -20,7 +21,11 @@ ARTICLE_TEMPLATE = '''
|
||||||
|
|
||||||
{body}
|
{body}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
[View this document's history]({github_history})
|
[View this document's history]({github_history})
|
||||||
|
|
||||||
|
{commits}
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def write(path, content):
|
def write(path, content):
|
||||||
|
@ -62,6 +67,25 @@ def git_file_edited_date(path):
|
||||||
output = subprocess.check_output(command, stderr=subprocess.PIPE).decode('utf-8')
|
output = subprocess.check_output(command, stderr=subprocess.PIPE).decode('utf-8')
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
def git_file_commit_history(path):
|
||||||
|
path = pathclass.Path(path)
|
||||||
|
repo = git_repo_for_file(path)
|
||||||
|
path = path.relative_to(repo, simple=True)
|
||||||
|
command = [
|
||||||
|
GIT,
|
||||||
|
'-C', repo.absolute_path,
|
||||||
|
'log',
|
||||||
|
'--pretty=format:%H %h %ad %s',
|
||||||
|
'--date=short',
|
||||||
|
'--',
|
||||||
|
path,
|
||||||
|
]
|
||||||
|
output = subprocess.check_output(command, stderr=subprocess.PIPE).decode('utf-8')
|
||||||
|
lines = [line for line in output.splitlines() if line.strip()] #'*' in line]
|
||||||
|
lines = [re.sub(r'([\*\_\[\]\(\)\^])', r'\\\1', line) for line in lines]
|
||||||
|
lines = [line.split(' ', 1) for line in lines]
|
||||||
|
return lines
|
||||||
|
|
||||||
def git_file_published_date(path):
|
def git_file_published_date(path):
|
||||||
path = pathclass.Path(path)
|
path = pathclass.Path(path)
|
||||||
repo = git_repo_for_file(path)
|
repo = git_repo_for_file(path)
|
||||||
|
@ -92,10 +116,18 @@ class Article:
|
||||||
relative_path = self.md_file.relative_to(repo, simple=True)
|
relative_path = self.md_file.relative_to(repo, simple=True)
|
||||||
github_history = f'https://github.com/voussoir/voussoir.net/commits/master/{relative_path}'
|
github_history = f'https://github.com/voussoir/voussoir.net/commits/master/{relative_path}'
|
||||||
|
|
||||||
|
commits = git_file_commit_history(self.md_file)
|
||||||
|
commits = [
|
||||||
|
f'- [{line}](https://github.com/voussoir/voussoir.net/commit/{hash})'
|
||||||
|
for (hash, line) in commits
|
||||||
|
]
|
||||||
|
commits = '\n'.join(commits)
|
||||||
|
|
||||||
md = vmarkdown.cat_file(self.md_file.absolute_path)
|
md = vmarkdown.cat_file(self.md_file.absolute_path)
|
||||||
md = ARTICLE_TEMPLATE.format(
|
md = ARTICLE_TEMPLATE.format(
|
||||||
body=md,
|
body=md,
|
||||||
github_history=github_history,
|
github_history=github_history,
|
||||||
|
commits=commits,
|
||||||
)
|
)
|
||||||
self.soup = vmarkdown.markdown(
|
self.soup = vmarkdown.markdown(
|
||||||
md,
|
md,
|
||||||
|
|
Loading…
Reference in a new issue