update search
This commit is contained in:
+50
-2
@@ -21,8 +21,15 @@ import asyncio
|
||||
from nicegui import ui, app
|
||||
import re
|
||||
|
||||
app.add_static_files('/images', 'docs_md/articles/images')
|
||||
app.add_static_files('/document/images', 'docs_md/articles/images')
|
||||
_current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
_articles_dir = os.path.abspath(os.path.join(_current_dir, '..', 'docs_md', 'articles'))
|
||||
_images_dir = os.path.join(_articles_dir, 'images')
|
||||
_img_dir = os.path.join(_articles_dir, 'img')
|
||||
|
||||
app.add_static_files('/images', _images_dir)
|
||||
app.add_static_files('/document/images', _images_dir)
|
||||
app.add_static_files('/img', _img_dir)
|
||||
app.add_static_files('/document/img', _img_dir)
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
@@ -821,6 +828,45 @@ def search_page() -> None: # build UI
|
||||
run_conv_button = ui.button('Run conversion', on_click=lambda: asyncio.create_task(run_dtm_handler()), color='primary')
|
||||
|
||||
|
||||
def linkify_references(content: str, root: str = 'docs_md/articles') -> str:
|
||||
def replace_anatomy(match):
|
||||
raw_text = match.group(0)
|
||||
uuid = match.group(1)
|
||||
fm, _, _ = search_md.get_doc_by_id(root, uuid)
|
||||
if fm:
|
||||
title = fm.get('title') or fm.get('pageTitle') or uuid
|
||||
return f'[{title}](/document/{uuid})'
|
||||
return raw_text
|
||||
|
||||
anatomy_pattern = re.compile(r'(?:[a-zA-Z0-9\-]+/)?ANATOMY:([a-f0-9\-]{36})', re.IGNORECASE)
|
||||
content = anatomy_pattern.sub(replace_anatomy, content)
|
||||
|
||||
def replace_ddx(match):
|
||||
raw_text = match.group(0)
|
||||
uuid = match.group(1)
|
||||
fm, _, _ = search_md.get_doc_by_id(root, uuid)
|
||||
if fm:
|
||||
title = fm.get('title') or fm.get('pageTitle') or uuid
|
||||
return f'[{title}](/document/{uuid})'
|
||||
return raw_text
|
||||
|
||||
ddx_pattern = re.compile(r'DDX:([a-f0-9\-]{36})', re.IGNORECASE)
|
||||
content = ddx_pattern.sub(replace_ddx, content)
|
||||
|
||||
def replace_standard_links(match):
|
||||
label = match.group(1)
|
||||
uuid = match.group(3)
|
||||
fm, _, _ = search_md.get_doc_by_id(root, uuid)
|
||||
if fm:
|
||||
return f'[{label}](/document/{uuid})'
|
||||
return match.group(0)
|
||||
|
||||
markdown_link_pattern = re.compile(r'\[([^\]]+)\]\(((?:https?://app\.statdx\.com)?/document/[^/]+/([a-f0-9\-]{36}))\)')
|
||||
content = markdown_link_pattern.sub(replace_standard_links, content)
|
||||
|
||||
return content
|
||||
|
||||
|
||||
@ui.page('/document/{identifier}')
|
||||
def render_doc_page(identifier: str):
|
||||
ui.add_head_html('''
|
||||
@@ -899,6 +945,8 @@ def render_doc_page(identifier: str):
|
||||
''')
|
||||
|
||||
fm, content, path = search_md.get_doc_by_id('docs_md/articles', identifier)
|
||||
if fm and content:
|
||||
content = linkify_references(content, 'docs_md/articles')
|
||||
if not fm:
|
||||
with ui.column().classes('w-full items-center justify-center p-12 gap-4'):
|
||||
ui.icon('warning', size='4rem', color='negative')
|
||||
|
||||
Reference in New Issue
Block a user