upd
This commit is contained in:
parent
5ff8b7bd17
commit
d557bce477
3 changed files with 26 additions and 9 deletions
|
@ -18,12 +18,13 @@ def main():
|
|||
parser.add_argument('-t' , '--template', action='store', help="Template directory. By default workdir/template")
|
||||
parser.add_argument('-o', '--out', action='store', help="Output directory. By default workdir/generated_out")
|
||||
parser.add_argument('-f', '--force', action='store_true', default=False, help="Force overwrite out dir")
|
||||
parser.add_argument('-s', '--server', action='store_true', default=False, help="Run server")
|
||||
parser.add_argument('-d', '--draft', action='store_true', default=False, help="Generate drafts")
|
||||
parser.add_argument('-s', '--server', action='store_true', default=False, help="Run server, implies drafts")
|
||||
|
||||
args = Arguments()
|
||||
parser.parse_args(namespace=args)
|
||||
|
||||
target = compile(args.workdir, args.template, args.out, args.force)
|
||||
target = compile(args.workdir, args.template, args.out, args.force, args.draft or args.server)
|
||||
print("Saved to", target)
|
||||
if args.server:
|
||||
import server
|
||||
|
|
|
@ -4,7 +4,7 @@ from json import loads
|
|||
from os import sep
|
||||
from os.path import join
|
||||
from typing import Any, Dict
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from git import Repo
|
||||
|
||||
@dataclass
|
||||
|
@ -12,6 +12,7 @@ class Article:
|
|||
id: str
|
||||
title: str
|
||||
summary: str
|
||||
draft: bool
|
||||
|
||||
revisions: int
|
||||
created_by: str
|
||||
|
@ -51,11 +52,20 @@ class Article:
|
|||
print(f"Article {id} has no content")
|
||||
|
||||
commits = list(repo.iter_commits(paths=filename))
|
||||
kwargs['draft'] = 'draft' in kwargs or len(commits) == 0
|
||||
|
||||
if not kwargs['draft']:
|
||||
kwargs['revisions'] = len(commits)
|
||||
kwargs['created_by'] = commits[-1].author.name
|
||||
kwargs['created_at'] = commits[-1].authored_datetime
|
||||
kwargs['created_at'] = commits[-1].authored_datetime.astimezone(timezone.utc)
|
||||
kwargs['modified_by'] = commits[0].author.name
|
||||
kwargs['modified_at'] = commits[0].authored_datetime
|
||||
kwargs['modified_at'] = commits[0].authored_datetime.astimezone(timezone.utc)
|
||||
else:
|
||||
kwargs['revisions'] = 0
|
||||
kwargs['created_by'] = "Draft"
|
||||
kwargs['created_at'] = datetime.now().astimezone(timezone.utc)
|
||||
kwargs['modified_by'] = "Draft"
|
||||
kwargs['modified_at'] = datetime.now().astimezone(timezone.utc)
|
||||
|
||||
return Article(html_content=content, custom=custom, **kwargs)
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ from minify_html import minify
|
|||
from article import Article, Page, Site
|
||||
from template import TemplateEnvironment
|
||||
|
||||
def compile(work_directory: str, template_directory: str=None, target_directory: str=None, force: bool=False) -> str:
|
||||
def compile(work_directory: str, template_directory: str=None, target_directory: str=None, force: bool=False, render_drafts: bool=False) -> str:
|
||||
if not isdir(work_directory):
|
||||
raise FileNotFoundError("One or more of the directories you specified do not exist")
|
||||
|
||||
|
@ -57,6 +57,10 @@ def compile(work_directory: str, template_directory: str=None, target_directory:
|
|||
id = fn.split('.')[0]
|
||||
article = Article.get(repo, id)
|
||||
|
||||
if article.draft and not render_drafts:
|
||||
print(f"Draft {id} not rendered")
|
||||
continue
|
||||
|
||||
html = template.process_article(article)
|
||||
html = minify(html)
|
||||
|
||||
|
@ -66,6 +70,8 @@ def compile(work_directory: str, template_directory: str=None, target_directory:
|
|||
|
||||
articles += [article]
|
||||
|
||||
articles.sort(key=lambda a : a.created_at, reverse=True)
|
||||
|
||||
page_index = 1
|
||||
pages = ceil(len(articles) / articles_per_page)
|
||||
while len(articles) > 0:
|
||||
|
|
Reference in a new issue