link directly to the tool page title

instead of the top of the page
this is especially important on mobile where the top of the page is
taken up with the sidebar boilerplate
develop
myk002 2022-09-23 11:33:14 -07:00
parent 52011bde7b
commit 1cd5e8657a
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
1 changed files with 12 additions and 9 deletions

@ -115,20 +115,23 @@ class DFHackToolDirectiveBase(sphinx.directives.ObjectDescription):
required_arguments = 0
optional_arguments = 1
def get_name_or_docname(self):
if self.arguments:
return self.arguments[0]
else:
def get_tool_name_from_docname(self):
parts = self.env.docname.split('/')
if 'tools' in parts:
return '/'.join(parts[parts.index('tools') + 1:])
else:
return parts[-1]
def get_name_or_docname(self):
if self.arguments:
return self.arguments[0]
return self.get_tool_name_from_docname()
def add_index_entries(self, name) -> None:
docname = self.env.docname
anchor = self.get_tool_name_from_docname().replace('/', '-')
tags = self.env.domaindata['tag-repo']['doctags'][docname]
indexdata = (name, self.options.get('summary', ''), '', docname, '', 0)
indexdata = (name, self.options.get('summary', ''), '', docname, anchor, 0)
self.env.domaindata['all']['objects'].append(indexdata)
for tag in tags:
self.env.domaindata[tag]['objects'].append(indexdata)
@ -247,10 +250,10 @@ def tag_domain_merge_domaindata(self, docnames: List[str], otherdata: Dict) -> N
def tag_index_generate(self, docnames: Optional[Iterable[str]] = None) -> Tuple[List[Tuple[str, List[IndexEntry]]], bool]:
content = defaultdict(list)
for name, desc, _, docname, _, _ in self.domain.data['objects']:
for name, desc, _, docname, anchor, _ in self.domain.data['objects']:
first_letter = name[0].lower()
content[first_letter].append(
IndexEntry(name, 0, docname, '', '', '', desc))
IndexEntry(name, 0, docname, anchor, '', '', desc))
return (sorted(content.items()), False)
def register_index(app, tag, title):