|
117 | 117 | "navbar_start": ["navbar-logo"], |
118 | 118 | "navbar_end": ["navbar-icon-links", "theme-switcher"], |
119 | 119 | "navbar_align": "content", |
120 | | - "header_links_before_dropdown": 8, |
| 120 | + "header_links_before_dropdown": 10, |
121 | 121 | "icon_links": [ |
122 | 122 | { |
123 | 123 | "name": "GitHub", |
|
144 | 144 | } |
145 | 145 |
|
146 | 146 | # -- 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 | + |
147 | 158 | branch = 'main' |
148 | 159 | link = f'https://github.com/pyfar/gallery/raw/{branch}/docs/' |
149 | 160 | folders_in = [ |
|
152 | 163 | '_static/header.rst', |
153 | 164 | 'resources/logos/pyfar_logos_fixed_size_imkar.png', |
154 | 165 | ] |
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) |
162 | 173 |
|
163 | 174 | # replace imkar hard link to internal link |
164 | 175 | with open("_static/header.rst", "rt") as fin: |
165 | 176 | 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) |
174 | 179 |
|
| 180 | + fout.writelines(lines) |
| 181 | + |
| 182 | + if not contains_project: |
| 183 | + fout.write(f' {project} <{project}>\n') |
0 commit comments