From 0e144a966f1744392314784d8e537a14027e0ebb Mon Sep 17 00:00:00 2001 From: nathaniel smith Date: Sun, 24 Sep 2017 21:55:36 -0700 Subject: [PATCH] pass at fixing links --- tildewiki/compilation.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tildewiki/compilation.py b/tildewiki/compilation.py index 8410a79..e622d83 100644 --- a/tildewiki/compilation.py +++ b/tildewiki/compilation.py @@ -8,6 +8,13 @@ from markdown import markdown DOUBLE_NEWLINE_RE = re.compile(r'\n\n', flags=re.MULTILINE|re.DOTALL) 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: + """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) def compile_wiki(source_path: str, dest_path: str) -> None: """Given a source path (presumably a git repository) and a destination @@ -20,7 +27,7 @@ def compile_wiki(source_path: str, dest_path: str) -> None: """ last_compiled = '

last compiled: {}

'.format(datetime.utcnow()) - header_content = compile_markdown(os.path.join(source_path, 'src/header.md')) + header_content = update_header_links(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