Skip to content

Commit

Permalink
make cards an extension (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
nabobalis authored Aug 10, 2024
1 parent 27acfd2 commit bd03114
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
3 changes: 1 addition & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2
build:
os: ubuntu-22.04
os: ubuntu-lts-latest
tools:
python: "mambaforge-latest"
jobs:
Expand All @@ -24,6 +24,5 @@ python:
install:
- method: pip
extra_requirements:
- all
- docs
path: .
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"sphinx.ext.napoleon",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"sunpy_sphinx_theme.cards",
]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
source_suffix = ".rst"
Expand Down
6 changes: 0 additions & 6 deletions src/sunpy_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
from pydata_sphinx_theme import utils
from sphinx.application import Sphinx

from .cards import Card, _Card, depart_card_node, visit_card_node

__all__ = ["get_html_theme_path", "ON_RTD", "PNG_ICON", "SVG_ICON"]


Expand Down Expand Up @@ -141,12 +139,8 @@ def setup(app: Sphinx):
theme_dir = get_html_theme_path()
app.add_html_theme("sunpy", theme_dir)
app.add_css_file("sunpy_style.css", priority=600)
app.add_css_file("sunpy_cards.css", priority=600)
app.add_directive("custom-card", Card)
app.add_node(_Card, html=(visit_card_node, depart_card_node))
app.connect("builder-inited", update_config)
app.connect("html-page-context", update_html_context)

# Conditionally include goat counter js
# We can't do this in update_config as that causes the scripts to be duplicated.
# Also in here none of the theme defaults have be applied by `update_config`
Expand Down
13 changes: 12 additions & 1 deletion src/sunpy_sphinx_theme/cards.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""
This provides the card extension from the website into the theme.
This provides a card extension for the website.
"""

from docutils import nodes
from docutils.parsers.rst import Directive, directives
from sphinx.application import Sphinx

__all__ = ["Card", "_Card", "visit_card_node", "depart_card_node"]

Expand Down Expand Up @@ -97,3 +98,13 @@ def run(self):
)
self.state.nested_parse(self.content, 0, out)
return [out]


def setup(app: Sphinx):
app.add_css_file("sunpy_cards.css", priority=600)
app.add_directive("custom-card", Card)
app.add_node(_Card, html=(visit_card_node, depart_card_node))
return {
"parallel_read_safe": True,
"parallel_write_safe": True,
}

0 comments on commit bd03114

Please sign in to comment.