Skip to content

Commit 03a5dde

Browse files
StanFromIrelandm-aciekAA-Turner
authored
Switch to a cards layout for the dashboard (#105)
Co-authored-by: Maciej Olko <[email protected]> Co-authored-by: Adam Turner <[email protected]>
1 parent 9239962 commit 03a5dde

File tree

12 files changed

+279
-238
lines changed

12 files changed

+279
-238
lines changed

.github/workflows/update.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
- run: sudo apt-get install -y gettext
2222
- run: pip install -r requirements.txt
2323
- run: uv run generate.py # generates index.html and index.json
24-
- run: mkdir -p build && cp index.* style.css build
2524
- name: Deploy 🚀
2625
if: github.event_name != 'pull_request'
2726
uses: JamesIves/github-pages-deploy-action@v4
@@ -55,10 +54,9 @@ jobs:
5554
if: github.event_name == 'pull_request'
5655
run: |
5756
curl -Lo index.html-public https://github.com/python-docs-translations/dashboard/raw/refs/heads/gh-pages/index.html
58-
diff --color=always -u index.html-public index.html || :
59-
cat index.html
57+
diff --color=always -u index.html-public build/index.html || :
58+
cat build/index.html
6059
- run: uv run generate_metadata.py # generates metadata.html
61-
- run: cp metadata.html warnings* build
6260
- name: Deploy metadata view 🚀
6361
if: github.event_name != 'pull_request'
6462
uses: JamesIves/github-pages-deploy-action@v4

build_status.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""
2-
Fetch build status of languages in the https://docs.python.org.
2+
Fetch translated names of languages.
33
4-
Yield a tuple of language code and a Boolean indicating
5-
whether it is in the language switcher.
4+
Yield a tuple of language code and a string with the translated name.
65
"""
76

87
import tomllib
@@ -11,26 +10,13 @@
1110
from urllib3 import PoolManager
1211

1312

14-
def get_languages(http: PoolManager) -> Iterator[tuple[str, bool]]:
13+
def get_languages(http: PoolManager) -> Iterator[tuple[str, str]]:
1514
data = http.request(
1615
'GET',
1716
'https://raw.githubusercontent.com/python/docsbuild-scripts/refs/heads/main/config.toml',
1817
).data
1918
config = tomllib.loads(data.decode())
2019
for code, language in config['languages'].items():
2120
language_code = code.lower().replace('_', '-')
22-
in_switcher = language.get('in_prod', config['defaults']['in_prod'])
23-
yield language_code, in_switcher
24-
25-
26-
def main() -> None:
27-
languages = {
28-
language: in_switcher for language, in_switcher in get_languages(PoolManager())
29-
}
30-
print(languages)
31-
for code in ('en', 'pl', 'ar', 'zh-cn', 'id'):
32-
print(f'{code}: {code in languages} {languages.get(code)}')
33-
34-
35-
if __name__ == '__main__':
36-
main()
21+
translated_name = language.get('translated_name')
22+
yield language_code, translated_name

build_warnings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ def number(clones_dir: str, repo: str, language_code: str) -> int:
3333
f'./sphinxbuild/{language_code}', # outputdir
3434
)
3535
)
36-
copyfile(warning_file, f'warnings-{language_code}.txt')
36+
copyfile(warning_file, f'build/warnings-{language_code}.txt')
3737
return len(findall('ERROR|WARNING', Path(warning_file).read_text()))

generate.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pathlib import Path
1010

1111
from git import Repo
12-
from jinja2 import Template
12+
from jinja2 import Environment, FileSystemLoader
1313
from urllib3 import PoolManager
1414

1515
import build_status
@@ -37,7 +37,11 @@ def get_completion_progress() -> Iterator['LanguageProjectData']:
3737
)
3838
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'venv'], check=True)
3939
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'gettext'], check=True)
40-
languages_built = dict(build_status.get_languages(PoolManager()))
40+
41+
languages_built: dict[str, str] = {
42+
language: translated_name
43+
for language, translated_name in build_status.get_languages(PoolManager())
44+
}
4145

4246
with concurrent.futures.ThreadPoolExecutor() as executor:
4347
return executor.map(
@@ -51,7 +55,7 @@ def get_completion_progress() -> Iterator['LanguageProjectData']:
5155
def get_project_data(
5256
language: Language,
5357
repo: str | None,
54-
languages_built: dict[str, bool],
58+
languages_built: dict[str, str],
5559
clones_dir: str,
5660
) -> 'LanguageProjectData':
5761
built = language.code in languages_built
@@ -62,6 +66,7 @@ def get_project_data(
6266
translators_data = TranslatorsData(0, False)
6367
change = 0.0
6468
branch = ''
69+
6570
return LanguageProjectData(
6671
language,
6772
repo,
@@ -70,7 +75,7 @@ def get_project_data(
7075
change,
7176
translators_data,
7277
built,
73-
in_switcher=languages_built.get(language.code),
78+
translated_name=languages_built.get(language.code, ''),
7479
uses_platform=language.code in contribute.pulling_from_transifex,
7580
contribution_link=contribute.get_contrib_link(language.code, repo),
7681
)
@@ -85,24 +90,30 @@ class LanguageProjectData:
8590
change: float
8691
translators: TranslatorsData
8792
built: bool
88-
in_switcher: bool | None
93+
translated_name: str
8994
uses_platform: bool
9095
contribution_link: str | None
9196

9297

9398
if __name__ == '__main__':
9499
logging.basicConfig(level=logging.INFO)
95100
logging.info(f'starting at {generation_time}')
96-
template = Template(Path('template.html.jinja').read_text())
101+
Path('build').mkdir(parents=True, exist_ok=True)
97102

98-
output = template.render(
99-
completion_progress=(completion_progress := list(get_completion_progress())),
103+
completion_progress = list(get_completion_progress())
104+
counts = get_counts(Path('clones', 'cpython', 'Doc', 'build', 'gettext'))
105+
106+
env = Environment(loader=FileSystemLoader('templates'))
107+
index = env.get_template('index.html.jinja').render(
108+
completion_progress=completion_progress,
100109
generation_time=generation_time,
101110
duration=(datetime.now(timezone.utc) - generation_time).seconds,
102-
counts=get_counts(Path('clones', 'cpython', 'Doc', 'build', 'gettext')),
103111
)
104112

105-
Path('index.html').write_text(output)
106-
Path('index.json').write_text(
107-
json.dumps(completion_progress, indent=2, default=asdict)
113+
Path('build/style.css').write_bytes(Path('src/style.css').read_bytes())
114+
Path('build/logo.png').write_bytes(Path('src/logo.png').read_bytes())
115+
Path('build/index.html').write_text(index)
116+
117+
Path('build/index.json').write_text(
118+
json.dumps([asdict(project) for project in completion_progress], indent=2)
108119
)

generate_metadata.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import dacite
1111
from git import Repo
12-
from jinja2 import Template
12+
from jinja2 import Environment, FileSystemLoader
1313
from urllib3 import request
1414

1515
import build_warnings
@@ -55,20 +55,20 @@ def get_language_repo_and_completion(
5555
if __name__ == '__main__':
5656
logging.basicConfig(level=logging.INFO)
5757
logging.info(f'starting at {generation_time}')
58-
template = Template(Path('metadata.html.jinja').read_text())
59-
if (index_path := Path('index.json')).exists():
60-
index_json = loads(Path('index.json').read_text())
58+
env = Environment(loader=FileSystemLoader('templates'))
59+
if (index_path := Path('build/index.json')).exists():
60+
index_json = loads(Path('build/index.json').read_text())
6161
else:
6262
index_json = request('GET', argv[1]).json()
6363

6464
completion_progress = [
6565
dacite.from_dict(LanguageProjectData, project) for project in index_json
6666
]
6767

68-
output = template.render(
68+
output = env.get_template('metadata.html.jinja').render(
6969
metadata=zip(completion_progress, get_projects_metadata(completion_progress)),
7070
generation_time=generation_time,
7171
duration=(datetime.now(timezone.utc) - generation_time).seconds,
7272
)
7373

74-
Path('metadata.html').write_text(output)
74+
Path('build/metadata.html').write_text(output)

src/logo.png

12.9 KB
Loading

src/style.css

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/* ---------------------------- Global Styles ------------------------------- */
2+
3+
body {
4+
padding-top: 4.5rem;
5+
padding-left: 1rem;
6+
padding-right: 1rem;
7+
padding-bottom: 3rem;
8+
color: #5a5a5a;
9+
background-color: rgb(245, 245, 245);
10+
}
11+
12+
a {
13+
color: #0d0d0d;
14+
}
15+
16+
a:hover {
17+
color: #1595fe;
18+
}
19+
20+
/* -------------------------------- navbar ---------------------------------- */
21+
22+
.navbar {
23+
background-color: rgb(245, 245, 245, 0.6);
24+
backdrop-filter: blur(10px);
25+
border-bottom: 0.25px solid #999;
26+
-webkit-backdrop-filter: blur(10px);
27+
}
28+
29+
.navbar li {
30+
transition: 0.3s background-color;
31+
text-align: center;
32+
background-color: transparent;
33+
padding: 0rem 1rem;
34+
text-decoration: none;
35+
border-radius: 0.3rem;
36+
}
37+
38+
.navbar li:hover {
39+
background-color: #d0cccd;
40+
}
41+
42+
.navbar li .nav-link {
43+
color: #0d0d0d;
44+
}
45+
46+
/* ----------------------- Cards and card columns --------------------------- */
47+
48+
.row > [class^="col-"] {
49+
display: flex;
50+
}
51+
52+
.card {
53+
flex: 1;
54+
}
55+
56+
/* ------------------------------ Index ------------------------------------- */
57+
58+
.progress-bar-container {
59+
border-radius: 4px;
60+
border: 1px solid rgba(0, 0, 0, 0.2);
61+
height: 20px;
62+
overflow: hidden;
63+
position: relative;
64+
}
65+
66+
.progress-bar-index {
67+
display: inline-block;
68+
color: white;
69+
height: 100%;
70+
line-height: 20px;
71+
border-top-left-radius: 3px;
72+
border-bottom-left-radius: 3px;
73+
}
74+
75+
/* ------------------------------ Metadata ---------------------------------- */
76+
77+
table {
78+
border-collapse: collapse;
79+
}
80+
th, td {
81+
border: 1px solid #ddd;
82+
padding: 8px 12px;
83+
text-align: left;
84+
white-space: nowrap;
85+
}
86+
th {
87+
background-color: #d6d6d6;
88+
}
89+
hr {
90+
color: #f4f4f4;
91+
}
92+
td[data-label="warnings"], td[data-label="lint"] {
93+
text-align: right;
94+
}
95+
96+
@media screen and (max-width: 600px) {
97+
table, thead, tbody, th, td, tr {
98+
display: block;
99+
}
100+
th {
101+
position: absolute;
102+
top: -9999px;
103+
left: -9999px;
104+
}
105+
tr {
106+
border: 1px solid #ccc;
107+
margin-bottom: 5px;
108+
}
109+
td {
110+
border: none;
111+
border-bottom: 1px solid #eee;
112+
padding-left: 50%;
113+
position: relative;
114+
}
115+
td:before {
116+
content: attr(data-label);
117+
font-weight: bold;
118+
left: 10px;
119+
position: absolute;
120+
}
121+
}

0 commit comments

Comments
 (0)