[PDF Download] Add links to sidebars

This commit is contained in:
Gabriel Hottiger 2019-07-04 13:28:02 +02:00
parent d89eadcbd9
commit 431ded7a54
3 changed files with 23 additions and 9 deletions

View file

@ -281,6 +281,7 @@ def build(config, rel_source, destination, **options):
sort=config.sort,
priority=config.priority,
invert=config.invert,
pdf_file=config.pdf_file,
)
# Get root ref.

View file

@ -9,7 +9,7 @@
{%- if versions.tags %}
<dl>
<dt>Tags</dt>
{%- for name, url in versions.tags %}
{%- for name, url, pdf_url in versions.tags %}
<dd><a href="{{ url }}">{{ name }}</a></dd>
{%- endfor %}
</dl>
@ -17,11 +17,22 @@
{%- if versions.branches %}
<dl>
<dt>Branches</dt>
{%- for name, url in versions.branches %}
{%- for name, url, pdf_url in versions.branches %}
<dd><a href="{{ url }}">{{ name }}</a></dd>
{%- endfor %}
</dl>
{%- endif %}
{%- if versions.pdf_file %}
<dl>
<dt>PDF</dt>
{%- for name, url, pdf_url in versions.tags %}
<dd><a href="{{ pdf_url }}" download>{{ name }}</a></dd>
{%- endfor %}
{%- for name, url, pdf_url in versions.branches %}
<dd><a href="{{ pdf_url }}" download>{{ name }}</a></dd>
{%- endfor %}
</dl>
{%- endif %}
</div>
</div>
{% elif html_theme == 'rasabaster' %}
@ -37,7 +48,7 @@
{%- if versions.tags %}
<p>tags</p>
<div class="dropdown-content">
{%- for name, url in versions.tags %}
{%- for name, url, pdf_url in versions.tags %}
<a href="{{ url }}">{{ name }}</a>
{%- endfor %}
</div>
@ -45,7 +56,7 @@
{%- if versions.branches %}
<p>branches</p>
<div class="dropdown-content">
{%- for name, url in versions.branches %}
{%- for name, url, pdf_url in versions.branches %}
<a href="{{ url }}">{{ name }}</a>
{%- endfor %}
</div>

View file

@ -1,6 +1,7 @@
"""Collect and sort version strings."""
import re
import os
RE_SEMVER = re.compile(r'^v?V?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?([\w.+-]*)$')
@ -98,7 +99,7 @@ class Versions(object):
:ivar dict recent_tag_remote: Most recently committed tag.
"""
def __init__(self, remotes, sort=None, priority=None, invert=False):
def __init__(self, remotes, sort=None, priority=None, invert=False, pdf_file=None):
"""Constructor.
:param iter remotes: Output of routines.gather_git_info(). Converted to list of dicts as instance variable.
@ -122,6 +123,7 @@ class Versions(object):
self.recent_branch_remote = None
self.recent_remote = None
self.recent_tag_remote = None
self.pdf_file = pdf_file
# Sort one or more times.
if sort:
@ -194,13 +196,13 @@ class Versions(object):
@property
def branches(self):
"""Return list of (name and urls) only branches."""
return [(r['name'], self.vpathto(r['name'])) for r in self.remotes if r['kind'] == 'heads']
"""Return list of (name and urls, pdf_urls) only branches."""
return [(r['name'], self.vpathto(r['name']), os.path.dirname(self.vpathto(r['name'])) + "/_static/" + self.pdf_file) for r in self.remotes if r['kind'] == 'heads']
@property
def tags(self):
"""Return list of (name and urls) only tags."""
return [(r['name'], self.vpathto(r['name'])) for r in self.remotes if r['kind'] == 'tags']
"""Return list of (name and urls, pdf_urls) only tags."""
return [(r['name'], self.vpathto(r['name']), os.path.dirname(self.vpathto(r['name'])) + "/_static/" + self.pdf_file) for r in self.remotes if r['kind'] == 'tags']
def vhasdoc(self, other_version):
"""Return True if the other version has the current document. Like Sphinx's hasdoc().