Compare commits
No commits in common. "e3772d63a3143d9bbbb3af56f11f77e3de82a202" and "6913498941ea13c901dadc1f1d292bfd5cb74bfd" have entirely different histories.
e3772d63a3
...
6913498941
3 changed files with 56 additions and 81 deletions
|
@ -1,35 +1,30 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
class DataRange():
|
||||||
class DataRange:
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.start = ""
|
self.start = ""
|
||||||
self.end = ""
|
self.end = ""
|
||||||
|
|
||||||
|
class Address():
|
||||||
class Address:
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.region = ""
|
self.region = ""
|
||||||
self.country = ""
|
self.country = ""
|
||||||
|
|
||||||
|
class Organisation():
|
||||||
class Organisation:
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.name = ""
|
self.name = ""
|
||||||
self.address = Address()
|
self.address = Address()
|
||||||
|
|
||||||
|
class CvPosition():
|
||||||
class CvPosition:
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.role = ""
|
self.role = ""
|
||||||
self.organisation = Organisation()
|
self.organisation = Organisation()
|
||||||
self.date_range = DateRange()
|
self.date_range = DateRange()
|
||||||
|
|
||||||
|
|
||||||
class AcademicEnrolement(CvPosition):
|
class AcademicEnrolement(CvPosition):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -37,30 +32,26 @@ class AcademicEnrolement(CvPosition):
|
||||||
self.program = ""
|
self.program = ""
|
||||||
self.grade = ""
|
self.grade = ""
|
||||||
|
|
||||||
|
class Award():
|
||||||
class Award:
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.year = ""
|
self.year = ""
|
||||||
self.role = ""
|
self.role = ""
|
||||||
self.title = ""
|
self.title = ""
|
||||||
self.event = ""
|
self.event = ""
|
||||||
|
|
||||||
|
class CvSection():
|
||||||
class CvSection:
|
|
||||||
|
|
||||||
def __init__():
|
def __init__():
|
||||||
self.title = ""
|
self.title = ""
|
||||||
|
|
||||||
|
|
||||||
class CvRoles(CvSection):
|
class CvRoles(CvSection):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.roles = []
|
self.roles = []
|
||||||
|
|
||||||
|
class Author():
|
||||||
class Author:
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.first_name = ""
|
self.first_name = ""
|
||||||
|
@ -69,32 +60,28 @@ class Author:
|
||||||
self.orcid = ""
|
self.orcid = ""
|
||||||
self.website = ""
|
self.website = ""
|
||||||
|
|
||||||
|
class Event():
|
||||||
class Event:
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.title = ""
|
self.title = ""
|
||||||
self.address = Address()
|
self.address = Address()
|
||||||
self.date = ""
|
self.date = ""
|
||||||
|
|
||||||
|
class BibliographicItem():
|
||||||
class BibliographicItem:
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.authors = []
|
self.authors = []
|
||||||
self.title = []
|
self.title = []
|
||||||
|
|
||||||
|
class TeachingRole():
|
||||||
class TeachingRole:
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.title = ""
|
self.title = ""
|
||||||
self.course = ""
|
self.course = ""
|
||||||
self.institute = Organisation()
|
self.institute = Organisation()
|
||||||
|
|
||||||
|
class Cv():
|
||||||
class Cv:
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.sections: list[CvSection] = []
|
self.sections: list[CvSection] = []
|
||||||
|
|
||||||
|
|
|
@ -3,18 +3,15 @@ import argparse
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from .site_generator import generate, Config
|
from .site_generator import SiteGenerator
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def generate(source_dir:Path, build_dir: Path):
|
||||||
|
|
||||||
def cli_generate(source_dir: Path, build_dir: Path):
|
generator = SiteGenerator(source_dir, build_dir)
|
||||||
|
generator.run()
|
||||||
config = Config(source_dir.resolve(), build_dir.resolve())
|
|
||||||
|
|
||||||
generate(config)
|
|
||||||
|
|
||||||
|
|
||||||
def main_cli():
|
def main_cli():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
@ -23,12 +20,11 @@ def main_cli():
|
||||||
help="Path to the build output",
|
help="Path to the build output",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--source_dir", type=Path, default=Path(), help="Site source directory"
|
"--source_dir", type=Path, default=Path(),
|
||||||
)
|
help="Site source directory")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
cli_generate(args.source_dir, args.build_dir)
|
generate(args.source_dir, args.build_dir)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main_cli()
|
main_cli()
|
||||||
|
|
|
@ -1,59 +1,51 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from dataclasses import dataclass
|
|
||||||
|
|
||||||
from markdown_it import MarkdownIt
|
from markdown_it import MarkdownIt
|
||||||
|
|
||||||
|
class SiteGenerator():
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
def __init__(self, source_dir: Path,
|
||||||
class Config:
|
build_dir: Path):
|
||||||
source_dir: Path
|
self.source_dir = source_dir.resolve()
|
||||||
build_dir: Path
|
self.build_dir = build_dir.resolve()
|
||||||
|
self.parser = MarkdownIt()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
|
||||||
def _read_if_exists(path: Path) -> str:
|
header_src = ""
|
||||||
if path.exists():
|
footer_src = ""
|
||||||
with open(path, "r", encoding="utf-8") as f:
|
|
||||||
return f.read()
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
header_path = self.source_dir / "templates/header.html"
|
||||||
|
footer_path = self.source_dir / "templates/footer.html"
|
||||||
|
if header_path.exists():
|
||||||
|
with open(header_path, 'r', encoding='utf-8') as f:
|
||||||
|
header_src = f.read()
|
||||||
|
|
||||||
def _replace_content(src: Path, dst: Path):
|
if footer_path.exists():
|
||||||
if src.exists():
|
with open(footer_path, 'r', encoding='utf-8') as f:
|
||||||
if dst.exists():
|
footer_src = f.read()
|
||||||
shutil.rmtree(dst)
|
|
||||||
shutil.copytree(src, dst)
|
|
||||||
|
|
||||||
|
static_dir = self.source_dir / "static"
|
||||||
|
build_static_dir = self.build_dir / "static"
|
||||||
|
if static_dir.exists():
|
||||||
|
|
||||||
def _write_file(path: Path, content: str):
|
if build_static_dir.exists():
|
||||||
os.makedirs(path.parent, exist_ok=True)
|
shutil.rmtree(build_static_dir)
|
||||||
with open(path, "w", encoding="utf-8") as f:
|
|
||||||
f.write(content)
|
|
||||||
|
|
||||||
|
shutil.copytree(static_dir, self.build_dir / "static")
|
||||||
|
|
||||||
def _read_file(path: Path) -> str:
|
for md_file in self.source_dir.glob('**/*.md'):
|
||||||
with open(path, "r", encoding="utf-8") as f:
|
with open(md_file, 'r', encoding='utf-8') as f:
|
||||||
return f.read()
|
md_src = f.read()
|
||||||
|
|
||||||
|
md_dir = md_file.parent.relative_to(self.source_dir)
|
||||||
|
html_path = self.build_dir / md_dir / (str(md_file.stem) + ".html")
|
||||||
|
os.makedirs(html_path.parent, exist_ok=True)
|
||||||
|
|
||||||
def generate(config: Config):
|
html_src = self.parser.render(md_src)
|
||||||
|
with open(html_path, 'w', encoding='utf-8') as f:
|
||||||
|
f.write(header_src + html_src + footer_src)
|
||||||
|
|
||||||
static_dir = config.source_dir / "static"
|
|
||||||
build_static_dir = config.build_dir / "static"
|
|
||||||
_replace_content(static_dir, build_static_dir)
|
|
||||||
|
|
||||||
template_dir = config.source_dir / "templates"
|
|
||||||
header = _read_if_exists(template_dir / "header.html")
|
|
||||||
footer = _read_if_exists(template_dir / "footer.html")
|
|
||||||
|
|
||||||
parser = MarkdownIt()
|
|
||||||
sources = config.source_dir.glob("**/*.md")
|
|
||||||
|
|
||||||
for source in sources:
|
|
||||||
source_dir = source.parent.relative_to(config.source_dir)
|
|
||||||
output_path = config.build_dir / source_dir / (str(source.stem) + ".html")
|
|
||||||
|
|
||||||
content = _read_file(source)
|
|
||||||
output = parser.render(content)
|
|
||||||
_write_file(output_path, header + output + footer)
|
|
||||||
|
|
Loading…
Reference in a new issue