-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
159 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
""" | ||
This provides the card extension from the website into the theme. | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
from docutils import nodes | ||
from docutils.parsers.rst import Directive, directives | ||
from sphinx.util.fileutil import copy_asset | ||
|
||
__all__ = ["Card", "visit_card_node", "depart_card_node", "copy_asset_files"] | ||
|
||
|
||
class _card(nodes.General, nodes.Element): | ||
pass | ||
|
||
|
||
def visit_card_node(self, node) -> None: | ||
title = node.get("title", "") | ||
key = title or node["github"] | ||
key = key.lower().replace(" ", "-") | ||
title = f"<h4>{title}</h4>" if len(title) > 0 else "" | ||
col_extra_class = "column-half" if title else "" | ||
body = f"""<div class="column {col_extra_class}"> | ||
{title} | ||
<div class="card"> | ||
<img class="dark-light" src="/_static/img/{node['img_name']}" alt="{node['name']}"> | ||
<p>{node['name']}</p> | ||
<p><button type="button" class="btn btn-sunpy btn-sunpy1" data-bs-toggle="modal" data-bs-target="#{key}">More Info</button></p> | ||
<div class="modal fade" id="{key}" tabindex=-1> | ||
<div class="modal-dialog modal-lg"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h4 class="modal-title center">{node['name']}</h4> | ||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | ||
</div> | ||
<div class="modal-body"> | ||
""" | ||
self.body.append(body) | ||
|
||
|
||
def depart_card_node(self, node) -> None: | ||
body = f""" | ||
<p>Affiliation: <a href="{node['aff_link']}">{node['aff_name']}</a></p> | ||
<p>GitHub: <a href="https://github.com/{node['github']}">{node['github']}</a></p> | ||
<p>Start Date: {node['date']}</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div></div>""" | ||
self.body.append(body) | ||
|
||
|
||
class Card(Directive): | ||
has_content = True | ||
required_arguments = 1 | ||
optional_arguments = 6 | ||
option_spec = { # NOQA: RUF012 | ||
"img_name": directives.unchanged, | ||
"title": directives.unchanged, | ||
"github": directives.unchanged, | ||
"aff_name": directives.unchanged, | ||
"aff_link": directives.unchanged, | ||
"date": directives.unchanged, | ||
"desc": directives.unchanged, | ||
} | ||
|
||
def run(self): | ||
title = self.options.get("title") if "title" in self.options else "" | ||
img_name = self.options.get("img_name") if "img_name" in self.options else "sunpy_icon.svg" | ||
github = self.options.get("github") if "github" in self.options else "" | ||
aff_name = self.options.get("aff_name") if "aff_name" in self.options else "" | ||
aff_link = self.options.get("aff_link") if "aff_link" in self.options else "" | ||
date = self.options.get("date") if "date" in self.options else "" | ||
desc = self.options.get("desc") if "desc" in self.options else "N/A" | ||
name = " ".join(self.arguments) | ||
out = _card( | ||
name=name, | ||
img_name=img_name, | ||
title=title, | ||
github=github, | ||
aff_name=aff_name, | ||
aff_link=aff_link, | ||
date=date, | ||
desc=desc, | ||
) | ||
self.state.nested_parse(self.content, 0, out) | ||
return [out] | ||
|
||
|
||
def copy_asset_files(app, exc) -> None: | ||
if exc is None: # Build succeeded | ||
for path in (Path(__file__).parent / "static").glob("*"): | ||
copy_asset(str(path), str(Path(app.outdir) / Path("_static"))) |