Skip to content

Commit

Permalink
Improve icon pack grid + general wording
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemiii91 committed May 18, 2024
1 parent 21c23d2 commit 13c1579
Show file tree
Hide file tree
Showing 24 changed files with 266 additions and 366 deletions.
17 changes: 12 additions & 5 deletions .github/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,21 @@ def rel_path(path: str, from_path: str) -> str:
LB_SPACER = " " + NB_SPACE

_pages = {
"custom": "Custom Themes",
"remixed": "Remixed Themes",
"icons_themes": "Theme Icon Packs",
"icons_standalone": "Standalone Icon Packs"
"custom": "Originals",
"remixed": "Remixed",
"icons_themes": "Iconified",
"icons_standalone": "Extra Icons"
}

PAGE_TITLES = {
"custom": "Originals — Custom Made Themes",
"remixed": "Remixed — Alternative Versions of Themes",
"icons_themes": "Iconified — Themes with Icon Packs",
"icons_standalone": "Extra Icons — Standalone Icon Packs"
}

HEADER_LINKS = {
"index": ["Index", README_PATH],
"index": ["Start", README_PATH],
**{name: [text.replace(" ", NB_SPACE), os.path.join(PAGES_DIR, name, "index.md")] for name, text in _pages.items()},
"contributing": ["Contributing", from_src("../CONTRIBUTING.md")]
}
Expand Down
48 changes: 18 additions & 30 deletions .github/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@

from utils import get_files, get_lines, get_subdirs, urlencode, git_last_changed, git_commit_count, datetime
from validation import validate_theme
from generate_icons import generate_icon_pack_table, get_ordered_icons
from generate_icons import generate_icon_pack_table, get_ordered_icons, IconPack, generate_icon_pack_url, icons_blacklist


icons_blacklist = get_lines(ICONS_BLACKLIST)
themes_featured = []
themes_icon_packs = []

Expand Down Expand Up @@ -49,11 +48,11 @@ def main():

os.makedirs(PAGES_DIR, exist_ok=True)

write_pages(themes_custom, "custom", "Custom Themes", generate_table_grid)
write_pages(themes_remixed, "remixed", "Remixed Themes", generate_table_grid)
write_pages(themes_custom, "custom", generate_table_grid)
write_pages(themes_remixed, "remixed", generate_table_grid)

write_pages(themes_icon_packs, "icons_themes", "Theme Icon Packs", generate_icon_pack_table)
write_pages(standalone_icon_packs, "icons_standalone", "Standalone Icon Packs", generate_icon_pack_table)
write_pages(themes_icon_packs, "icons_themes", generate_icon_pack_table)
write_pages(standalone_icon_packs, "icons_standalone", generate_icon_pack_table)

write_file(README_PATH, generate_index({
"custom": len(themes_custom),
Expand Down Expand Up @@ -92,8 +91,8 @@ def generate_index(counts: dict):
def generate_index_list(counts: dict) -> str:
buffer = ""
for group_name, count in counts.items():
text, link = HEADER_LINKS[group_name]
buffer += f"### [{text} ({count})]({rel_path(link, '.')})\n\n"
_, link = HEADER_LINKS[group_name]
buffer += f"### [{PAGE_TITLES[group_name]} ({count})]({rel_path(link, '.')})\n\n"
return buffer


Expand All @@ -102,22 +101,22 @@ def generate_recents_grid(items: list[dict]) -> str:
return apply_template(GRID_TEMPLATE, {"GRID_ITEMS": "\n\n".join(generate_item(item["theme"]) for item in items[:MAX_RECENTS])})


def write_pages(items: list, group_name: str, group_header: str, item_grid_generator: Callable[[list], str], page_size: int = 12, **opts):
def write_pages(items: list, group_name: str, item_grid_generator: Callable[[list], str], page_size: int = 12, **opts):
workdir = os.path.join(PAGES_DIR, group_name)
os.makedirs(workdir, exist_ok=True)

total = len(items)
num_pages = math.ceil(total / page_size)

for page in tqdm(range(num_pages), desc=group_header):
for page in tqdm(range(num_pages), desc=PAGE_TITLES[group_name]):
current_path = os.path.join(workdir, format_page_filename(page))

index = page * page_size
batch = items[index : index + page_size]

buffer = ""
buffer += apply_template(HEADER_TEMPLATE, { "LINKS": generate_header_links(current_path, current_group=group_name) })
buffer += f"\n## {group_header}\n\n*Page {page + 1} of {num_pages}{total} items available*\n"
buffer += f"\n## {PAGE_TITLES[group_name]}\n\n*Page {page + 1} of {num_pages}{total} items available*\n"
buffer += item_grid_generator(batch, **opts) + "\n\n"

if num_pages > 1:
Expand Down Expand Up @@ -265,16 +264,14 @@ def generate_item(theme: str, index: int = 0, collect_data: bool = False) -> str

if collect_data:
if has_icon_pack:
for subdir in theme_subdirs:
if os.path.isdir(f"{subdir}/icons") and os.path.basename(subdir) not in icons_blacklist:
themes_icon_packs.append({
"name": os.path.basename(subdir),
"path": from_src(os.path.join("..", subdir, "icons")),
"is_theme": True,
"theme": theme,
"release_url": release_url,
"preview_url": generate_icon_pack_url(theme, [subdir])
})
valid_subdirs = [subdir for subdir in theme_subdirs if os.path.isdir(f"{subdir}/icons") and os.path.basename(subdir) not in icons_blacklist]
themes_icon_packs.extend(IconPack(
dir_name=os.path.basename(subdir),
dir_path=os.path.join(subdir, "icons"),
theme=theme,
release_url=release_url,
theme_subdir=subdir)
for subdir in valid_subdirs)
if commit_count <= 1:
recents_maybe_append(recently_added, last_changed_datetime, theme)
else:
Expand All @@ -288,14 +285,5 @@ def recents_maybe_append(recents: list[dict], timestamp: datetime, theme: str):
recents.append({"ts": timestamp, "theme": theme})


def generate_icon_pack_url(theme: str, theme_subdirs: list[str]) -> str:
icons_dirs = [f"{subdir}/icons" for subdir in theme_subdirs if os.path.isdir(f"{subdir}/icons") and os.path.basename(subdir) not in icons_blacklist]

url = f"https://onionui.github.io/iconpack_preview.html#{urlencode(theme)},"
url += ",".join(f"{urlencode(os.path.basename(os.path.dirname(icons_dir)))}:{urlencode(icons_dir)}" for icons_dir in icons_dirs)

return url


if __name__ == "__main__":
main()
77 changes: 41 additions & 36 deletions .github/generate_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,80 +10,85 @@
ALL_ICONS = ['32X', '5200', '7800', 'amiga', 'arcade', 'atari', 'c64', 'col', 'cpc', 'cps1', 'cps2', 'cps3', 'dos', 'fairchild', 'fc', 'fds', 'gb', 'gba', 'gbc', 'gg', 'gw', 'itv', 'lynx', 'md', 'megaduck', 'ms', 'msx', 'nds', 'neocd', 'neogeo', 'ngp', 'ody', 'pce', 'pcecd', 'pico', 'poke', 'ports', 'ps', 'satella', 'scummvm', 'search', 'segacd', 'segasgone', 'sfc', 'sgb', 'sgfx', 'sufami', 'supervision', 'tic', 'vb', 'vdp', 'vectrex', 'ws', 'zxs']


icons_blacklist = get_lines(ICONS_BLACKLIST)


class IconPack:
def __init__(self, dir_name: str, dir_path: str, release_url: str = None, theme: str = None, theme_subdir: str = None):
self.name = dir_name
self.path = from_src(os.path.join("..", dir_path))
self.release_url = f"https://raw.githubusercontent.com/OnionUI/Themes/main/{urlencode(os.path.join("release", dir_path + ".zip"))}" \
if not release_url else release_url
self.preview_url = generate_icon_pack_url(dir_name, theme_subdirs=[theme_subdir] if theme_subdir else None)
self.is_theme = theme is not None
self.theme = theme


def generate_icon_pack_url(dir_name: str, theme_subdirs: list[str] = None) -> str:
url = f"https://onionui.github.io/iconpack_preview.html#{urlencode(dir_name)}"
if theme_subdirs:
icons_dirs = [f"{subdir}/icons" for subdir in theme_subdirs if os.path.isdir(f"{subdir}/icons") and os.path.basename(subdir) not in icons_blacklist]
url += "," + ",".join(f"{urlencode(os.path.basename(os.path.dirname(icons_dir)))}:{urlencode(icons_dir)}" for icons_dir in icons_dirs)
return url


def get_ordered_icons() -> list[dict]:
ordered_icons = []
icon_packs = []
ordered_icons: list[IconPack] = []
icon_packs: list[IconPack] = []

for dir_name in os.listdir("icons"):
dir_path = os.path.join("icons", dir_name)
release_url = os.path.join("release", dir_path + ".zip")

if not os.path.isfile(release_url):
if not os.path.isfile(os.path.join("release", dir_path + ".zip")):
continue

icon_packs.append({
"name": dir_name,
"path": from_src(os.path.join("..", dir_path)),
"release_url": f"https://raw.githubusercontent.com/OnionUI/Themes/main/{urlencode(release_url)}",
"preview_url": f"https://onionui.github.io/iconpack_preview.html#{urlencode(dir_name)}"
})
icon_packs.append(IconPack(dir_name, dir_path))

for icon_pack in get_lines(ICONS_ORDERING):
result = next((x for x in icon_packs if x['name'] == icon_pack), None)
if result is None:
continue
ordered_icons.append(result)
result = next((x for x in icon_packs if x.name == icon_pack), None)
if result:
ordered_icons.append(result)

ordered_icons.reverse()

return ordered_icons


def generate_icon_pack_table(icon_packs: list[dict], cols: int = ICONS_COLS) -> str:
def generate_icon_pack_table(icon_packs: list[IconPack], cols: int = ICONS_COLS) -> str:
current_path = os.path.join(PAGES_ICONS_DIR, ".")
output = "<table align=center><tr>\n\n"

for i, icon_pack in enumerate(icon_packs):
if i > 0 and i % cols == 0:
output += "</tr><tr>\n"
output += generate_icon_pack_entry(current_path, **icon_pack, index=i)
output += generate_icon_pack_entry(current_path, icon_pack, index=i)

output += "</tr></table>\n\n"

return output


def generate_icon_pack_entry(current_path: str, name, path, release_url, preview_url, is_theme: bool = False, theme: str = "", index: int = 0):
preview_path = from_src(os.path.join(path, f"preview.png"))

ensure_has_icon_preview(path)

output = f"""
<td valign="top">
#### {name}
def generate_icon_pack_entry(current_path: str, icon_pack: IconPack, index: int = 0):
preview_path = from_src(os.path.join(icon_pack.path, f"preview.png"))

![{name}]({urlencode(rel_path(preview_path, current_path))})
ensure_has_icon_preview(icon_pack.path)

"""
output = f"""\n<td valign="top">\n\n[![{icon_pack.name}]({urlencode(rel_path(preview_path, current_path))})]({icon_pack.preview_url} "Click to see the full icon pack preview page")\n\n**{icon_pack.name}**\n\n"""

if len(release_url) != 0:
dn_text = f"Download {theme} (theme)" if is_theme else f"Download {name} (icon pack)"
output += f"[{dn_text}]({release_url})\n\n"
dn_text = f"Download theme" if icon_pack.is_theme else f"Download icon pack"
dn_link = f"[{dn_text}]({icon_pack.release_url} \"{icon_pack.theme if icon_pack.is_theme else icon_pack.name}\")"

readme_path = ""

for readme_file in README_TEST + [f"../{fn}" for fn in README_TEST]:
readme_path = os.path.abspath(from_src(os.path.join("..", path, readme_file)))
readme_path = os.path.abspath(from_src(os.path.join("..", icon_pack.path, readme_file)))
if os.path.isfile(readme_path):
readme_path = readme_path[len(REL_PATH):]
break
readme_path = ""

readme = f"<a href=\"{urlencode(readme_path)}\">{README_ICON}</a> &nbsp;&nbsp; " if len(readme_path) != 0 else ""
readme = f"<a href=\"{urlencode(readme_path)}\">{README_ICON}</a> {NB_SPACER} " if len(readme_path) != 0 else ""

icon_count = sum(os.path.isfile(f"{path}/{icon}.png") for icon in ALL_ICONS)
output += f"<sub><sup>{icon_count}/{len(ALL_ICONS)} icons ({round(icon_count/len(ALL_ICONS)*100)}% complete)</sup> &nbsp;&nbsp; {readme}<a href=\"{preview_url}\">{PREVIEW_ICON}</a></sub>"
icon_count = sum(os.path.isfile(f"{icon_pack.path}/{icon}.png") for icon in ALL_ICONS)
output += f"{dn_link} <sub><sup>{NB_SPACER} {icon_count / len(ALL_ICONS) * 100:.0f}%{NB_SPACE}complete</sup> {NB_SPACER} {readme}</sub>"

output += f"\n\n{ICONS_COLUMN_SPANNER if index < ICONS_COLS else ''}<br/></td>\n\n"

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

# <img alt="Onion Themes" src="https://user-images.githubusercontent.com/44569252/179506709-0db2a8f5-3074-477c-81c4-719f281ddccc.png#gh-dark-mode-only" width="464px"><img alt="Onion Themes" src="https://user-images.githubusercontent.com/44569252/179506712-d5a1a916-7270-4902-aa55-5d93f7ee0f6e.png#gh-light-mode-only" width="464px">

*The Onion Theme Repository* &nbsp;&nbsp; **Index** &nbsp;&nbsp;[Custom&nbsp;Themes](generated/custom/index.md) &nbsp;&nbsp;[Remixed&nbsp;Themes](generated/remixed/index.md) &nbsp;&nbsp;[Theme&nbsp;Icon&nbsp;Packs](generated/icons_themes/index.md) &nbsp;&nbsp;[Standalone&nbsp;Icon&nbsp;Packs](generated/icons_standalone/index.md) &nbsp;&nbsp;[Contributing](CONTRIBUTING.md)
*The Onion Theme Repository* &nbsp;&nbsp; **Start** &nbsp;&nbsp;[Originals](generated/custom/index.md) &nbsp;&nbsp;[Remixed](generated/remixed/index.md) &nbsp;&nbsp;[Iconified](generated/icons_themes/index.md) &nbsp;&nbsp;[Extra&nbsp;Icons](generated/icons_standalone/index.md) &nbsp;&nbsp;[Contributing](CONTRIBUTING.md)

<p>&nbsp;</p>

Expand All @@ -71,13 +71,13 @@

*Click on a section below to browse themes and icon packs*

### [Custom&nbsp;Themes (156)](generated/custom/index.md)
### [Originals — Custom Made Themes (156)](generated/custom/index.md)

### [Remixed&nbsp;Themes (15)](generated/remixed/index.md)
### [Remixed — Alternative Versions of Themes (15)](generated/remixed/index.md)

### [Theme&nbsp;Icon&nbsp;Packs (43)](generated/icons_themes/index.md)
### [Iconified — Themes with Icon Packs (43)](generated/icons_themes/index.md)

### [Standalone&nbsp;Icon&nbsp;Packs (7)](generated/icons_standalone/index.md)
### [Extra Icons — Standalone Icon Packs (7)](generated/icons_standalone/index.md)



Expand Down
4 changes: 2 additions & 2 deletions generated/custom/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@

# <img alt="Onion Themes" src="https://user-images.githubusercontent.com/44569252/179506709-0db2a8f5-3074-477c-81c4-719f281ddccc.png#gh-dark-mode-only" width="464px"><img alt="Onion Themes" src="https://user-images.githubusercontent.com/44569252/179506712-d5a1a916-7270-4902-aa55-5d93f7ee0f6e.png#gh-light-mode-only" width="464px">

*The Onion Theme Repository* &nbsp;&nbsp; [Index](../../README.md) &nbsp;&nbsp;**Custom&nbsp;Themes** &nbsp;&nbsp;[Remixed&nbsp;Themes](../remixed/index.md) &nbsp;&nbsp;[Theme&nbsp;Icon&nbsp;Packs](../icons_themes/index.md) &nbsp;&nbsp;[Standalone&nbsp;Icon&nbsp;Packs](../icons_standalone/index.md) &nbsp;&nbsp;[Contributing](../../CONTRIBUTING.md)
*The Onion Theme Repository* &nbsp;&nbsp; [Start](../../README.md) &nbsp;&nbsp;**Originals** &nbsp;&nbsp;[Remixed](../remixed/index.md) &nbsp;&nbsp;[Iconified](../icons_themes/index.md) &nbsp;&nbsp;[Extra&nbsp;Icons](../icons_standalone/index.md) &nbsp;&nbsp;[Contributing](../../CONTRIBUTING.md)

<p>&nbsp;</p>


## Custom Themes
## Originals — Custom Made Themes

*Page 1 of 13 — 156 items available*
<table align="center"><tr>
Expand Down
4 changes: 2 additions & 2 deletions generated/custom/page-02.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@

# <img alt="Onion Themes" src="https://user-images.githubusercontent.com/44569252/179506709-0db2a8f5-3074-477c-81c4-719f281ddccc.png#gh-dark-mode-only" width="464px"><img alt="Onion Themes" src="https://user-images.githubusercontent.com/44569252/179506712-d5a1a916-7270-4902-aa55-5d93f7ee0f6e.png#gh-light-mode-only" width="464px">

*The Onion Theme Repository* &nbsp;&nbsp; [Index](../../README.md) &nbsp;&nbsp;**Custom&nbsp;Themes** &nbsp;&nbsp;[Remixed&nbsp;Themes](../remixed/index.md) &nbsp;&nbsp;[Theme&nbsp;Icon&nbsp;Packs](../icons_themes/index.md) &nbsp;&nbsp;[Standalone&nbsp;Icon&nbsp;Packs](../icons_standalone/index.md) &nbsp;&nbsp;[Contributing](../../CONTRIBUTING.md)
*The Onion Theme Repository* &nbsp;&nbsp; [Start](../../README.md) &nbsp;&nbsp;**Originals** &nbsp;&nbsp;[Remixed](../remixed/index.md) &nbsp;&nbsp;[Iconified](../icons_themes/index.md) &nbsp;&nbsp;[Extra&nbsp;Icons](../icons_standalone/index.md) &nbsp;&nbsp;[Contributing](../../CONTRIBUTING.md)

<p>&nbsp;</p>


## Custom Themes
## Originals — Custom Made Themes

*Page 2 of 13 — 156 items available*
<table align="center"><tr>
Expand Down
4 changes: 2 additions & 2 deletions generated/custom/page-03.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@

# <img alt="Onion Themes" src="https://user-images.githubusercontent.com/44569252/179506709-0db2a8f5-3074-477c-81c4-719f281ddccc.png#gh-dark-mode-only" width="464px"><img alt="Onion Themes" src="https://user-images.githubusercontent.com/44569252/179506712-d5a1a916-7270-4902-aa55-5d93f7ee0f6e.png#gh-light-mode-only" width="464px">

*The Onion Theme Repository* &nbsp;&nbsp; [Index](../../README.md) &nbsp;&nbsp;**Custom&nbsp;Themes** &nbsp;&nbsp;[Remixed&nbsp;Themes](../remixed/index.md) &nbsp;&nbsp;[Theme&nbsp;Icon&nbsp;Packs](../icons_themes/index.md) &nbsp;&nbsp;[Standalone&nbsp;Icon&nbsp;Packs](../icons_standalone/index.md) &nbsp;&nbsp;[Contributing](../../CONTRIBUTING.md)
*The Onion Theme Repository* &nbsp;&nbsp; [Start](../../README.md) &nbsp;&nbsp;**Originals** &nbsp;&nbsp;[Remixed](../remixed/index.md) &nbsp;&nbsp;[Iconified](../icons_themes/index.md) &nbsp;&nbsp;[Extra&nbsp;Icons](../icons_standalone/index.md) &nbsp;&nbsp;[Contributing](../../CONTRIBUTING.md)

<p>&nbsp;</p>


## Custom Themes
## Originals — Custom Made Themes

*Page 3 of 13 — 156 items available*
<table align="center"><tr>
Expand Down
4 changes: 2 additions & 2 deletions generated/custom/page-04.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@

# <img alt="Onion Themes" src="https://user-images.githubusercontent.com/44569252/179506709-0db2a8f5-3074-477c-81c4-719f281ddccc.png#gh-dark-mode-only" width="464px"><img alt="Onion Themes" src="https://user-images.githubusercontent.com/44569252/179506712-d5a1a916-7270-4902-aa55-5d93f7ee0f6e.png#gh-light-mode-only" width="464px">

*The Onion Theme Repository* &nbsp;&nbsp; [Index](../../README.md) &nbsp;&nbsp;**Custom&nbsp;Themes** &nbsp;&nbsp;[Remixed&nbsp;Themes](../remixed/index.md) &nbsp;&nbsp;[Theme&nbsp;Icon&nbsp;Packs](../icons_themes/index.md) &nbsp;&nbsp;[Standalone&nbsp;Icon&nbsp;Packs](../icons_standalone/index.md) &nbsp;&nbsp;[Contributing](../../CONTRIBUTING.md)
*The Onion Theme Repository* &nbsp;&nbsp; [Start](../../README.md) &nbsp;&nbsp;**Originals** &nbsp;&nbsp;[Remixed](../remixed/index.md) &nbsp;&nbsp;[Iconified](../icons_themes/index.md) &nbsp;&nbsp;[Extra&nbsp;Icons](../icons_standalone/index.md) &nbsp;&nbsp;[Contributing](../../CONTRIBUTING.md)

<p>&nbsp;</p>


## Custom Themes
## Originals — Custom Made Themes

*Page 4 of 13 — 156 items available*
<table align="center"><tr>
Expand Down
4 changes: 2 additions & 2 deletions generated/custom/page-05.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@

# <img alt="Onion Themes" src="https://user-images.githubusercontent.com/44569252/179506709-0db2a8f5-3074-477c-81c4-719f281ddccc.png#gh-dark-mode-only" width="464px"><img alt="Onion Themes" src="https://user-images.githubusercontent.com/44569252/179506712-d5a1a916-7270-4902-aa55-5d93f7ee0f6e.png#gh-light-mode-only" width="464px">

*The Onion Theme Repository* &nbsp;&nbsp; [Index](../../README.md) &nbsp;&nbsp;**Custom&nbsp;Themes** &nbsp;&nbsp;[Remixed&nbsp;Themes](../remixed/index.md) &nbsp;&nbsp;[Theme&nbsp;Icon&nbsp;Packs](../icons_themes/index.md) &nbsp;&nbsp;[Standalone&nbsp;Icon&nbsp;Packs](../icons_standalone/index.md) &nbsp;&nbsp;[Contributing](../../CONTRIBUTING.md)
*The Onion Theme Repository* &nbsp;&nbsp; [Start](../../README.md) &nbsp;&nbsp;**Originals** &nbsp;&nbsp;[Remixed](../remixed/index.md) &nbsp;&nbsp;[Iconified](../icons_themes/index.md) &nbsp;&nbsp;[Extra&nbsp;Icons](../icons_standalone/index.md) &nbsp;&nbsp;[Contributing](../../CONTRIBUTING.md)

<p>&nbsp;</p>


## Custom Themes
## Originals — Custom Made Themes

*Page 5 of 13 — 156 items available*
<table align="center"><tr>
Expand Down
Loading

0 comments on commit 13c1579

Please sign in to comment.