Fix resolve_ref()

This commit is contained in:
Kovid Goyal 2022-08-20 11:29:40 +05:30
parent ea8f223298
commit cd35f92607
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 20 additions and 10 deletions

View File

@ -57,16 +57,19 @@ def resolve_ref(ref: str, website_url: Callable[[str], str] = website_url) -> st
href = m['ref'].get(ref, '') href = m['ref'].get(ref, '')
if href: if href:
return href return href
if ref.startswith('conf-'): if ref.startswith('conf-kitty-'):
base = 'generated/' + ref.rpartition('-')[0] href = f'{website_url("conf")}#{ref}'
href = f'{website_url(base)}#{ref}' elif ref.startswith('conf-kitten-'):
parts = ref.split('-')
href = website_url("kittens/" + parts[2] + f'#{ref}')
elif ref.startswith('at_'): elif ref.startswith('at_'):
href = f'{website_url("generated/cli-kitty-at")}#{ref}' base = ref.split('_', 1)[1]
href = website_url("remote-control/#at_" + base.replace('_', '-'))
elif ref.startswith('action-group-'): elif ref.startswith('action-group-'):
href = f'{website_url("generated/actions")}#{ref}' href = f'{website_url("actions")}#{ref}'
elif ref.startswith('action-'): elif ref.startswith('action-'):
frag = ref.partition('-')[-1].replace('_', '-') frag = ref.partition('-')[-1].replace('_', '-')
href = f'{website_url("generated/actions")}#{frag}' href = f'{website_url("actions")}#{frag}'
return href return href

View File

@ -78,10 +78,17 @@ class TestBuild(BaseTest):
def test_docs_url(self): def test_docs_url(self):
from kitty.utils import docs_url from kitty.utils import docs_url
p = partial(docs_url, local_docs_root='/docs') p = partial(docs_url, local_docs_root='/docs')
self.ae(p(), 'file:///docs/index.html')
self.ae(p('conf'), 'file:///docs/conf.html') def t(x, e):
self.ae(p('kittens/ssh#frag'), 'file:///docs/kittens/ssh.html#frag') self.ae(p(x), 'file:///docs/' + e)
self.ae(p('#ref=confloc'), 'file:///docs/conf.html#confloc') t('', 'index.html')
t('conf', 'conf.html')
t('kittens/ssh#frag', 'kittens/ssh.html#frag')
t('#ref=confloc', 'conf.html#confloc')
t('#ref=conf-kitty-fonts', 'conf.html#conf-kitty-fonts')
t('#ref=conf-kitten-ssh-xxx', 'kittens/ssh.html#conf-kitten-ssh-xxx')
t('#ref=at_close_tab', 'remote-control.html#at_close-tab')
t('#ref=action-copy', 'actions.html#copy')
def main() -> None: def main() -> None: