Skip to content

Commit

Permalink
Make logo adapt to dark mode; add source code links to documentation (#…
Browse files Browse the repository at this point in the history
…113)

* Automatic logo adaptation to GitHub dark mode

* Add source code links to documentation

* Adjust page width CSS
  • Loading branch information
gamatos authored Nov 10, 2023
1 parent 04101d5 commit 3832018
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# qujax

<div align="center">
<a href="https://cqcl.github.io/qujax/"><img src="docs/logo.svg" alt="logo"></img></a>
<a href="https://cqcl.github.io/qujax/">
<picture>
<source srcset="docs/logo_dark_mode.svg" media="(prefers-color-scheme: dark)">
<img src="docs/logo.svg">
</picture>
</a>
</div>

[![PyPI - Version](https://img.shields.io/pypi/v/qujax)](https://pypi.org/project/qujax/)
Expand Down
10 changes: 8 additions & 2 deletions docs/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
background: #85cfcb;
}

.wy-nav-content {
max-width: 1000px;
@media screen and (min-width: 1000px) {
.wy-nav-content {
max-width: 1000px;
}
}

html.writer-html4 .rst-content dl:not(.docutils) > dt, html.writer-html5 .rst-content dl[class]:not(.option-list):not(.field-list):not(.footnote):not(.citation):not(.glossary):not(.simple) > dt {
Expand All @@ -50,4 +52,8 @@ h1, h2, h3, h4, h5, h6 {

div.toctree-wrapper .caption-text{
color: #203847;
}

.rst-content .viewcode-back, .rst-content .viewcode-link {
padding-left: 6px;
}
36 changes: 36 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os
import sys
import importlib
import inspect
import pathlib

sys.path.insert(0, os.path.abspath("..")) # pylint: disable=wrong-import-position

Expand All @@ -22,6 +25,7 @@
"sphinx_rtd_theme",
"sphinx.ext.napoleon",
"sphinx.ext.mathjax",
"sphinx.ext.linkcode",
"myst_parser",
]

Expand Down Expand Up @@ -62,3 +66,35 @@
"collapse_navigation": False,
"prev_next_buttons_location": "None",
}


def linkcode_resolve(domain, info):
"""
Called by sphinx's linkcode extension, which adds links directing the user to the
source code of the API objects being documented. The `domain` argument specifies which
programming language the object belongs to. The `info` argument is a dictionary with
information specific to the programming language of the object.
For Python objects, this dictionary contains a `module` key with the module the object is in
and a `fullname` key with the name of the object. This function uses this information to find
the source file and range of lines the object is defined in and to generate a link pointing to
those lines on GitHub.
"""
github_url = f"https://github.com/CQCL/qujax/tree/develop/qujax"

if domain != "py":
return

module = importlib.import_module(info["module"])
obj = getattr(module, info["fullname"])

try:
path = pathlib.Path(inspect.getsourcefile(obj))
file_name = path.name
lines = inspect.getsourcelines(obj)
except TypeError:
return

start_line, end_line = lines[1], lines[1] + len(lines[0]) - 1

return f"{github_url}/{file_name}#L{start_line}-L{end_line}"
55 changes: 55 additions & 0 deletions docs/logo_dark_mode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3832018

Please sign in to comment.