Sphinx is the package to create websites in pyton.
Steps done in terminal
.
It should be already installed with Anaconda. If not:
pip install Sphinx
- Go to the project folder:
cd <projectFolder>
- Launch sphinx:
sphinx-quickstart
- Fill out the requirements. Useful entries:
Select root path: .
Enter (alreadycd
ed to the folder)Separate source and build directories (y/n) [n]:
y
imgmath: include math, rendered as PNG or SVG images (y/n) [n]:
y
mathjax: include math, rendered in the browser by MathJax (y/n) [n]:
y
githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]:
y
Create Makefile? (y/n) [y]:
y
If site pages are written in markdown, install markdown parser.
Documentation here: http://www.sphinx-doc.org/en/master/usage/markdown.html
pip install recommonmark
- Open
source/conf.py
and:- Uncomment line 51 and comment line 52 (search if they are not there). It has to look like this:
source_suffix = ['.rst', '.md'] #source_suffix = '.rst'
- Add these lines anywhere (below the previous lines is fine):
source_parsers = { '.md': 'recommonmark.parser.CommonMarkParser', }
- Uncomment line 51 and comment line 52 (search if they are not there). It has to look like this:
Basic documentation here: http://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html
Documentation of python addictions here: http://www.sphinx-doc.org/en/stable/markup/index.html
Basics: http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#paragraphs
It has more functions than markdown (e.g. good for template "guzzle").
make html
- to open it, double click on
build/html/index.html
- List of themes:
- If theme chosen in https://sphinx-themes.org/, click on
pypi
:- Installation: as indicated
- Use: as indicated
make html
- refresh page
- Change theme in
conf.py
inhtml_theme =
. - To see where the theme is installed:
pip show theme_name
(e.g.pip show guzzle_sphinx_theme
)
(The theme for pyKNEEr is guzzle: https://pypi.org/project/guzzle_sphinx_theme/
The theme for my personal website is sphinx-bootstrap: https://pypi.org/project/sphinx-bootstrap-theme/)
- The home page is
source\index.rst
- Add a new
.md
file to the foldersource
- Add the file to
index.rst
, undertoctree
(toc
= table of content). Example: Adding the page "introduction":.. toctree:: :maxdepth: 2 :hidden: introduction
make html
- refresh page
- Some changes for sidebar are allowed in
conf.py
. Example:html_sidebars = { '**': [ 'logo-text.html', ]
- Options for changes in
conf.py
here: http://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_sidebars - To customize changes, for example in
global toc
:- Create the file
globaltoc.html
and put it in the folder_templates
. It overwrites the original one. (Easier to copy the original one (use search to find it) into_templates
) - Modify
_templates\globaltoc.html
- Create the file
- Create
custom.css
insource/_static/css
(if foldercss
does not exist, create it) - In
conf.py
add:def setup(app): app.add_stylesheet('css/custom.css')
- Add the changes (they will overwrite the original css).
- Trick 1: Changes in css do not always update quickly. Write some text somewhere ->
make html
-> refresh the html page. Also the style will be updated - Trick 2: To know the name of the classes to change, look at the content of the html file and find the class name there (in Chrome: right-click on the .html file ->
View page source
; or open with an editor - e.g. Atom )
Example for image usage:
.. image:: picture.jpg
:width: 200px
:height: 100px
:scale: 50 %
:alt: alternate text
:align: right
Example for figure usage:
.. figure:: picture.png
:scale: 50 %
:alt: map to buried treasure
This is the caption of the figure (a simple paragraph).
-
Personal webpage
- Create the repository
yourUserName.github.io
(it has to be this name) - Commit all the content of the
build
folder directly into the repository - Make sure that the repository contains the file
.nojekyll
.
.nojekyll
tells GitHub not to use Jekyll (its default) to build the website..nojekyll
is created when running the commandsphinx-quickstart
to make the website (command:githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]:
y
)..nojekyll
can also be created manually with a text editor as an empty file with that name - (To see/hide the hidden files in mac: https://ianlunn.co.uk/articles/quickly-showhide-hidden-files-mac-os-x-mavericks/) - Go to
settings
->GitHub Pages
->Source
->Master branch
->Save
- The link to the website appears above
Source
. It takes a few minutes to have the website up
- Create the repository
-
Project webpage
- In the repository of your project create a folder called
docs
(it has to be this name) - Commit all the content of the
build
folder directly into the folderdocs
- Make sure that the repository contains the file
.nojekyll
.
.nojekyll
tells GitHub not to use Jekyll (its default) to build the website..nojekyll
is created when running the commandsphinx-quickstart
to make the website (command:githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]:
y
)..nojekyll
can also be created manually with a text editor as an empty file with that name - Go to
settings
->GitHub Pages
->Source
->Master branch/docs folder
->Save
- The link to the website appears above
Source
. It takes a few minutes to have the website up - Note: double-check if
.nojekyll
is needed also in the main folder of the repository
- In the repository of your project create a folder called
Make sure you already have the website address
Go to Google Analytics, and then:
- Go to Admin (bottom left)
- Create account
If the website template already includes support for GA tracking number, enter it as indicated in the template instructions (usually in confy.py
).
If the website templete does not include support for GA tracking number (from: https://www.ericholscher.com/blog/2009/apr/5/adding-google-analytics-sphinx-docs/):
- In the
source
folder, create a fodler_templates
- In
_templates
, create the filelayout.html
and copy/paste these lines:Substitute{% extends "!layout.html" %} {% block footer %} {{ super() }} <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("GAtrackingNumberHere"); pageTracker._trackPageview(); } catch(err) {}</script> {% endblock %}
GAtrackingNumberHere
with your actual number (do not delete the quotes) - Run
make html
Open your index.html
file
- in a text editor (e.g. Atom) and search for your GA code, or
- in Chrome, then right-click ->
View page source
, and search for your GA code