This commit is contained in:
Kovid Goyal
2022-08-20 12:03:33 +05:30
parent b6760a59fa
commit e289f4959f
4 changed files with 36 additions and 26 deletions

View File

@@ -56,21 +56,21 @@ def resolve_ref(ref: str, website_url: Callable[[str], str] = website_url) -> st
m = ref_map()
href = m['ref'].get(ref, '')
if href:
return website_url(href)
if ref.startswith('conf-kitty-'):
href = f'{website_url("conf")}#{ref}'
pass
elif ref.startswith('conf-kitty-'):
href = f'conf#{ref}'
elif ref.startswith('conf-kitten-'):
parts = ref.split('-')
href = website_url("kittens/" + parts[2] + f'#{ref}')
href = "kittens/" + parts[2] + f'/#{ref}'
elif ref.startswith('at_'):
base = ref.split('_', 1)[1]
href = website_url("remote-control/#at_" + base.replace('_', '-'))
href = "remote-control/#at_" + base.replace('_', '-')
elif ref.startswith('action-group-'):
href = f'{website_url("actions")}#{ref}'
href = f'actions/#{ref}'
elif ref.startswith('action-'):
frag = ref.partition('-')[-1].replace('_', '-')
href = f'{website_url("actions")}#{frag}'
return href
href = f'actions/#{frag}'
return website_url(href)
def remove_markup(text: str) -> str:

View File

@@ -230,12 +230,14 @@ def read_kitty_resource(name: str, package_name: str = 'kitty') -> bytes:
return read_binary(package_name, name)
def website_url(doc_name: str = '') -> str:
def website_url(doc_name: str = '', website: str = 'https://sw.kovidgoyal.net/kitty/') -> str:
if doc_name:
doc_name = doc_name.rstrip('/')
if doc_name:
doc_name += '/'
return f'https://sw.kovidgoyal.net/kitty/{doc_name}'
base, _, frag = doc_name.partition('#')
base = base.rstrip('/')
if base:
base += '/'
doc_name = base + (f'#{frag}' if frag else '')
return website + doc_name
handled_signals: Set[int] = set()

View File

@@ -1071,11 +1071,14 @@ def safer_fork() -> int:
return pid
def docs_url(which: str = '', local_docs_root: str = '') -> str:
def docs_url(which: str = '', local_docs_root: Optional[str] = '') -> str:
from urllib.parse import quote
from .constants import local_docs, website_url
from .conf.types import resolve_ref
ld = local_docs_root or local_docs()
if local_docs_root is None:
ld = ''
else:
ld = local_docs_root or local_docs()
base, frag = which.partition('#')[::2]
base = base.strip('/')
if frag.startswith('ref='):

View File

@@ -77,18 +77,23 @@ class TestBuild(BaseTest):
def test_docs_url(self):
from kitty.utils import docs_url
p = partial(docs_url, local_docs_root='/docs')
from kitty.constants import website_url
def t(x, e):
self.ae(p(x), 'file:///docs/' + e)
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 run_tests(p, base, suffix='.html'):
def t(x, e):
self.ae(p(x), base + e)
t('', 'index.html' if suffix == '.html' else '')
t('conf', f'conf{suffix}')
t('kittens/ssh#frag', f'kittens/ssh{suffix}#frag')
t('#ref=confloc', f'conf{suffix}#confloc')
t('#ref=conf-kitty-fonts', f'conf{suffix}#conf-kitty-fonts')
t('#ref=conf-kitten-ssh-xxx', f'kittens/ssh{suffix}#conf-kitten-ssh-xxx')
t('#ref=at_close_tab', f'remote-control{suffix}#at_close-tab')
t('#ref=action-copy', f'actions{suffix}#copy')
run_tests(partial(docs_url, local_docs_root='/docs'), 'file:///docs/')
w = website_url()
run_tests(partial(docs_url, local_docs_root=None), w, '/')
def main() -> None: