Skip to content

Commit

Permalink
Merge pull request NHERI-SimCenter#70 from ioannis-vm/docs
Browse files Browse the repository at this point in the history
Introduce documentation pages.
  • Loading branch information
zsarnoczay authored Nov 5, 2024
2 parents 11c9d64 + c01f906 commit 261a8e8
Show file tree
Hide file tree
Showing 64 changed files with 4,796 additions and 289 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/build_docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build and deploy documentation
on:
push:
branches:
- docs
jobs:
build-docs:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ['3.10']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y pandoc
python -m pip install -e .[development]
- name: Build docs
run: cd doc && make html
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./doc/build/html
32 changes: 32 additions & 0 deletions .github/workflows/docs_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Check for Sphinx Warnings

on:
pull_request:
paths:
- "doc/**"
- "**/*.rst"
- ".github/workflows/docs_check.yaml"
- "setup.py"

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Check out the repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y pandoc
python -m pip install -e .[development]
- name: Check for Sphinx warnings
run: |
sphinx-build -M html ./doc/source ./doc/_build --fail-on-warning
20 changes: 20 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions doc/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
56 changes: 56 additions & 0 deletions doc/source/_extensions/latest_citation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# noqa: INP001, CPY001, D100
import requests
from docutils import nodes
from docutils.parsers.rst import Directive


class LatestCitationDirective(Directive): # noqa: D101
def run(self): # noqa: ANN201, D102
citation_text, bibtex_text = self.get_latest_zenodo_citation()

# Create nodes for the standard citation and BibTeX
citation_node = nodes.paragraph(text=citation_text)
bibtex_node = nodes.literal_block(text=bibtex_text, language='bibtex')

return [citation_node, bibtex_node]

def get_latest_zenodo_citation(self): # noqa: PLR6301, ANN201, D102
url = 'https://zenodo.org/api/records/?q=conceptdoi:10.5281/zenodo.2558557&sort=mostrecent'
try:
response = requests.get(url) # noqa: S113
except requests.exceptions.ConnectionError:
return '(No Connection)', ''
data = response.json()
latest_record = data['hits']['hits'][0]
authors = [
author['name'] for author in latest_record['metadata']['creators']
]
combine_chars = [', '] * (len(authors) - 2) + [', and ']
author_str = authors[0]
for author, combine_char in zip(authors[1::], combine_chars):
author_str += combine_char + author
title = latest_record['metadata']['title'].split(': ')[0]
version = latest_record['metadata']['version']
doi = latest_record['metadata']['doi']
year = latest_record['metadata']['publication_date'][:4]
month = latest_record['metadata']['publication_date'][5:7] # noqa: F841
publisher = 'Zenodo'

# Standard citation
citation_text = f'{author_str} ({year}) {title}. DOI:{doi}'

# BibTeX citation
bibtex_text = f"""@software{{{author_str.replace(" ", "_").replace(",", "").replace("_and_", "_").lower()}_{year}_{doi.split('.')[-1]},
author = {{{" and ".join(authors)}}},
title = {{{title}}},
year = {year},
publisher = {{{publisher}}},
version = {{{version}}},
doi = {{{doi}}},
}}"""

return citation_text, bibtex_text


def setup(app): # noqa: ANN201, D103, ANN001
app.add_directive('latest-citation', LatestCitationDirective)
33 changes: 33 additions & 0 deletions doc/source/_static/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
wy-nav-content {
max-width: none;
}


.math {
text-align: left;
}

.eqno {
float: right;
}


#div.wy-side-scroll{
# background:#cb463f;
#}

div.wy-menu.wy-menu-vertical > .caption {
color: #cb463f;
}

# LIGHT BLUE background:#0099ff
# BLUE: background:#0B619C
# ADAM RED: background:#cb463f;

span.caption.caption-text{
color: #000000;
}

td{
white-space: normal !important;
}
150 changes: 150 additions & 0 deletions doc/source/_static/front_page/api-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 261a8e8

Please sign in to comment.