Skip to content

Commit 4c8a980

Browse files
MAINT: Add sphinx card configuration according to screen size (#259)
1 parent fca1ab9 commit 4c8a980

File tree

5 files changed

+77
-26
lines changed

5 files changed

+77
-26
lines changed

doc/source/conf.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
from datetime import datetime
44
import os
5-
from pathlib import Path
6-
from typing import List
75

8-
from bs4 import BeautifulSoup
9-
import requests
106
from sphinx.builders.latex import LaTeXBuilder
117

128
LaTeXBuilder.supported_image_types = ["image/png", "image/pdf", "image/svg+xml"]
@@ -23,10 +19,6 @@
2319
watermark,
2420
)
2521

26-
THIS_PATH = Path(__file__).parent.resolve()
27-
28-
EXAMPLE_PATH = (THIS_PATH / "examples" / "sphinx_examples").resolve()
29-
3022
# Project information
3123
project = "ansys_sphinx_theme"
3224
copyright = f"(c) {datetime.now().year} ANSYS, Inc. All rights reserved"
@@ -146,10 +138,24 @@
146138
notfound_context = {
147139
"body": generate_404(),
148140
}
141+
149142
notfound_no_urls_prefix = True
150143

144+
# ONLY FOR ANSYS-SPHINX-THEME
145+
146+
from pathlib import Path
147+
from typing import List
148+
149+
import requests
150+
151+
THIS_PATH = Path(__file__).parent.resolve()
152+
153+
EXAMPLE_PATH = (THIS_PATH / "examples" / "sphinx_examples").resolve()
151154

152-
def extract_example_links(archive_url: str, exclude_files: List[str]) -> List[str]:
155+
156+
def extract_example_links(
157+
archive_url: str, archive_base_url: str, exclude_files: List[str]
158+
) -> List[str]:
153159
"""
154160
Extract example links from a specific URL.
155161
@@ -166,13 +172,16 @@ def extract_example_links(archive_url: str, exclude_files: List[str]) -> List[st
166172
List of example links.
167173
"""
168174
response = requests.get(archive_url)
169-
soup = BeautifulSoup(response.content, "html5lib")
170-
links = soup.find_all("a")
171-
example_links = [
172-
f"https://raw.githubusercontent.com{link['href'].replace('/blob/', '/')}"
173-
for link in links
174-
if link["href"].endswith(".txt") and all(file not in link["href"] for file in exclude_files)
175+
json_data = response.json()
176+
items = json_data.get("payload", {}).get("tree", {}).get("items", [])
177+
178+
txt_file_paths = [
179+
item["path"]
180+
for item in items
181+
if item["name"].endswith(".txt") and all(file not in item["path"] for file in exclude_files)
175182
]
183+
example_links = [f"{archive_base_url}{path.replace('/blob/', '/')}" for path in txt_file_paths]
184+
176185
return example_links
177186

178187

@@ -207,14 +216,18 @@ def download_and_process_files(example_links: List[str]) -> List[str]:
207216
if not line.startswith("Cards Clickable") and not line.startswith("...............")
208217
]
209218
f.write(
210-
b"\n".join([line.replace("target", file_name).encode() for line in filtered_lines])
219+
"\n".join([line.replace("target", file_name) for line in filtered_lines]).encode()
211220
)
212221
file_names.append(file_name)
222+
213223
return file_names
214224

215225

216226
URL_ARCHIVE = "https://github.com/executablebooks/sphinx-design/tree/main/docs/snippets/rst"
217-
example_links = extract_example_links(URL_ARCHIVE, exclude_files=["article-info.txt"])
227+
ARCHIVE_BASE_URL = f"https://raw.githubusercontent.com/executablebooks/sphinx-design/main/"
228+
example_links = extract_example_links(
229+
URL_ARCHIVE, ARCHIVE_BASE_URL, exclude_files=["article-info.txt"]
230+
)
218231
file_names = download_and_process_files(example_links)
219232

220233
jinja_contexts = {"examples": {"inputs_examples": file_names}}

doc/source/examples/sphinx-design.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ please refer `sphinx design <https://sphinx-design.readthedocs.io/en/latest/inde
1717
.. literalinclude:: sphinx_examples/{{ filename }}
1818
:language: rst
1919

20-
This directive renders the as follow:
20+
This directive renders as follows:
2121

2222
.. include:: sphinx_examples/{{ filename }}
2323

doc/source/getting_started/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Consider using the ``conf.py`` for this repository:
2828

2929
.. literalinclude:: ../conf.py
3030
:language: python
31+
:end-before: # ONLY FOR ANSYS-SPHINX-THEME
3132

3233
.. toctree::
3334
:hidden:

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ doc = [
3737
"sphinx-copybutton==0.5.2",
3838
"sphinx-notfound-page==0.8.3",
3939
"sphinx-design==0.4.1",
40-
"bs4==0.0.1",
41-
"html5lib==1.1",
4240
"requests==2.31.0",
4341
"sphinx-jinja==2.0.2",
4442
]

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/static/css/ansys_sphinx_theme.css

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,11 @@ i.fa-square-github:before {
769769
color: white;
770770
}
771771

772+
.navbar-icon-links {
773+
font-size: 1.5rem;
774+
color: white;
775+
}
776+
772777
/*
773778
##############################
774779
image padding before and after
@@ -838,10 +843,9 @@ Sphinx design
838843
font-size: medium;
839844
flex: auto;
840845
}
841-
/*
842-
Sphinx-design tab
843-
*/
846+
/* Sphinx-design tab */
844847

848+
/* Common styles for all screen sizes */
845849
.sd-tab-set > input:not(.focus-visible) + label {
846850
outline: none;
847851
font-size: large;
@@ -869,10 +873,23 @@ Sphinx-design tab
869873
border-color: var(--pst-color-text-base);
870874
}
871875

872-
/*
873-
Sphinx-design card
874-
*/
876+
/* Media query for medium-sized screens */
877+
@media screen and (max-width: 768px) {
878+
.sd-tab-set > input:not(.focus-visible) + label {
879+
font-size: medium;
880+
}
881+
}
875882

883+
/* Media query for small-sized screens */
884+
@media screen and (max-width: 576px) {
885+
.sd-tab-set > input:not(.focus-visible) + label {
886+
font-size: small;
887+
}
888+
}
889+
890+
/* Sphinx-design card */
891+
892+
/* Common styles for all screen sizes */
876893
.sd-card .sd-card-text {
877894
font-family: var(--pst-font-family-base) !important;
878895
}
@@ -902,12 +919,34 @@ html[data-theme="dark"] .sd-card-img-top[src*=".png"] {
902919
filter: invert(0.82) brightness(0.8) contrast(1.2);
903920
}
904921

922+
/* Common styles for all screen sizes */
905923
.sd-card {
906924
border-radius: 0;
907925
padding: 10px 10px 10px 10px;
908926
font-family: var(--pst-font-family-base) !important;
909927
}
910928

929+
/* Media query for medium-sized screens */
930+
@media screen and (max-width: 768px) {
931+
.sd-card .sd-card-header {
932+
font-size: var(--pst-font-size-h6);
933+
}
934+
}
935+
936+
/* Media query for small-sized screens */
937+
@media screen and (max-width: 576px) {
938+
.sd-card .sd-card-header {
939+
font-size: var(--pst-font-size-h5);
940+
}
941+
.sd-card {
942+
padding: 5px 5px 5px 5px;
943+
}
944+
.sd-sphinx-override,
945+
.sd-sphinx-override * {
946+
box-sizing: content-box !important;
947+
}
948+
}
949+
911950
/*
912951
Sphinx-design dropdown
913952
*/

0 commit comments

Comments
 (0)