Skip to content

Commit 482a388

Browse files
committed
as
1 parent 526ed64 commit 482a388

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,4 @@ docs/_static/favicon.ico
121121
docs/_static/header.rst
122122
docs/_static/css/custom.css
123123
docs/resources/logos/pyfar_logos_fixed_size_imkar.png
124+
docs/resources/logos/pyfar_logos_fixed_size_pyfar.png

docs/conf.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"navbar_start": ["navbar-logo"],
118118
"navbar_end": ["navbar-icon-links", "theme-switcher"],
119119
"navbar_align": "content",
120-
"header_links_before_dropdown": 8,
120+
"header_links_before_dropdown": 10,
121121
"icon_links": [
122122
{
123123
"name": "GitHub",
@@ -144,6 +144,17 @@
144144
}
145145

146146
# -- download navbar and style files from gallery -----------------------------
147+
def download_files_from_gallery(link, folders_in):
148+
c = urllib3.PoolManager()
149+
for file in folders_in:
150+
url = link + file
151+
filename = file
152+
os.makedirs(os.path.dirname(filename), exist_ok=True)
153+
with c.request('GET', url, preload_content=False) as res:
154+
if res.status == 200:
155+
with open(filename, 'wb') as out_file:
156+
shutil.copyfileobj(res, out_file)
157+
147158
branch = 'main'
148159
link = f'https://github.com/pyfar/gallery/raw/{branch}/docs/'
149160
folders_in = [
@@ -152,23 +163,21 @@
152163
'_static/header.rst',
153164
'resources/logos/pyfar_logos_fixed_size_imkar.png',
154165
]
155-
c = urllib3.PoolManager()
156-
for file in folders_in:
157-
url = link + file
158-
filename = file
159-
os.makedirs(os.path.dirname(filename), exist_ok=True)
160-
with c.request('GET', url, preload_content=False) as res, open(filename, 'wb') as out_file:
161-
shutil.copyfileobj(res, out_file)
166+
download_files_from_gallery(link, folders_in)
167+
# if logo does not exist, use pyfar logo
168+
if not os.path.exists(html_logo):
169+
download_files_from_gallery(
170+
link, ['resources/logos/pyfar_logos_fixed_size_pyfar.png'])
171+
shutil.copyfile(
172+
'resources/logos/pyfar_logos_fixed_size_pyfar.png', html_logo)
162173

163174
# replace imkar hard link to internal link
164175
with open("_static/header.rst", "rt") as fin:
165176
with open("header.rst", "wt") as fout:
166-
contains_imkar = False
167-
for line in fin:
168-
line_new = line.replace(f'https://{project}.readthedocs.io', project)
169-
if line_new != line:
170-
contains_imkar = True
171-
fout.write(line_new)
172-
if not contains_imkar:
173-
fout.write(f' {project} <{project}>\n')
177+
lines = [line.replace(f'https://{project}.readthedocs.io', project) for line in fin]
178+
contains_project = any(project in line for line in lines)
174179

180+
fout.writelines(lines)
181+
182+
if not contains_project:
183+
fout.write(f' {project} <{project}>\n')

0 commit comments

Comments
 (0)