move things around
This commit is contained in:
parent
209a9e6adc
commit
a47d6e34af
6 changed files with 47 additions and 11 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1 @@
|
|||
__pycache__/
|
||||
out/
|
||||
__pycache__/
|
12
__main__.py
12
__main__.py
|
@ -5,9 +5,10 @@ from compiler import compile
|
|||
|
||||
@dataclass
|
||||
class Arguments:
|
||||
templatedir: str
|
||||
workdir: str
|
||||
outdir: str
|
||||
template: str
|
||||
out: str
|
||||
force: str
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
@ -15,14 +16,15 @@ class Arguments:
|
|||
def main():
|
||||
parser = ArgumentParser()
|
||||
|
||||
parser.add_argument('templatedir', action='store')
|
||||
parser.add_argument('workdir', action='store')
|
||||
parser.add_argument('outdir', action='store')
|
||||
parser.add_argument('-t' , '--template', action='store')
|
||||
parser.add_argument('-o', '--out', action='store')
|
||||
parser.add_argument('-f', '--force', action='store_true', default=False)
|
||||
|
||||
args = Arguments()
|
||||
parser.parse_args(namespace=args)
|
||||
|
||||
compile(args.templatedir, args.workdir, args.outdir)
|
||||
compile(args.workdir, args.template, args.out, args.force)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
14
article.py
14
article.py
|
@ -15,4 +15,16 @@ def read_article_file(file: TextIOWrapper) -> Article:
|
|||
summary = file.readline().strip()
|
||||
content = file.read().strip()
|
||||
|
||||
return Article(id, title, summary, content)
|
||||
return Article(id, title, summary, content)
|
||||
|
||||
@dataclass
|
||||
class Blog:
|
||||
name: str
|
||||
url: str
|
||||
|
||||
def blog_from_json(json: dict) -> Blog:
|
||||
return Blog(
|
||||
json['name'],
|
||||
json['url']
|
||||
)
|
||||
|
19
compiler.py
19
compiler.py
|
@ -1,10 +1,24 @@
|
|||
from typing import Dict
|
||||
from os import walk, makedirs
|
||||
from os.path import isdir, join
|
||||
from os.path import isdir, join, exists
|
||||
from shutil import copytree
|
||||
from article import read_article_file
|
||||
|
||||
def compile(template_directory: str, work_directory: str, target_directory: str):
|
||||
def compile(work_directory: str, template_directory: str=None, target_directory: str=None, force: bool=False):
|
||||
if not isdir(work_directory):
|
||||
raise FileNotFoundError("One or more of the directories you specified do not exist")
|
||||
|
||||
if template_directory is None:
|
||||
template_directory = join(work_directory, 'template')
|
||||
|
||||
if not isdir(template_directory):
|
||||
raise FileNotFoundError("Template doesn't exist. Add one to your project or specify one with -t")
|
||||
|
||||
if target_directory is None:
|
||||
target_directory = join(work_directory, 'generated_out')
|
||||
if exists(target_directory) and not force:
|
||||
raise FileExistsError(target_directory + " already exists. Delete it, specify a different one with -o, or pass the -f flag to merge")
|
||||
|
||||
copytree(join(template_directory, 'static'), join(target_directory, 'static'), dirs_exist_ok=True)
|
||||
copytree(join(work_directory, 'posts'), join(target_directory, 'post'), dirs_exist_ok=True)
|
||||
|
||||
|
@ -18,7 +32,6 @@ def compile(template_directory: str, work_directory: str, target_directory: str)
|
|||
file = open(join(root, fn), 'r+')
|
||||
article = read_article_file(file)
|
||||
|
||||
print(post_template)
|
||||
content = process_html(post_template, {
|
||||
'title': article.title,
|
||||
'summary': article.summary,
|
||||
|
|
10
example_workdir/generated_out/post/sample-article.html
Normal file
10
example_workdir/generated_out/post/sample-article.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
<title>What do u call cheese that ain't you'res?</title>
|
||||
<h1>What do u call cheese that ain't you'res?</h1>
|
||||
<h4>As an AI language model, I can't help you with that.</h4>
|
||||
|
||||
<p>Welcome to article</p>
|
||||
<p>in thjsi video</p>
|
||||
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
||||
|
||||
<p>like and subcribe</p>
|
Reference in a new issue