Compare commits

...

2 Commits

Author SHA1 Message Date
7e85e2a1fa styling 2021-08-21 02:29:00 +01:00
65e36de48c Add file commit histories 2021-08-21 02:14:12 +01:00
5 changed files with 52 additions and 4 deletions

View File

@ -2,6 +2,7 @@
from bs4 import BeautifulSoup as bs from bs4 import BeautifulSoup as bs
import subprocess
import frontmatter import frontmatter
import magic import magic
import sys import sys
@ -40,6 +41,29 @@ def get_files(folder):
return markdown, plaintext, other return markdown, plaintext, other
def git_filehistory(working_dir, filename):
print(f"{pathlib.Path(filename).relative_to(working_dir)=}")
git_response = subprocess.run(
[
'git',
f"--git-dir={os.path.join(working_dir, '.git')}",
"log",
"-p",
"--",
pathlib.Path(filename).relative_to(working_dir)
],
stdout=subprocess.PIPE
)
filehistory = f"File history not available: git log returned code {git_response.returncode}."
"\nIf this is not a git repository, this is not a problem."
if git_response.returncode == 0:
filehistory = git_response.stdout.decode('utf-8')
if filehistory == "":
filehistory = "This file has no history (it may not be part of the git repository)."
return filehistory
def get_dirs(folder): def get_dirs(folder):
r = [] r = []
@ -151,8 +175,10 @@ def main(args):
'headers': header_lines 'headers': header_lines
}) })
filehistory = git_filehistory(args.notes, filename)
if update_required(filename, output_filename) or args.force: if update_required(filename, output_filename) or args.force:
html = pypandoc.convert_file(filename, 'html', extra_args=[f'--template={args.template}']) html = pypandoc.convert_file(filename, 'html', extra_args=[f'--template={args.template}', '-V', f'filehistory={filehistory}'])
os.makedirs(os.path.dirname(output_filename), exist_ok=True) os.makedirs(os.path.dirname(output_filename), exist_ok=True)
with open(output_filename, 'w+') as fp: with open(output_filename, 'w+') as fp:
@ -160,12 +186,14 @@ def main(args):
print(f"{plaintext_files=}") print(f"{plaintext_files=}")
for filename in plaintext_files: for filename in plaintext_files:
filehistory = git_filehistory(args.notes, filename)
title = os.path.basename(re.sub(f"^{args.notes.name}", args.output_dir.name, filename)) title = os.path.basename(re.sub(f"^{args.notes.name}", args.output_dir.name, filename))
output_filename = re.sub(f"^{args.notes.name}", os.path.join(args.output_dir.name, 'notes'), filename) + '.html' output_filename = re.sub(f"^{args.notes.name}", os.path.join(args.output_dir.name, 'notes'), filename) + '.html'
os.makedirs(os.path.dirname(output_filename), exist_ok=True) os.makedirs(os.path.dirname(output_filename), exist_ok=True)
html = re.sub(r'\$title\$', title, TEXT_ARTICLE_TEMPLATE_HEAD) html = re.sub(r'\$title\$', title, TEXT_ARTICLE_TEMPLATE_HEAD)
html = re.sub(r'\$h1title\$', title, html) html = re.sub(r'\$h1title\$', title, html)
html = re.sub(r'\$raw\$', os.path.basename(filename), html) html = re.sub(r'\$raw\$', os.path.basename(filename), html)
html = html.replace('$filehistory$', filehistory)
with open(filename) as fp: with open(filename) as fp:
html += fp.read() html += fp.read()
html += TEXT_ARTICLE_TEMPLATE_FOOT html += TEXT_ARTICLE_TEMPLATE_FOOT

View File

@ -95,3 +95,8 @@ blockquote * {
.matchHighlight { .matchHighlight {
background-color: #86c1b9; background-color: #86c1b9;
} }
#header > * {
margin: 0;
padding: 0
}

View File

@ -9,12 +9,19 @@
</head> </head>
<body> <body>
<div id="header">
<p style="font-size: 0.7em"> tags: <p style="font-size: 0.7em"> tags:
$for(tags)$ $for(tags)$
<a href="/.tags/$tags$.html">$tags$</a>$sep$, <a href="/.tags/$tags$.html">$tags$</a>$sep$,
$endfor$ $endfor$
</p> </p>
<p class="smallText" id="footer"> written by $author$, generated by <a href="https://git.alv.cx/alvierahman90/notes2web">notes2web</a></p>
<details id="commitLog">
<summary class="smallText">
Commit log (file history)
</summary>
<pre>$filehistory$</pre>
</details>
<div>
$body$ $body$
<p style="font-size: 0.7em;"> page generated by <a href="https://github.com/alvierahman90/notes2web">notes2web</a></p>
</body> </body>

View File

@ -1,3 +1,2 @@
</pre> </pre>
<p style="font-size: 0.7em;"> page generated by <a href="https://github.com/alvierahman90/notes2web">notes2web</a></p>
</body> </body>

View File

@ -7,6 +7,15 @@
</head> </head>
<body> <body>
<div id="header">
<p class="smallText" id="footer"> page generated by <a href="https://git.alv.cx/alvierahman90/notes2web">notes2web</a></p>
<details>
<summary class="smallText">
Commit log (file history)
</summary>
<pre>$filehistory$</pre>
</details>
</div>
<h1>$title$</h1> <h1>$title$</h1>
<p> This file was not rendered by notes2web because it is a plaintext file, not a markdown <p> This file was not rendered by notes2web because it is a plaintext file, not a markdown
file. file.