Skip to content

Commit b59c2d7

Browse files
Add header links to github/colab/binder
Add ablog with tags, authors, and categories Modify example notebooks
1 parent 22af744 commit b59c2d7

File tree

12 files changed

+627
-295
lines changed

12 files changed

+627
-295
lines changed

doc/.templates/nb-badges.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% if pagename in ablog %}
2+
3+
<!-- Generate correct links and render github/binder/colab badges -->
4+
{% set gh_basepath = github_user + '/' + github_repo + '/blob/' + github_version + '/' %}
5+
{% set encoded_base = github_user + '%252F' + github_repo %}
6+
{% set gh_binder = github_user + '/' + github_repo + '/' + github_version %}
7+
{% set doc_path_aux = doc_path | trim('/') %}
8+
{% set file_path = doc_path_aux + '/' + pagename + ".ipynb" %}
9+
{% set encoded_path = file_path | replace("/", "%252F") %}
10+
11+
12+
<div class="sd-text-right">
13+
<p>
14+
<a href="{{ github_url + '/' + gh_basepath + file_path }}", role="button" target="_blank">
15+
<img src="{{ pathto('_static/github.svg', 1) }}" alt="View On GitHub"></a>
16+
17+
<a href="{{ 'https://mybinder.org/v2/gh/' + sandbox_repo + '?urlpath=git-pull%3Frepo%3Dhttps%253A%252F%252Fgithub.com%252F' + encoded_base + '%26urlpath%3Dtree%252F' + github_repo + '%252F' + encoded_path + '%26branch%3D' + github_version }}" target="_blank">
18+
<img src="{{ pathto('_static/binder.svg', 1) }}" alt="Open In Binder"></a>
19+
20+
<a href="{{ 'https://colab.research.google.com/github/' + gh_basepath + file_path }}" target="_blank">
21+
<img src="{{ pathto('_static/colab.svg', 1) }}" alt="Open In Colab"/></a>
22+
</p>
23+
</div>
24+
{% endif %}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- continuation of examples/page_footer.md -->
2+
{% if pagename in ablog %}
3+
{% set post = ablog[pagename] %}
4+
{% for coll in post.author %}
5+
{% if coll|length %}
6+
{{ coll }}
7+
{% if loop.index < post.author | length %},{% endif %}
8+
{% else %}
9+
{{ coll }}
10+
{% if loop.index < post.author | length %},{% endif %}
11+
{% endif %}
12+
{% endfor %}. "{{ title.split(' — ')[0] }}". In: <i>Pytensor Examples</i>. Ed. by Pytensor Team. <!-- DOI: <a href={{ doi_url }}>{{ doi_code }}</a> -->
13+
{% endif %}

doc/blog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
orphan: true
3+
---
4+
5+
# Recent updates
6+
7+
<!-- auto generated by ablog so it's empty -->

doc/conf.py

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
# pytensor documentation build configuration file, created by
2-
# sphinx-quickstart on Tue Oct 7 16:34:06 2008.
3-
#
4-
# This file is execfile()d with the current directory set to its containing
5-
# directory.
6-
#
7-
# The contents of this file are pickled, so don't put values in the namespace
8-
# that aren't pickleable (module imports are okay, they're removed
9-
# automatically).
10-
#
11-
# All configuration values have a default value; values that are commented out
12-
# serve to show the default value.
13-
14-
# If your extensions are in another directory, add it here. If the directory
15-
# is relative to the documentation root, use Path.absolute to make it
16-
# absolute, like shown here.
17-
# sys.path.append(str(Path("some/directory").absolute()))
18-
191
import os
202
import inspect
213
import sys
@@ -37,6 +19,7 @@
3719
"sphinx.ext.mathjax",
3820
"sphinx_design",
3921
"sphinx.ext.intersphinx",
22+
"ablog",
4023
"myst_nb",
4124
"generate_gallery",
4225
]
@@ -96,6 +79,7 @@
9679
# List of directories, relative to source directories, that shouldn't be
9780
# searched for source files.
9881
exclude_dirs = ["images", "scripts", "sandbox"]
82+
exclude_patterns = ['page_footer.md', '**/*.myst.md']
9983

10084
# The reST default role (used for this markup: `text`) to use for all
10185
# documents.
@@ -160,15 +144,27 @@
160144
"type": "fontawesome",
161145
},
162146
],
147+
"secondary_sidebar_items": ["page-toc", "edit-this-page", "sourcelink", "donate"],
148+
"navbar_start": ["navbar-logo"],
149+
"article_header_end": ["nb-badges"],
150+
"article_footer_items": ["rendered_citation.html"],
163151
}
164152
html_context = {
153+
"github_url": "https://github.com",
165154
"github_user": "pymc-devs",
166155
"github_repo": "pytensor",
167-
"github_version": "main",
156+
"github_version": version if "." in rtd_version else "main",
157+
"sandbox_repo": f"pymc-devs/pymc-sandbox/{version}",
168158
"doc_path": "doc",
169159
"default_mode": "light",
170160
}
171161

162+
# Add any paths that contain custom static files (such as style sheets) here,
163+
# relative to this directory. They are copied after the builtin static files,
164+
# so a file named "default.css" will overwrite the builtin "default.css".
165+
# html_static_path = ["../_static"]
166+
html_extra_path = ["_thumbnails", 'images', "robots.txt"]
167+
templates_path = [".templates"]
172168

173169
# The name for this set of Sphinx documents. If None, it defaults to
174170
# "<project> v<release> documentation".
@@ -311,18 +307,50 @@ def find_source():
311307
]
312308
myst_dmath_double_inline = True
313309

310+
citation_code = f"""
311+
```bibtex
312+
@incollection{{citekey,
313+
author = "<notebook authors, see above>",
314+
title = "<notebook title>",
315+
editor = "Pytensor Team",
316+
booktitle = "Pytensor Examples",
317+
}}
318+
```
319+
"""
320+
314321
myst_substitutions = {
315322
"pip_dependencies": "{{ extra_dependencies }}",
316323
"conda_dependencies": "{{ extra_dependencies }}",
317324
"extra_install_notes": "",
325+
"citation_code": citation_code,
318326
}
319327

320328
nb_execution_mode = "off"
321329
nbsphinx_execute = "never"
322330
nbsphinx_allow_errors = True
323331

332+
rediraffe_redirects = {
333+
"index.md": "gallery.md",
334+
}
324335

325336
# -- Bibtex config -------------------------------------------------
326337
bibtex_bibfiles = ["references.bib"]
327338
bibtex_default_style = "unsrt"
328339
bibtex_reference_style = "author_year"
340+
341+
342+
# -- ablog config -------------------------------------------------
343+
blog_baseurl = "https://pytensor.readthedocs.io/en/latest/index.html"
344+
blog_title = "Pytensor Examples"
345+
blog_path = "blog"
346+
blog_authors = {
347+
"contributors": ("Pytensor Contributors", "https://pytensor.readthedocs.io"),
348+
}
349+
blog_default_author = "contributors"
350+
post_show_prev_next = False
351+
fontawesome_included = True
352+
# post_redirect_refresh = 1
353+
# post_auto_image = 1
354+
# post_auto_excerpt = 2
355+
356+
notfound_urls_prefix = "/projects/examples/en/latest/"

doc/environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies:
2020
- myst-nb
2121
- matplotlib
2222
- watermark
23+
- ablog
2324
- pip
2425
- pip:
2526
- -e ..

doc/gallery/page_footer.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## License notice
2+
All the notebooks in this example gallery are provided under the
3+
[MIT License](https://github.com/pymc-devs/pytensor/blob/main/LICENSE)
4+
which allows modification, and redistribution for any
5+
use provided the copyright and license notices are preserved.
6+
7+
## Citing PyMC examples
8+
9+
To cite this notebook, use the DOI provided by Zenodo for the pytensor repository.
10+
11+
:::{important}
12+
Many notebooks are adapted from other sources: blogs, books... In such cases you should
13+
cite the original source as well.
14+
15+
Also remember to cite the relevant libraries used by your code.
16+
:::
17+
18+
Here is an example citation template in bibtex:
19+
20+
{{ citation_code }}
21+
22+
which once rendered could look like:
23+
24+
<!-- continues in _templates/page.html!!! -->
25+
<!-- I wanted to get some kind of automatation to the process,
26+
and html templates have access to many variables that are not available
27+
from jinja-myst -->

0 commit comments

Comments
 (0)