Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gallery shortcode #504

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.DEFAULT_GOAL := doc-serve

GH_ORG = scientific-python
TEAMS_DIR = doc/static/teams
TEAMS_DIR = doc/content/about
TEAMS = theme-team
TEAMS_QUERY = python tools/team_query.py

Expand All @@ -11,7 +11,7 @@ $(TEAMS_DIR):

$(TEAMS_DIR)/%.md: $(TEAMS_DIR)
$(eval TEAM_NAME=$(shell python -c "import re; print(' '.join(x.capitalize() for x in re.split('-|_', '$*')))"))
$(TEAMS_QUERY) --org $(GH_ORG) --team "$*" > $(TEAMS_DIR)/$*.html
$(TEAMS_QUERY) --org $(GH_ORG) --team "$*" --dir $(TEAMS_DIR)

teams-clean:
for team in $(TEAMS); do \
Expand Down
5 changes: 5 additions & 0 deletions doc/content/_gallery/ipython.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "IPython"
avatar: https://avatars.githubusercontent.com/u/230453
repository: https://github.com/ipython/ipython
---
5 changes: 5 additions & 0 deletions doc/content/_gallery/matplotlib.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "Matplotlib"
avatar: https://avatars.githubusercontent.com/u/215947
repository: https://github.com/matplotlib/matplotlib
---
5 changes: 5 additions & 0 deletions doc/content/_gallery/networkx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "NetworkX"
avatar: https://avatars.githubusercontent.com/u/388785
repository: https://github.com/networkx/networkx
---
5 changes: 5 additions & 0 deletions doc/content/_gallery/numpy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "NumPy"
avatar: https://avatars.githubusercontent.com/u/288276
repository: https://github.com/numpy/numpy
---
5 changes: 5 additions & 0 deletions doc/content/_gallery/pandas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "pandas"
avatar: https://avatars.githubusercontent.com/u/21206976
repository: https://github.com/pandas-dev/pandas
---
5 changes: 5 additions & 0 deletions doc/content/_gallery/scikit-image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "scikit-image"
avatar: https://avatars.githubusercontent.com/u/897180
repository: https://github.com/scikit-image/scikit-image
---
5 changes: 5 additions & 0 deletions doc/content/_gallery/scikit-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "scikit-learn"
avatar: https://avatars.githubusercontent.com/u/365630
repository: https://github.com/scikit-learn/scikit-learn
---
5 changes: 5 additions & 0 deletions doc/content/_gallery/scipy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "SciPy"
avatar: https://raw.githubusercontent.com/scipy/archive/main/branding/logos/scipy_logo.svg
repository: https://github.com/scipy/scipy
---
5 changes: 5 additions & 0 deletions doc/content/_gallery/xarray.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "xarray"
avatar: https://numfocus.org/wp-content/uploads/2018/09/xarray-logo-square.png
repository: https://github.com/pydata/xarray
---
5 changes: 5 additions & 0 deletions doc/content/_gallery/zarr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "Zarr-Python"
avatar: https://raw.githubusercontent.com/zarr-developers/zarr-logo/main/zarr-pink-stacked.svg
repository: https://github.com/zarr-developers/zarr-python
---
2 changes: 1 addition & 1 deletion doc/content/about/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ The **Scientific Python Hugo Theme** is a theme for the
[Hugo](https://gohugo.io) static site generator built on the
[Fresh](https://github.com/StefMa/hugo-fresh) theme.

{{< include-html "static/teams/theme-team.html" >}}
{{< gallery pages="./theme-team" columns="2 4 4 5" >}}
5 changes: 5 additions & 0 deletions doc/content/about/theme-team/adam-porter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "Adam Porter"
avatar: https://avatars.githubusercontent.com/u/601365?v=4
repository: https://github.com/alphapapa
---
5 changes: 5 additions & 0 deletions doc/content/about/theme-team/brian-hawthorne.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "Brian Hawthorne"
avatar: https://avatars.githubusercontent.com/u/352264?u=1fd523aa28b0451454989400579d97a8c1bc1b9a&v=4
repository: https://github.com/brianhawthorne
---
Empty file.
5 changes: 5 additions & 0 deletions doc/content/about/theme-team/jarrod-millman.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "Jarrod Millman"
avatar: https://avatars.githubusercontent.com/u/123428?v=4
repository: https://github.com/jarrodmillman
---
5 changes: 5 additions & 0 deletions doc/content/about/theme-team/pamphile-roy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "Pamphile Roy"
avatar: https://avatars.githubusercontent.com/u/23188539?u=64445b52dbf3f75de8006ed4264fdd2afaed97a3&v=4
repository: https://github.com/tupui
---
5 changes: 5 additions & 0 deletions doc/content/about/theme-team/stefan-van-der-walt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "Stefan van der Walt"
avatar: https://avatars.githubusercontent.com/u/45071?u=c779b5e06448fbc638bc987cdfe305c7f9a7175e&v=4
repository: https://github.com/stefanv
---
30 changes: 29 additions & 1 deletion doc/content/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,35 @@ in `/news.md`, instead of adding posts to `/news`. Set the
`newsHeader` parameter in the preamble of that document to populate
the banner on the front page.

## Team gallery
## Galleries

The shortcode

```
{{</* gallery pages="./_gallery" columns="2 4 4 5" */>}}
```

with

```
_gallery/
├── ipython.md
├── matplotlib.md
├── networkx.md
├── numpy.md
├── pandas.md
├── scikit-image.md
├── scikit-learn.md
├── scipy.md
├── xarray.md
└── zarr.md
```

will

{{< gallery pages="./_gallery" columns="2 4 4 5" >}}

### Team gallery

The `tools/team_query.py` file gets a list of team members from GitHub. To
use it, you will need to set the GH_TOKEN environment variable
Expand Down
61 changes: 0 additions & 61 deletions doc/static/teams/theme-team.html

This file was deleted.

37 changes: 37 additions & 0 deletions layouts/shortcodes/gallery.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{ $shortcode := . }}

<div class="sd-container-fluid sd-mb-4">
{{- with .Get "columns" -}}
{{ $columns := split . " " }}
{{ $xs := index $columns 0 }}
{{ $sm := index $columns 1 }}
{{ $md := index $columns 2 }}
{{ $lg := index $columns 3 }}
<div class="sd-row sd-row-cols-1 sd-row-cols-xs-{{ $xs }} sd-row-cols-sm-{{ $sm }} sd-row-cols-md-{{ $md }} sd-row-cols-lg-{{ $lg }} sd-g-2 sd-g-xs-{{ $xs }} sd-g-sm-{{ $sm }} sd-g-md-{{ $md }} sd-g-lg-{{ $lg }}">
{{- else }}
<div class="sd-row sd-row-cols-1 sd-row-cols-xs-1 sd-row-cols-sm-2 sd-row-cols-md-3 sd-row-cols-lg-4 sd-g-2 sd-g-xs-2 sd-g-sm-2 sd-g-md-2 sd-g-lg-2">
{{- end }}
{{ $section := .Page.GetPage (.Get "pages") }}
{{ range (or $section.Pages ($section.Resources.ByType "page")) }}
<div class="sd-col sd-d-flex-row">
{{ $link_internal := eq ($shortcode.Get "link") "internal" }}
{{ $link_url := or (and $link_internal .RelPermalink) .Params.repository }}
<div class="sd-card sd-w-100 sd-shadow-sm sd-card-hover">
<div class="sd-card-header">
<p class="sd-card-text">{{ .Title }}</p>
</div>
<div class="sd-card-body">
<p class="sd-card-text">
<img
src="{{ default (relURL "/images/avatar.png") (.Params.avatar) }}"
loading="lazy"
alt="Avatar of {{ .Title }}"
/>
</p>
</div>
<a class="sd-stretched-link" href="{{ $link_url }}"></a>
</div>
</div>
{{ end }}
</div>
</div>
43 changes: 13 additions & 30 deletions tools/team_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ def api(query):
parser = argparse.ArgumentParser(description="Generate team gallery from GitHub")
parser.add_argument("--org", required=True, help="GitHub organization name")
parser.add_argument("--team", required=True, help="Team name in the organization")
parser.add_argument("--dir", required=True, help="Directory for team members")
args = parser.parse_args()

org = args.org
team = args.team
directory = os.path.join(args.dir, team)
os.makedirs(directory, exist_ok=True)

token = os.environ.get("GH_TOKEN", None)
if token is None:
Expand All @@ -61,38 +64,18 @@ def api(query):
members = resp["data"]["organization"]["team"]["members"]["nodes"]
team_name = resp["data"]["organization"]["team"]["name"]

team_template = string.Template(
"""\
<div class="team">
<h3 id="${team}" class="team-name">${team_name}</h3>
<div class="team-members">
${members}
</div>
</div>"""
)

member_template = string.Template(
"""\
<div class="team-member">
<a href="${url}" class="team-member-name">
<div class="team-member-photo">
<img
src="${avatarUrl}"
loading="lazy"
alt="Avatar of ${name}"
/>
</div>
${name}
</a>
</div>"""
"""---
title: "${name}"
avatar: ${avatarUrl}
repository: ${url}
---
"""
)

members_list = []
for m in members:
m["name"] = m["name"] or m["login"]
members_list.append(member_template.substitute(**m))

members_str = "".join(members_list)
team_str = team_template.substitute(members=members_str, team=team, team_name=team_name)

print(team_str)
filename = os.path.join(directory, f"{m['name'].lower().replace(' ', '-')}.md")
text = member_template.substitute(**m)
with open(filename, "w") as file:
file.write(text)