http://Linuxleren.nl: website met sphinx

Sphinx is een handig instrument om mooie en intelligente documentatie te ontwikkelen. Het maakt gebruik van de RestructuredText-markup om 1 enkel tekstdocument om te zetten naar html, LaTeX, Epub. Ideaal dus om zowel een website als handboek aan te maken.


Waarom?


Mijn interesse ligt in de eerste plaats bij de website. Graag had ik een statische website: geen gedoe met php, databases, en frameworks die je contstant moet updaten om hacking te voorkomen. Bovendien kan je een statische site ook op een heel eenvoudige server draaien met een lichtgewicht webserver als lighttpd (https://www.lighttpd.net/).  Statisch heeft ook nadelen: geen zoekfunctie, zelf html schrijven, geen interactie met bezoekers, moeilijk te onderhouden als de site wat groter wordt,  enz.

Om de nadelen wat aan te pakken is de keuze voor sphinx gemaakt. Met sphinx is het heel gemakkelijk om een grotere site te maken, heb je een zoekfunctie, moet je geen html zelf schrijven (wel restructuredtext). Meer voordelen van sphinx kun je lezen op http://www.sphinx-doc.org/en/stable/


Installatie op debian stretch


Er zijn genoeg handleidingen online die je correct info geven hoe je sphinx moet installeren. Ik spits me toe op mijn configuratie.

Sphinx is een python-project dat aanwezig is in de Debiansoftwarebronnen. Installeer de versie van python3. Het is ook aan te raden om direct wat extra thema's te installeren.  In terminal wordt je root en voer volgend commando uit:

apt install python3-sphinx  python3-sphinx-bootstrap-theme python3-sphinx-rtd-theme python3-pallets-sphinx-themes

Het thema op de website is sphinxbootstrap4. Dit zit niet in Debian. Hiervoor moet je eerst de python-installer via Debian installeren. Vervolgens moet je vanuit de python-installer het thema installeren.

apt install python3-pip

pip3 install sphinxbootstrap4theme


Voila, je kunt eraan beginnen ;-) Volg instructies op
http://www.sphinx-doc.org/en/stable/tutorial.html


Stap voor stap: aanmaken van de website met sphinx


Maak een map aan waarin je de website zult plaatsen. Dit doe je in terminal als gewone gebruiker.

mkdir mijn-website
cd mijn-website


Start de sphinx-quickstart op


sphinx-quickstart


Dit zijn mijn keuzes (niet ingevuld is gewoon op enter drukken) 


> Selected rooth path: seperate source and build directories: y
> Name prefix for templates and static dir [_]:
> Project name: test
> Author name(s): mijn naam
> Project release []: 0.1
> Project language [en]: nl
> Source file suffix [.rst]:
> Name of your master document (without suffix) [index]:
> Do you want to use the epub builder (y/n) [n]:
> autodoc: automatically insert docstrings from modules (y/n) [n]: y
> doctest: automatically test code snippets in doctest blocks (y/n) [n]:
> intersphinx: link between Sphinx documentation of different projects (y/n) [n]:
> todo: write "todo" entries that can be shown or hidden on build (y/n) [n]:
> coverage: checks for documentation coverage (y/n) [n]:
> imgmath: include math, rendered as PNG or SVG images (y/n) [n]:
> mathjax: include math, rendered in the browser by MathJax (y/n) [n]:
> ifconfig: conditional inclusion of content based on config values (y/n) [n]: y
> viewcode: include links to the source code of documented Python objects (y/n) [n]:
> githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]
> Create Makefile? (y/n) [y]:
> Create Windows command file? (y/n) [y]: n


Voila. Het zit erop:

Finished: An initial directory structure has been created.

You should now populate your master file ./source/index.rst and create other documentation source files. Use the Makefile to build the docs, like so:
   make builder
where "builder" is one of the supported builders, e.g. html, latex or linkcheck.



Pas  in de map source het bestand conf.py aan. Hier volgt mijn conf.py voor linuxleren.nl

# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = 'linuxleren'
copyright = '2018, Koen Wybo'
author = 'Koen Wybo'

# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = ''


# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.intersphinx',
    'sphinx.ext.todo',
    'sphinx.ext.ifconfig',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'nl'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = []

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'


# -- Options for HTML output -------------------------------------------------

import sphinxbootstrap4theme

#html_theme = "yummy_sphinx_theme"
#html_theme_path = ["_themes", ]

html_theme = 'sphinxbootstrap4theme'
html_theme_path = [sphinxbootstrap4theme.get_path()]

# Html logo in navbar.
# Fit in the navbar at the height of image is 37 px.
html_logo = '_static/logo.png'


html_theme_options = {
    # Navbar style.
    # Values: 'fixed-top', 'full' (Default: 'fixed-top')
    'navbar_style' : 'fixed-top',

    # Navbar link color modifier class.
    # Values: 'dark', 'light' (Default: 'dark')
    'navbar_color_class' : 'dark',

    # Navbar background color class.
    # Values: 'inverse', 'primary', 'faded', 'success',
    #         'info', 'warning', 'danger' (Default: 'inverse')
    'navbar_bg_class' : 'inverse',

    # Show global TOC in navbar.
    # To display up to 4 tier in the drop-down menu.
    # Values: True, False (Default: True)
    'navbar_show_pages' : False,

    # Link name for global TOC in navbar.
    # (Default: 'Pages')
    'navbar_pages_title' : 'Pages',

    # Specify a list of menu in navbar.
    # Tuples forms:
    #  ('Name', 'external url or path of pages in the document', boolean)
    # Third argument:
    # True indicates an external link.
    # False indicates path of pages in the document.
    'navbar_links' : [
    ('Linux Leren', 'index', False),
        ("Boek", "boek/boek", False),
        ("Leer Debian", "online-doc/index-handleiding", False)
       #        ("Nieuwsbrief", "nieuwsbrief/index", False)
     ],

    # Total width(%) of the document and the sidebar.
    # (Default: 80%)
    'main_width' : '80%',

    # Render sidebar.
    # Values: True, False (Default: True)
    'show_sidebar' : False,

    # Render sidebar in the right of the document.
    # Values:True, False (Default: False)
    'sidebar_right': False,

    # Fix sidebar.
    # Values: True, False (Default: True)
    'sidebar_fixed': True,

    # Html table header class.
    # Values: 'inverse', 'light' (Deafult: 'inverse')
    'table_thead_class' : 'inverse'
}



# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
#html_theme = 'Guzzle'

# Theme options are theme-specific and customize the look and feel of a theme
# further.  For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself.  Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'linuxlerendoc'


# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
    # The paper size ('letterpaper' or 'a4paper').
    #
    # 'papersize': 'letterpaper',

    # The font size ('10pt', '11pt' or '12pt').
    #
    # 'pointsize': '10pt',

    # Additional stuff for the LaTeX preamble.
    #
    # 'preamble': '',

    # Latex figure (float) alignment
    #
    # 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
#  author, documentclass [howto, manual, or own class]).
latex_documents = [
    (master_doc, 'linuxleren.tex', 'linuxleren Documentation',
     'Koen Wybo', 'manual'),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
    (master_doc, 'linuxleren', 'linuxleren Documentation',
     [author], 1)
]


# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
#  dir menu entry, description, category)
texinfo_documents = [
    (master_doc, 'linuxleren', 'linuxleren Documentation',
     author, 'linuxleren', 'One line description of project.',
     'Miscellaneous'),
]


# -- Extension configuration -------------------------------------------------

# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}

# -- Options for todo extension ----------------------------------------------

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True





Maak een index.rst aan in source. Schrijf je tekst in RestructuredText-markup. Heel veel info vind je op http://www.sphinx-doc.org/en/stable/tutorial.html

Vervolgens maak je je website aan met

make html 

Dit doe je in de map van de website.

De website is terug te vinden in ./build/html/