Skip to content

Commit

Permalink
Merge branch 'main' into cookbook-gallery-196
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-rose authored Jun 7, 2024
2 parents fb316ef + e91753a commit 0f8e601
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 213 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/update-cookbook-gallery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
shell: bash -l {0}
steps:
- name: Find Comment
uses: peter-evans/find-comment@v2
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.issue.number }}
Expand All @@ -23,7 +23,7 @@ jobs:

- name: Create comment
if: steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v3
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body: |
Expand All @@ -33,7 +33,7 @@ jobs:
- name: Update comment
if: steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v3
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
branch: cookbook-gallery-${{ github.event.issue.number }}

- name: Find Comment
uses: peter-evans/find-comment@v2
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.issue.number }}
Expand All @@ -141,7 +141,7 @@ jobs:

- name: Create comment
if: steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v3
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body: |
Expand All @@ -151,7 +151,7 @@ jobs:
- name: Update comment
if: steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v3
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
Expand Down
8 changes: 3 additions & 5 deletions site/_extensions/cookbook_gallery_generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from gallery_generator import build_from_repos, generate_menu, generate_repo_dicts


def main(app):

with open("cookbook_gallery.txt") as fid:
Expand All @@ -15,8 +14,8 @@ def main(app):
for line in fid:
subtext = subtext + line

submit_btn_link = "https://github.com/ProjectPythia/cookbook-gallery/issues/new?assignees=ProjectPythia%2Feducation&labels=content%2Ccookbook-gallery-submission&template=update-cookbook-gallery.yaml&title=Update+Gallery+with+new+Cookbook"
submit_btn_txt = "Submit a new Cookbook"
submit_btn_link = "https://projectpythia.org/cookbook-guide.html"
submit_btn_txt = "How can I create a new Cookbook?"
menu_html = generate_menu(
repo_dicts, submit_btn_txt=submit_btn_txt, submit_btn_link=submit_btn_link
)
Expand All @@ -25,6 +24,5 @@ def main(app):
repo_dicts, "index", title=title, subtext=subtext, menu_html=menu_html
)


def setup(app):
app.connect("builder-inited", main)
app.connect("builder-inited", main)
102 changes: 55 additions & 47 deletions site/_extensions/gallery_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import itertools, json, yaml, pathlib, subprocess, requests
from truncatehtml import truncate
import re


def _grab_binder_link(repo):
Expand Down Expand Up @@ -43,6 +44,12 @@ def _run_cffconvert(command):
error_message = stderr.decode("utf-8").strip()
raise RuntimeError(f"cffconvert command failed: {error_message}")

def _make_standard_name(name):
'''Take string input like LASTNAME, FIRSTNAME and return FIRSTNAME LASTNAME without comma'''
lastfirst = name.split(', ')
firstlast = lastfirst[::-1]
standard = ' '.join(firstlast)
return standard

def generate_repo_dicts(all_items):

Expand All @@ -60,7 +67,7 @@ def generate_repo_dicts(all_items):
cookbook_title = citation_dict["title"]
description = citation_dict["description"]
creators = citation_dict["creators"]
names = [creator.get("name") for creator in creators]
names = [_make_standard_name(creator.get("name")) for creator in creators]
authors = ", ".join(names)

gallery_info_url = f"https://raw.githubusercontent.com/ProjectPythia/{repo}/main/_gallery_info.yml"
Expand Down Expand Up @@ -107,14 +114,18 @@ def _generate_sorted_tag_keys(repo_dicts):
return sorted(key_set)


def _title_case_preserve(s):
return re.sub(r'\b(\w)', lambda m: m.group(1).upper(), s)

def _generate_tag_set(repo_dicts, tag_key=None):

tag_set = set()
for repo_dict in repo_dicts:
for k, e in repo_dict["tags"].items():
tags = [_title_case_preserve(t) for t in e]
if tag_key and k != tag_key:
continue
for t in e:
for t in tags:
tag_set.add(t)

return tag_set
Expand All @@ -126,20 +137,18 @@ def _generate_tag_menu(repo_dicts, tag_key):
tag_list = sorted(tag_set)

options = "".join(
f'<li><label class="dropdown-item checkbox {tag_key}"><input type="checkbox" rel={tag.replace(" ", "-")} onchange="change();">&nbsp;{tag}</label></li>'
f'<li><label class="dropdown-item checkbox {tag_key}"><input type="checkbox" rel={tag.replace(" ", "-").lower()} onchange="change();">&nbsp;{tag}</label></li>'
for tag in tag_list
)

return f"""
<div class="dropdown">
<button class="btn btn-sm btn-outline-primary mx-1 dropdown-toggle" type="button" id="{tag_key}Dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{tag_key.title()}
</button>
<ul class="dropdown-menu" aria-labelledby="{tag_key}Dropdown">
{options}
</ul>
</div>
:::{{dropdown}} {tag_key}
<div class="dropdown">
<ul>
{options}
</ul>
</div>
:::
"""


Expand Down Expand Up @@ -194,12 +203,11 @@ def build_from_repos(
tag_list = sorted((itertools.chain(*tag_dict.values())))
tag_list_f = [tag.replace(" ", "-") for tag in tag_list]
tags = [
f'<span class="badge bg-primary mybadges">{tag}</span>'
f'<span class="badge bg-primary mybadges">{_title_case_preserve(tag)}</span>'
for tag in tag_list_f
]
tags = "\n".join(tags)

# tag_class_str = " ".join(tag_list_f)
tag_classes = " ".join(tag_list_f)

description = repo_dict["description"]
ellipsis_str = '<a class="modal-btn"> ... more</a>'
Expand All @@ -208,68 +216,68 @@ def build_from_repos(
if ellipsis_str in short_description:
modal_str = f"""
<div class="modal">
<div class="content">
<img src="{thumbnail_url}" class="modal-img" />
<h3 class="display-3">{cookbook_title}</h3>
{authors_str}
<p class="my-2">{description}</p>
<p class="my-2">{tags}</p>
<p class="mt-3 mb-0"><a href="{cookbook_url}" class="btn btn-outline-primary btn-block">Visit Website</a></p>
</div>
<div class="content">
<img src="{thumbnail_url}" class="modal-img" />
<h3 class="display-3">{cookbook_title}</h3>
{authors_str}
<p class="my-2">{description}</p>
<p class="my-2">{tags}</p>
<p class="mt-3 mb-0"><a href="{cookbook_url}" class="btn btn-outline-primary btn-block">Visit Website</a></p>
</div>
</div>
"""
modal_str = '\n'.join([m.lstrip() for m in modal_str.split('\n')])
else:
modal_str = ""
new_card = f"""\

new_card = f"""
:::{{grid-item-card}}
:shadow: md
:class-footer: card-footer
<div class="d-flex gallery-card">
<img src="{thumbnail_url}" class="gallery-thumbnail" />
<div class="container">
<a href="{cookbook_url}" class="text-decoration-none"><h4 class="display-4 p-0">{cookbook_title}</h4></a>
<p class="card-subtitle">{authors_str}</p>
<p class="my-2">{short_description} </p>
</div>
</div>
{modal_str}
+++
<div class="tagsandbadges">
{tags}
<div>{status_badges}</div>
</div>
:class-card: tagged-card {tag_classes}
<div class="d-flex gallery-card">
<img src="{thumbnail_url}" class="gallery-thumbnail" />
<div class="container">
<a href="{cookbook_url}" class="text-decoration-none"><h4 class="display-4 p-0">{cookbook_title}</h4></a>
<p class="card-subtitle">{authors_str}</p>
<p class="my-2">{short_description} </p>
</div>
</div>
{modal_str}
+++
<div class="tagsandbadges">
{tags}
<div>{status_badges}</div>
</div>
:::
"""

grid_body.append('\n'.join([m.lstrip() for m in new_card.split('\n')]))


grid_body = "\n".join(grid_body)

stitle = f"#### {subtitle}" if subtitle else ""
stext = subtext if subtext else ""

grid_body = "\n".join(grid_body)

grid = f"""
# {title}
{'=' * len(title)}
{stitle}
{stext}
{menu_html}
::::{{grid}} 1
:gutter: 4
:gutter: 0
{grid_body}
<div class="modal-backdrop"></div>
<script src="/_static/custom.js"></script>
<script src="../html/_static/custom.js"></script>
"""

grid = '\n'.join([m.lstrip() for m in grid.split('\n')])
Expand Down
46 changes: 46 additions & 0 deletions site/_static/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,49 @@ main.banner-main #project-pythia {
.tagsandbadges {
padding: 0 0;
}

.dropdown ul {
list-style: none;
padding: 0;
margin: 0;
}

.dropdown-item {
display: block;
}

.dropdown-item input[type="checkbox"] {
margin-right: 0.5em;
}

details.sd-dropdown {
box-shadow: none !important;
}

details.sd-dropdown summary.sd-card-header + div.sd-summary-content {
background-color: white !important;
border: 0.2rem solid var(--pst-sd-dropdown-color) !important;
border-radius: calc(.25rem - 1px);
}

.bd-content .sd-card .sd-card-header {
background-color: var(--pst-color-panel-background) !important;
}

.sd-summary-content.sd-card-body.docutils {
position: absolute;
z-index: 100;
}

details.sd-dropdown summary.sd-card-header {
border: 0.2rem solid var(--pst-sd-dropdown-color) !important;
border-radius: calc(.25rem - 1px);
}

p {
color: black;
}

.sd-col.sd-d-flex-row.docutils.has-visible-card {
margin-bottom: 1rem;
}
Loading

0 comments on commit 0f8e601

Please sign in to comment.