Skip to content

Commit

Permalink
Add option to open topic-box in same tab (#1059)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarcia360 authored Apr 5, 2024
1 parent 125eede commit af474c8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/source/examples/panel-box.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Syntax
Options
-------

The ``topic-box`` directive supports the following options:
The ``panel-box`` directive supports the following options:

.. list-table::
:widths: 20 20 10 20 30
Expand Down
31 changes: 31 additions & 0 deletions docs/source/examples/topic-box.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ The ``topic-box`` directive supports the following options:
-
- getting-started
- Relative link or external URL for the call to action. Do not use leading and trailing ("/") symbols to define relative links. (e.g. instead of ``/getting-started/``, use ``getting-started``).
* - ``link_target``
- string
-
- auto
- Defines if the link should be opened in a new tab or not. Available values: `auto`, `_blank`, `_self`. Defaults to `auto`.
* - ``anchor``
- string
-
Expand Down Expand Up @@ -137,6 +142,32 @@ Results in:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.


Topic with external link (same tab)
...................................

Using:

.. code-block:: rst
.. topic-box::
:title: Lorem Ipsum
:link: https://scylladb.com
:link_target: _self
:anchor: Lorem ipsum
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Results in:

.. topic-box::
:title: Lorem Ipsum
:link: https://scylladb.com
:link_target: _self
:anchor: Lorem ipsum

Lorem ipsum dolor sit amet, consectetur adipiscing elit.


Topic with horizontal scroll (mobile)
.....................................

Expand Down
24 changes: 13 additions & 11 deletions sphinx_scylladb_theme/extensions/topic_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class TopicBox(Directive):
option_spec = {
"title": directives.unchanged_required,
"link": directives.path,
"link_target": directives.path,
"anchor": directives.path,
"icon": directives.path,
"icon_color": directives.path,
Expand All @@ -24,20 +25,21 @@ def run(self):
container_class_name = self.options.get("class", "").replace(",", " ")

link = self.options.get("link")
link_target = self.options.get("link_target", "auto")
link_template = """
<div class="{class_name} {container_class_name}">
<div class="card">
"""
if is_url(link):
link_template = """
<div class="cell {class_name} {container_class_name}">
<a class="card" href="{link}" target="_blank">
"""
elif link:
link_template = """
<div class="cell {class_name} {container_class_name}">
<a class="card" href="{link}">
"""
if link:
target_attr = ''
if link_target == "_blank":
target_attr = 'target="_blank"'
elif link_target == 'auto' and is_url(link):
target_attr = 'target="_blank"'
link_template = f"""
<div class="cell {class_name} {container_class_name}">
<a class="card" href="{link}" {target_attr}>
"""

html_tag_open = generate_template(
link_template,
Expand Down Expand Up @@ -84,7 +86,7 @@ def run(self):
<i class="fa fa-external-link" aria-hidden="true"></i>
</div>
"""
if is_url(link)
if target_attr == 'target="_blank"'
else """
<div class="{class_name}__anchor">{anchor}</div>
""",
Expand Down

0 comments on commit af474c8

Please sign in to comment.