From 2bf447b17bfbb510bb76b4db64b44f9b6525796f Mon Sep 17 00:00:00 2001 From: Jessica Scheick Date: Tue, 21 May 2024 09:56:54 -0400 Subject: [PATCH 1/2] add tutorial gallery to jupyterbook --- .gitignore | 1 + book/_config.yml | 2 + book/_ext/build_gallery.py | 95 ++++++++++++++++++++++++++++++++++++++ book/reference/gallery.yml | 10 ++++ conda/environment.yml | 4 +- 5 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 book/_ext/build_gallery.py create mode 100644 book/reference/gallery.yml diff --git a/.gitignore b/.gitignore index aeeb83c..b4777b0 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ cookiecutter.json /book/_build/html/assets ## Temporary files created by build scripts /team/team.yaml +/book/reference/gallery.txt # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/book/_config.yml b/book/_config.yml index 15e0b5d..8cdb9cf 100644 --- a/book/_config.yml +++ b/book/_config.yml @@ -67,6 +67,8 @@ sphinx: .py: - jupytext.reads - fmt: py:percent + local_extensions: + build_gallery: "_ext" # Add GitHub buttons to your book # See https://jupyterbook.org/customize/config.html#add-a-link-to-your-repository diff --git a/book/_ext/build_gallery.py b/book/_ext/build_gallery.py new file mode 100644 index 0000000..4e9d645 --- /dev/null +++ b/book/_ext/build_gallery.py @@ -0,0 +1,95 @@ +# from https://github.com/excutablebooks meta/docs/conf.py + +from pathlib import Path +import random +from textwrap import dedent +from urllib.parse import urlparse + +import yaml + +from sphinx.application import Sphinx +from sphinx.util import logging +from sphinx.util.typing import ExtensionMetadata + +LOGGER = logging.getLogger("conf") + +def build_gallery(app: Sphinx): + # Build the gallery file + LOGGER.info("building gallery...") + grid_items = [] + projects = yaml.safe_load((Path(app.srcdir) / "reference/gallery.yml").read_text()) + random.shuffle(projects) + for item in projects: + if not item.get("image"): + item["image"] = "https://jupyterbook.org/_images/logo-square.svg" + + repo_text = "" + star_text = "" + + if item["repository"]: + repo_text = f'{{bdg-link-secondary}}`repo <{item["repository"]}>`' + + try: + url = urlparse(item["repository"]) + if url.netloc == "github.com": + _, org, repo = url.path.rstrip("/").split("/") + star_text = f"[![GitHub Repo stars](https://img.shields.io/github/stars/{org}/{repo}?style=social)]({item['repository']})" + except Exception as error: + pass + + grid_items.append( + f"""\ + `````{{grid-item-card}} {" ".join(item["name"].split())} + :text-align: center + + logo + + +++ + ````{{grid}} 2 2 2 2 + :margin: 0 0 0 0 + :padding: 0 0 0 0 + :gutter: 1 + + ```{{grid-item}} + :child-direction: row + :child-align: start + :class: sd-fs-5 + + {{bdg-link-secondary}}`website <{item["website"]}>` + {repo_text} + ``` + ```{{grid-item}} + :child-direction: row + :child-align: end + + {star_text} + ``` + ```` + ````` + """ + ) + grid_items = "\n".join(grid_items) + +# :column: text-center col-6 col-lg-4 +# :card: +my-2 +# :img-top-cls: w-75 m-auto p-2 +# :body: d-none + + panels = f""" +``````{{grid}} 1 2 3 3 +:gutter: 1 1 2 2 + +{dedent(grid_items)} +`````` + """ + (Path(app.srcdir) / "reference/gallery.txt").write_text(panels) + + +def setup(app: Sphinx) -> ExtensionMetadata: + app.connect('builder-inited', build_gallery) + + return { + 'version': '0.1', + 'parallel_read_safe': True, + 'parallel_write_safe': True, + } \ No newline at end of file diff --git a/book/reference/gallery.yml b/book/reference/gallery.yml new file mode 100644 index 0000000..363d2bd --- /dev/null +++ b/book/reference/gallery.yml @@ -0,0 +1,10 @@ +- name: Data access with earthaccess + website: https://earthaccess.readthedocs.io/en/latest/tutorials/file-access/ + repository: https://github.com/nsidc/earthaccess + image: +- name: Data access with icepyx + website: https://icepyx.readthedocs.io/en/latest/example_notebooks/IS2_data_access.html + repository: https://github.com/icesat2py/icepyx + image: https://icepyx.readthedocs.io/en/latest/_static/icepyx_v2_oval_orig_nobackgr.png + + \ No newline at end of file diff --git a/conda/environment.yml b/conda/environment.yml index cdea46d..d5021b2 100644 --- a/conda/environment.yml +++ b/conda/environment.yml @@ -8,14 +8,16 @@ channels: - conda-forge dependencies: - ipyleaflet - - jupyter-book<2 + - jupyter-book - jupyter-resource-usage - jupyterhub-singleuser - jupyterlab - jupytext - pip - python + - sphinx - sphinxcontrib-bibtex + - yaml # For building the Splashpage - cookiecutter # Dependencies of jinja-markdown: From 1e250086304dc7c4b452c5a36dd194809083a9a2 Mon Sep 17 00:00:00 2001 From: Jessica Scheick Date: Tue, 21 May 2024 09:57:16 -0400 Subject: [PATCH 2/2] add IS2 resources page draft to JupyterBook --- book/_toc.yml | 1 + book/reference/IS2-resources.md | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 book/reference/IS2-resources.md diff --git a/book/_toc.yml b/book/_toc.yml index f427aa5..95e65e2 100644 --- a/book/_toc.yml +++ b/book/_toc.yml @@ -32,5 +32,6 @@ parts: chapters: - file: reference/glossary - file: reference/bibliography + - file: reference/IS2-resources - file: reference/questions diff --git a/book/reference/IS2-resources.md b/book/reference/IS2-resources.md new file mode 100644 index 0000000..39c1c9a --- /dev/null +++ b/book/reference/IS2-resources.md @@ -0,0 +1,16 @@ +# ICESat-2 Resources + +A large number of resources exist for helping you get and work with ICESat-2 data. +These range from packages and tutorials created by NSIDC, the DAAC that manages ICESat-2 data, +to community created libraries (such as icepyx and SlideRule) to individual GitHub repositories +created by researchers using ICESat-2 data in their work. + +## Lists of Resources +Both icepyx and NSIDC already have compiled lists of resources for obtaining and working with ICESat-2 data. +We encourage you to check them out, but have not recreated them here so you can always find the latest and greatest. + +## Gallery of Tutorials +The Organizing Team (OT) has compiled this gallery of their favorite tutorials utilizing ICESat-2 data to help you find great example workflows from across disciplines. + +```{include} gallery.txt +``` \ No newline at end of file