Skip to content

Commit 34baa98

Browse files
authored
Add external links icons to sidebar and topic boxes (#231)
* Add external links icons to sidebar and topic boxes * Replace topic box link icon
1 parent 7432684 commit 34baa98

File tree

10 files changed

+91
-40
lines changed

10 files changed

+91
-40
lines changed

docs/source/contribute/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Contribute
99
Contribute to the Sphinx Theme <contribute-theme>
1010
upgrade/index
1111
api/sphinx_scylladb_theme
12+
Source Code <https://github.com/scylladb/sphinx-scylladb-theme>
1213

1314
We are always looking for those who want to help and appreciate any contribution we can get.
1415

@@ -17,4 +18,4 @@ Before you can contribute to Scylla for the first time, you should download, pri
1718
There are two ways to contribute to Scylla Docs:
1819

1920
* :doc:`Contribute to the Documentation <contribute-docs>` - by writing new or changing existing Documentation.
20-
* :doc:`Contribute to the Sphinx Theme <contribute-theme>` - this is the CSS for our docs website.
21+
* :doc:`Contribute to the Sphinx Theme <contribute-theme>` - this is the CSS for our docs website.

docs/source/examples/topic-box.rst

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ The ``topic-box`` directive supports the following options:
3636
- Topic box title.
3737
* - ``icon``
3838
- string
39-
-
39+
-
4040
- fa fa-home
41-
- A list of CSS classes to render icons, separated by comma or space.
41+
- A list of CSS classes to render icons, separated by comma or space.
4242
* - ``image``
4343
- string
4444
-
@@ -108,6 +108,30 @@ Results in:
108108

109109
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
110110

111+
Topic with external link
112+
........................
113+
114+
Using:
115+
116+
.. code-block:: rst
117+
118+
.. topic-box::
119+
:title: Lorem Ipsum
120+
:link: https://scylladb.com
121+
:anchor: Lorem ipsum
122+
123+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
124+
125+
Results in:
126+
127+
.. topic-box::
128+
:title: Lorem Ipsum
129+
:link: https://scylladb.com
130+
:anchor: Lorem ipsum
131+
132+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
133+
134+
111135
Topic with horizontal scroll (mobile)
112136
.....................................
113137

poetry.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sphinx_scylladb_theme/breadcrumbs.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<div class="breadcrumbs">
22
<span class="bread__item"
3-
><a href="{{ pathto(master_doc) }}" class="bread__highlight"> <i class="fas fa-home"></i> {{ project }}</a></span
3+
><a href="{{ pathto(master_doc) }}" class="bread__highlight">
4+
<i class="fas fa-home"></i> {{ project }}</a
5+
></span
46
>
57
{% for doc in parents %}
68
<span class="bread__item"
7-
><a href="{{ doc.spannk|e }}">{{ doc.title }}</a></span
9+
><a href="{{ doc.link|e }}">{{ doc.title }}</a></span
810
>
911
{% endfor %}
1012
<span class="bread__item bread__item--last">{{ title }}</span>

sphinx_scylladb_theme/extensions/topic_box.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from docutils import nodes
55
from docutils.parsers.rst import Directive, directives
66

7-
from .utils import generate_template
7+
from .utils import generate_template, is_url
88

99

1010
class TopicBox(Directive):
@@ -24,16 +24,23 @@ def run(self):
2424
container_class_name = self.options.get("class", "").replace(",", " ")
2525

2626
link = self.options.get("link")
27-
html_tag_open = generate_template(
27+
link_template = """
28+
<div class="{class_name} {container_class_name}">
29+
<div class="card">
2830
"""
31+
if is_url(link):
32+
link_template = """
33+
<div class="cell {class_name} {container_class_name}">
34+
<a class="card" href="{link}" target="_blank">
35+
"""
36+
elif link:
37+
link_template = """
2938
<div class="cell {class_name} {container_class_name}">
3039
<a class="card" href="{link}">
3140
"""
32-
if link
33-
else """
34-
<div class="{class_name} {container_class_name}">
35-
<div class="card">
36-
""",
41+
42+
html_tag_open = generate_template(
43+
link_template,
3744
class_name=class_name,
3845
container_class_name=container_class_name,
3946
link=link,
@@ -73,8 +80,12 @@ def run(self):
7380
anchor = (
7481
generate_template(
7582
"""
76-
<div class="{class_name}__anchor">{anchor}</div>
77-
""",
83+
<div class="{class_name}__anchor">{anchor} <i class="fa fa-external-link" aria-hidden="true"></i></div>
84+
"""
85+
if is_url(link)
86+
else """
87+
<div class="{class_name}__anchor">{anchor}</div>
88+
""",
7889
class_name=class_name,
7990
anchor=anchor,
8091
)

sphinx_scylladb_theme/static/css/main.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/css/base/_reset.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ a {
1818
color: $color-typography-base-link;
1919
}
2020

21+
a.reference:after {
22+
font-family: $font-icons-family;
23+
font-size: $font-smallest;
24+
padding: 0 4px;
25+
}
26+
27+
a.reference.external:after {
28+
content: "\f08e";
29+
}
30+
31+
a.reference.download:after {
32+
content: "\f019";
33+
}
34+
2135
a:hover {
2236
color: $color-typography-base-link;
2337
font-weight: 500;

src/css/components/_content.scss

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,6 @@
4747
margin-bottom: $gap;
4848
}
4949

50-
.reference:after {
51-
font-family: $font-icons-family;
52-
font-size: $font-smallest;
53-
padding: 0 4px;
54-
}
55-
56-
.reference.external:after {
57-
content: "\f08e";
58-
}
59-
60-
.reference.download:after {
61-
content: "\f019";
62-
}
63-
6450
.section {
6551
margin-top: -$header-height;
6652
padding-top: $header-height;

tests/extensions/test_topic_box.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@
7171
<div class="topic-box__body">
7272
""",
7373
],
74+
[
75+
[],
76+
{"title": "Lorem Ipsum", "link": "https://test.local"},
77+
["Content"],
78+
"""
79+
<div class="cell topic-box ">
80+
<a class="card" href="https://test.local" target="_blank">
81+
<div class="topic-box__head">
82+
<h3 class="topic-box__title">Lorem Ipsum</h3>
83+
</div>
84+
<div class="topic-box__body">
85+
""",
86+
],
7487
]
7588

7689

tests/test_sphinx_scylladb_theme.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ def test_override_smv_latest_version_env():
2626
def test_override_rst_epilog():
2727
config = ConfigStub()
2828
config.rst_epilog = "|a| raw:: html"
29-
assert "|v| raw:: html" in override_rst_epilog(config)
30-
assert "|x| raw:: html" in override_rst_epilog(config)
29+
assert "|v| replace:: :raw-html:" in override_rst_epilog(config)
30+
assert "|x| replace:: :raw-html:" in override_rst_epilog(config)

0 commit comments

Comments
 (0)