feat: add git_creation_date method
This commit is contained in:
parent
8a614fee99
commit
b2748a6cf3
|
|
@ -0,0 +1,26 @@
|
|||
from datetime import datetime
|
||||
from subprocess import check_output
|
||||
|
||||
from jwebsite.content import Content
|
||||
|
||||
|
||||
def git_creation_date(content: Content) -> datetime:
|
||||
git_dir = check_output(["git", "rev-parse", "--show-toplevel"], encoding="utf-8")
|
||||
git_dir = git_dir.strip()
|
||||
log = check_output(
|
||||
[
|
||||
"git",
|
||||
"log",
|
||||
"--pretty=format:%ad",
|
||||
"--date=iso-strict",
|
||||
"--diff-filter=A",
|
||||
"--",
|
||||
str(content.path.relative_to(git_dir)),
|
||||
],
|
||||
encoding="utf-8",
|
||||
)
|
||||
log_lines = log.splitlines()
|
||||
if len(log_lines) == 0:
|
||||
return datetime.now()
|
||||
|
||||
return datetime.fromisoformat(log_lines[0])
|
||||
|
|
@ -6,6 +6,7 @@ from jinja2.environment import Environment
|
|||
from jinja2.loaders import FileSystemLoader
|
||||
|
||||
from jwebsite.content import ContentDirectory
|
||||
from jwebsite.git import git_creation_date
|
||||
|
||||
|
||||
class Site:
|
||||
|
|
@ -13,7 +14,7 @@ class Site:
|
|||
self.__root_directory = root_directory
|
||||
self.__output_directory = root_directory / "build"
|
||||
self.__environment = Environment(loader=FileSystemLoader(searchpath=root_directory / "src"))
|
||||
self.__environment.filters.update({"output": self.__output})
|
||||
self.__environment.filters.update({"output": self.__output, "git_creation_date": git_creation_date})
|
||||
self.__content = ContentDirectory(root_directory / "content")
|
||||
|
||||
@property
|
||||
|
|
|
|||
Loading…
Reference in New Issue