From 11919ff3d048831fdbdacbefa0bc67e106af451a Mon Sep 17 00:00:00 2001 From: nathaniel smith Date: Sun, 24 Sep 2017 22:03:38 -0700 Subject: [PATCH] second pass --- tildewiki/compilation.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tildewiki/compilation.py b/tildewiki/compilation.py index e622d83..1a08040 100644 --- a/tildewiki/compilation.py +++ b/tildewiki/compilation.py @@ -10,11 +10,13 @@ HEADER_TITLE_RE = re.compile(r'(.*?)') TITLE_RE = re.compile(r'.*?') LINK_RE = re.compile(r'\/wiki') -def update_header_links(header_content:str) -> str: +def update_header_links(header_content:str, depth:int) -> str: """Given compiled header content, change absolute URLs in the header to be relative to the root URL. this is a dirty hack to save links during preview.""" - return re.sub(LINK_RE, '../wiki', header_content) + dots = os.path.join(*['..' for _ in range(depth)]) + repl = os.path.join(dots, wiki) + return re.sub(LINK_RE, repl, header_content) def compile_wiki(source_path: str, dest_path: str) -> None: """Given a source path (presumably a git repository) and a destination @@ -27,16 +29,16 @@ def compile_wiki(source_path: str, dest_path: str) -> None: """ last_compiled = '

last compiled: {}

'.format(datetime.utcnow()) - header_content = update_header_links(compile_markdown(os.path.join(source_path, 'src/header.md'))) + header_content = compile_markdown(os.path.join(source_path, 'src/header.md')) footer_content = last_compiled + compile_markdown(os.path.join(source_path, 'src/footer.md')) - # TODO fix any links in header/footer to work with preview path - articles_root = os.path.join(source_path, 'src/articles') toc_content = '{}\n