diff --git a/.gitignore b/.gitignore index b175eb0..d3c89b4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ *.egg-info/ build/ dist/ +site/ __pycache__ diff --git a/Makefile b/Makefile index 7a87d4c..5ec855e 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ python := $(run) python lint := rye lint -- --select I fmt := rye fmt mypy := $(run) mypy +mkdocs := $(run) mkdocs ############################################################################## # Local "interactive testing" of the code. @@ -48,6 +49,20 @@ stricttypecheck: # Perform a strict static type checks with mypy .PHONY: checkall checkall: codestyle lint stricttypecheck # Check all the things +############################################################################## +# Documentation. +.PHONY: docs +docs: # Generate the system documentation + $(mkdocs) build + +.PHONY: rtfm +rtfm: # Locally read the library documentation + $(mkdocs) serve + +.PHONY: publishdocs +publishdocs: # Set up the docs for publishing + $(mkdocs) gh-deploy + ############################################################################## # Package/publish. .PHONY: package diff --git a/docs/images/default-output-look.png b/docs/images/default-output-look.png new file mode 100644 index 0000000..cc1cc07 Binary files /dev/null and b/docs/images/default-output-look.png differ diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..476bc40 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,261 @@ +## Introduction + +[`ng2web`](https://github.com/davep/ng2web) is one in a [long line of Norton +Guide tools I've written over the latest couple or so +decades](https://www.davep.org/norton-guides/). It is, in effect, a +replacement for [`w3ng`](https://github.com/davep/w3ng) and +[`ng2html`](https://github.com/davep/ng2html). + +As for what it does: it will take a [Norton Guide +file](https://en.wikipedia.org/wiki/Norton_Guides) and turns the content +into a collection of HTML pages, which you can then incorporate into a web +site. + +## Command line options + +The command is called `ng2web` and all command line options can be found +with: + +```sh +ng2web --help +``` + +giving output like this: + +```bash exec="on" result="text" +ng2web --help +``` + +The key options are: + +### `--index` + +By default `ng2web` generates all pages with names that are prefixed with +the filename of the guide (minus the extension) and, for all pages relating +to short and long entries, including the byte offset of the entry in the +guide; this means that amongst the generated pages there's no obvious +starting location. + +Add the `--index` switch to tell `ng2web` to always generate the first entry +in the guide as the file `index.html`. + +### `--output` + +Use this switch to optionally specify the output directory for the generated +HTML. By default all HTML files will be generated in the current directory. + +### `--templates` + +Use this switch to optionally specify a location to look for templates that +will override the default templates (see [the next section](#templates) in +this document for details on how to use templates to control the output of +`ng2web`). + +## Templates + +The output of `ng2web` is styled using a collection of templates. The +builtin templates are designed to give the output a bit of a classic Norton +Guide reader look. + +![Default look of the output](images/default-output-look.png) + +There are a number of templates that control each of the major types of +content inside a Norton Guide. + +### The base template (`base.html`) + +The base template is the base for the other templates that output a specific +type of page. + +```jinja +--8<-- "src/ng2web/templates/base.html" +``` + +If you wish to change the look and feel of every page in the output, this is +probably the template you want to [override](#overriding-templates). + +### The about page template (`about.html`) + +This is the template for the "about" page of the output; typically this is +where the credits for the guide will be shown. + +```jinja +--8<-- "src/ng2web/templates/about.html" +``` + +### The base entry template (`entry.html`) + +This is the template that both [short](#the-short-entry-template-shorthtml) +and [long](#the-long-entry-template-longhtml) entry templates build upon. + +```jinja +--8<-- "src/ng2web/templates/entry.html" +``` + +### The short entry template (`short.html`) + +This is the template for creating pages from short entries in the guide. +Short entries typically have no "see also" section and also have lines that +link elsewhere. + +```jinja +--8<-- "src/ng2web/templates/short.html" +``` + +### The long entry template (`long.html`) + +This is the template for creating pages from long entries in the guide. Long +entries typically have an optional "see also" section and have lines that +don't link anywhere else; the text content of a long entry is simply text, +not links that go elsewhere. + +```jinja +--8<-- "src/ng2web/templates/long.html" +``` + +### Link navigation include (`inc/nav-link.html`) + +This is a utility include template that is used by [the base +template](#the-base-template-basehtml) to emit the navigation links that +appear at the top of the page: the *About*, *Previous*, *Up* and *Next* +links. + +```jinja +--8<-- "src/ng2web/templates/inc/nav-link.html" +``` + +### The stylesheet template + +The stylesheet for the site is generated using this template. + +```css +--8<-- "src/ng2web/templates/base.css" +``` + +As you'll see: the bulk of this file is just static CSS; the only part +making use of templating being the `span` foreground and background colour +utility classes; the styles being `.bg0` through `.bg15` and `.fg0` through +`.fg15`. By default the expansion is a selection of web colours that best +match the colours common in text modes on PC/DOS systems. + +The default selection is: + +0. black +1. navy +2. green +3. teal +4. maroon +5. purple +6. olive +7. silver +8. gray +9. blue +10. lime +11. aqua +12. red +13. fuchsia +14. yellow +15. white + +## Overriding templates + +### Custom template locations + +By default, when a template is needed, `ng2web` will look in the following +locations, in the following order. Once a template is found that one is +used. + +1. The directory provided with [the `--templates` switch](#-templates). +2. `./templates/`, below the current working directory, if it exists. +3. `ng2web`'s own default templates. + +!!! tip + + You only need to make a copy of a template you actually want to change. + Overriding one template doesn't mean you need to make a copy of all of + them. Each tamplet is individually looked for using these rules. + +## Global values + +The following global variables are available in the templates: + +### `generator` + +The generator name for `ng2web`, this will include the version number of +`ng2web` and of `ngdb` ([the library that `ng2web` is built +on](https://github.com/davep/ngdb.py)). + +An example looks like: + +``` +ng2web v0.1.1 (ngdb v0.12.0) +``` + +### `guide` + +A reference to the guide object that is being used to read the Norton Guide +file. This allows access to [any of the properties and methods of +`ngdb.NortonGuide`](https://blog.davep.org/ngdb.py/library-contents/guide/). + +!!! warning + + It's best to restrict use of this to read-only properties; calling + anything that may change the state of the underlying guide object could + cause unexpected results. + +### `about_url` + +The URL for the about page that will be generated. + +### `stylesheet` + +The name of the stylesheet that will be generated. + +## Available filters + +The following filters are made available in the templates: + +### `urlify` + +Takes a particular linked option within a guide and turns it into a web +link. Most often used when generating links in entries; for example: + +```jinja +{{ line.text|toHTML }} +``` + +### `toHTML` + +Takes some text and makes it safe to use in a HTML document. This can also +be seen being used in the example given above. + +### `title` + +Takes a guide entry and emits a suitable title for it. For example: + +```jinja +{% block title %}{{ entry|title }}{% endblock %} +``` + +The title will be rendered as path of sorts, which will include the title of +the guide, the title of the menu the entry relates to, and the prompt from +the menu that the entry relates to. For example: + +``` +MrDebug for CA-Clipper Ver 1.20.147ß » Reference » Menus +``` + +!!! tip + + As a special case, if you pass `None` as the entry `title` will simply + output the title of the guide. + +## Getting help + +If you need some help using `ng2web`, or have ideas for improvements, please +feel free to drop by [the +discussions](https://github.com/davep/ng2web/discussions) and ask or +suggest. If you believe you've found a bug please feel free to [raise an +issue](https://github.com/davep/ng2web/issues). + +[//]: # (index.md ends here) diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..245a12f --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,39 @@ +site_name: ng2web +docs_dir: docs/ +repo_url: https://github.com/davep/ng2web + +nav: + - "Guide": index.md + +markdown_extensions: + - admonition + - pymdownx.snippets + - pymdownx.superfences: + custom_fences: + - name: bash + class: bash + validator: !!python/name:markdown_exec.validator + format: !!python/name:markdown_exec.formatter + +plugins: + - markdown-exec + +theme: + name: material + features: + - content.code.copy + palette: + - media: "(prefers-color-scheme: light)" + scheme: default + accent: purple + toggle: + icon: material/weather-sunny + name: Switch to dark mode + - media: "(prefers-color-scheme: dark)" + scheme: slate + primary: black + toggle: + icon: material/weather-night + name: Switch to light mode + +### mkdocs.yml ends here diff --git a/pyproject.toml b/pyproject.toml index af890da..8b2ccb1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,7 @@ classifiers = [ ] [project.urls] -Homepage = "https://github.com/davep/ng2web" +Homepage = "https://blog.davep.org/ng2web/" Repository = "https://github.com/davep/ng2web" Documentation = "https://blog.davep.org/ng2web/" Source = "https://github.com/davep/ng2web" @@ -64,6 +64,8 @@ managed = true dev-dependencies = [ "pre-commit>=4.2.0", "mypy>=1.15.0", + "mkdocs-material>=9.6.9", + "markdown-exec>=1.10.2", ] [tool.hatch.metadata] diff --git a/requirements-dev.lock b/requirements-dev.lock index 76ab54f..50fcd26 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -10,19 +10,53 @@ # universal: false -e file:. +babel==2.17.0 + # via mkdocs-material +backrefs==5.8 + # via mkdocs-material +certifi==2025.1.31 + # via requests cfgv==3.4.0 # via pre-commit +charset-normalizer==3.4.1 + # via requests +click==8.1.8 + # via mkdocs +colorama==0.4.6 + # via mkdocs-material distlib==0.3.9 # via virtualenv filelock==3.18.0 # via virtualenv +ghp-import==2.1.0 + # via mkdocs identify==2.6.9 # via pre-commit +idna==3.10 + # via requests jinja2==3.1.6 + # via mkdocs + # via mkdocs-material # via ng2web +markdown==3.7 + # via mkdocs + # via mkdocs-material + # via pymdown-extensions +markdown-exec==1.10.2 markupsafe==3.0.2 # via jinja2 + # via mkdocs # via ng2web +mergedeep==1.3.4 + # via mkdocs + # via mkdocs-get-deps +mkdocs==1.6.1 + # via mkdocs-material +mkdocs-get-deps==0.2.0 + # via mkdocs +mkdocs-material==9.6.9 +mkdocs-material-extensions==1.3.1 + # via mkdocs-material mypy==1.15.0 mypy-extensions==1.0.0 # via mypy @@ -30,14 +64,42 @@ ngdb==0.12.0 # via ng2web nodeenv==1.9.1 # via pre-commit +packaging==24.2 + # via mkdocs +paginate==0.5.7 + # via mkdocs-material +pathspec==0.12.1 + # via mkdocs platformdirs==4.3.7 + # via mkdocs-get-deps # via virtualenv pre-commit==4.2.0 +pygments==2.19.1 + # via mkdocs-material +pymdown-extensions==10.14.3 + # via markdown-exec + # via mkdocs-material +python-dateutil==2.9.0.post0 + # via ghp-import pyyaml==6.0.2 + # via mkdocs + # via mkdocs-get-deps # via pre-commit + # via pymdown-extensions + # via pyyaml-env-tag +pyyaml-env-tag==0.1 + # via mkdocs +requests==2.32.3 + # via mkdocs-material +six==1.17.0 + # via python-dateutil typing-extensions==4.12.2 # via mypy # via ng2web # via ngdb +urllib3==2.3.0 + # via requests virtualenv==20.29.3 # via pre-commit +watchdog==6.0.0 + # via mkdocs