kb4it with no command, in a terminal, opens the terminal interface. With a command it works like any other command-line tool.
| Command | Does |
|---|---|
kb4it create THEME [APP] PATH |
Creates a knowledge base in PATH from a theme and one of its apps (default if you leave it out) |
kb4it create --index yes THEME [APP] PATH |
Also decides whether search engines may index the site: --index yes writes "seo": {"index": true} into repo.json, --index no writes false. Without it nothing is written and the build reminds you; see Search engines |
kb4it create --id ID THEME [APP] PATH |
Also gives the new knowledge base the id ID; see Project ids |
kb4it build CONFIG |
Builds the website of the knowledge base whose settings are in CONFIG |
kb4it build --force CONFIG |
Rebuilds everything |
kb4it build --trace CONFIG |
Builds and shows how long each part of the build took; see Build timings |
kb4it serve CONFIG |
Builds, serves the site at http://127.0.0.1:8642/ and rebuilds it when you save; see its options and Preview while you write |
kb4it verify CONFIG |
Checks every document, the links between documents (LINK_BROKEN, LINK_NO_EXTENSION, ANCHOR_MISSING) and the theme's own rules without building. It also shows INDEX_UNSET while seo.index is not set, as information, and checks the profiles: an error such as PROFILE_INVALID fails it, PROFILE_NO_CONTACT and AUTHOR_NO_PROFILE do not |
kb4it info CONFIG |
Shows the main settings |
kb4it themes |
Lists the installed themes with their version, fingerprint, folder and whether builds use that copy (active=yes or active=no) |
kb4it install-theme SOURCE |
Installs a theme from a zip file or an https:// URL into your themes folder. See Install a theme |
kb4it new-theme ID [--plain] [DIR] |
Creates a theme of your own from a starter theme. See Start a theme |
kb4it theme-info [ID or DIR] [--repo CONFIG] [--json] |
Shows what a theme is made of: features, hooks, options, templates and settings. See Look inside a theme |
kb4it uninstall-theme ID [--yes] |
Removes a theme from your themes folder. See Install a theme |
kb4it doctor |
Shows the KB4IT build and commit, Python, the folders it uses and every theme; ends with 1 when a bundled file or theme is missing. See Check the installation |
kb4it apps THEME |
Lists the sample apps of a theme |
kb4it projects |
Lists the knowledge bases you created or imported, with their ids. Piped, it prints id, name and config separated by tabs, with no header |
kb4it import CONFIG [--id ID] [--name NAME] |
Adds an existing knowledge base to the list; on a listed one, sets its id or name. See Import and delete |
kb4it delete PROJECT [--files] [--yes] |
Removes a knowledge base from the list; --files also deletes its folder. See Import and delete |
kb4it keys PROJECT [KEY [VALUE]] |
Lists the properties of the documents, the values of one, or the documents with one value. See Properties and values |
kb4it search PATTERN [-p PROJECT]... |
Finds text in the Markdown sources and prints path:line: text. See Search the sources |
kb4it help |
Opens the offline copy of this help in your browser; see Help center |
kb4it help --url |
Prints the address of the online help |
kb4it help --dismiss |
Hides the help notice |
kb4it --version |
Prints the KB4IT build, then the commit it was built from and when |
CONFIG is the path of config/repo.json, for example ~/mykb/config/repo.json, or the id of a listed project. PROJECT is the same: an id or a config path.
Project ids
An id is a short name you choose for a knowledge base, so you type kb4it build sapblog instead of the whole path. It has 1 to 32 characters: lowercase letters, digits and dashes, starting with a letter. Each id is used by one project only.
Give an id when you create or import a knowledge base: kb4it create --id sapblog techdoc ~/kb/sap or kb4it import ~/kb/sap/config/repo.json --id sapblog. To give an id to a knowledge base that is already listed, run kb4it import on it again with --id. The terminal interface has an Edit id button on the project screen.
Every command that takes CONFIG (build, serve, info, verify, keys, delete, search -p) also takes an id. KB4IT reads the word this way:
- When a file with that name exists, it is the config file. So
kb4it build config/repo.jsonworks as always. - Otherwise, when a listed project has that id, KB4IT uses its config file.
- Otherwise the command ends with
1and says that there is no such id or file.
Import and delete
kb4it import CONFIG adds a knowledge base you already have, for example one cloned from git. The display name is the title in repo.json, or the folder name; --name sets another one. Running it on a listed knowledge base adds nothing twice: it sets the --id and --name you give, or says it is already listed.
kb4it delete PROJECT removes the knowledge base from the list. Its files stay on disk.
kb4it delete PROJECT --files also deletes the knowledge base folder, the one that holds config/. In a terminal it shows the folder and the number of files, and asks you to type the id (or the folder name, when the project has no id). In a script, add --yes; without a terminal and without --yes it deletes nothing and ends with 1. It refuses, and deletes nothing, when:
- the folder has no
config/holding the project'srepo.json; - the folder is
/, your home folder or~/.kb4it, or contains one of them; - a build or
kb4it serveis using the knowledge base.
When target in repo.json points outside the knowledge base folder, the website there is kept, and the command prints its path.
Install a theme
kb4it install-theme SOURCE installs a theme into ~/.kb4it/opt/resources/themes/. SOURCE is the path of a zip file or an https:// address of one. The zip holds one top folder named exactly as the id in its theme.json; see Pack a theme as a zip.
- KB4IT checks the whole zip before it changes anything. A refused zip leaves your themes as they were; the message says what is wrong.
- When you already have a theme with that id, it is deleted and the new one takes its place. The output names the version it replaced.
- A theme of yours may have the id of a bundled theme. Yours is used in every build, and the output says so.
- Downloads use
https://only, also after a redirect, because a theme runs code at build time. The limit is 100 MB and 60 seconds. - The zip is unpacked in
~/.kb4it/var/tmp/, and the temporary files are removed afterwards.
$ kb4it install-theme ~/Downloads/mytheme.zip
Installed mytheme 1.2.0 in /home/me/.kb4it/opt/resources/themes/mytheme, replacing 1.1.0
kb4it uninstall-theme ID removes a theme from your themes folder. Bundled themes cannot be removed. Before it deletes anything, it lists the projects that use the theme: with a bundled theme of the same id they use it again, otherwise their builds fail until you install the theme again. In a terminal, type the id to confirm; in a script, add --yes. Without a terminal and without --yes it removes nothing and ends with 1.
Start a theme
kb4it new-theme ID copies the starter theme starter-docs into your themes folder as ~/.kb4it/opt/resources/themes/ID/, with ID as its id in theme.json and in the repo.json of its sample app. starter-docs is a document theme on UIkit: property pages, a table of all documents and search. With --plain it copies starter-plain, a theme of plain pages with a home page and search, no property pages. Give a folder after the id to create the theme there instead, as DIR/ID.
$ kb4it new-theme mytheme
Theme mytheme created in /home/me/.kb4it/opt/resources/themes/mytheme
The id takes lower-case letters, digits, - and _. The command ends with 1 and writes nothing when the id is not valid, names a bundled theme, or the folder exists. See Write a theme.
kb4it themes lists every copy. The one builds use has active=yes; a bundled theme hidden by one of yours shows active=no shadowed_by=user. A theme shipped inside a knowledge base's source/resources/themes/ wins over both, and is not listed.
A build that runs while you reinstall the theme it uses may fail; build again.
Look inside a theme
kb4it theme-info ID loads the theme without building a site and prints, one section per line:
theme: id, version, where it was found (builtin,user,pathortheme_path) and its folder.api: the base class. A theme onBuilderorDocumentThemeshowslegacy ... (deprecated).features: what the theme has switched on, in the order they run, such asproperty_pages,events,table_filterorsearch. The theme's own features are marked(theme).hooks: every method the theme overrides, with its file and line and the feature it belongs to.options: the class attributes the theme sets over a KB4IT default.templates: every template the theme can render and where it comes from:repo(the site's overrides),theme,base:NAME(the template base) orcommon.settings: the settings class and its values.
$ kb4it theme-info techdoc
theme techdoc 1.4.0 (builtin) /usr/lib/python3/site-packages/kb4it/resources/themes/techdoc
api BaseTheme, 3 classes in the MRO
features toc, metadata, table, property_pages, all_documents, not_found, events, stats, ...
Give a folder instead of an id to look at a theme you are writing. --repo CONFIG takes the theme of that site (or its theme_path), resolves the site's template overrides and shows the settings merged with its repo.json. --json prints the same as JSON. The command ends with 1 when the theme cannot be found or loaded.
Properties and values
kb4it keys reads the front matter of the documents in source/ directly. It needs no build.
| Command | Prints |
|---|---|
kb4it keys sapblog |
Each property with the number of documents that use it. Title is left out |
kb4it keys sapblog Tag |
Each value of Tag with its number of documents |
kb4it keys sapblog Tag backup |
The path of each document with Tag: backup, one per line |
Property names and values match in any case: kb4it keys sapblog tag BACKUP works. Documents KB4IT cannot read are left out, and one line on standard error gives how many; kb4it verify tells why. An unknown property or value ends with 1.
Search the sources
kb4it search PATTERN finds PATTERN in the Markdown documents of every listed knowledge base, front matter included. Each match prints as path:line: text, with the full path, the way grep -n does:
kb4it search restore # every knowledge base
kb4it search restore -p sapblog -p ops # only these two
kb4it search restore --where Status=Open # only documents with Status: Open
vim -q <(kb4it search restore -p sapblog) # open the matches in vim's quickfix list
| Option | Does |
|---|---|
-p PROJECT, --project PROJECT |
Searches this knowledge base only; repeat it for several. Without -p, every listed one |
--where KEY=VALUE |
Keeps the documents with that property value, in any case. Different keys must all match; the same key repeated matches any of its values: --where Status=Open --where Status=Planned --where Tag=backup means (Open or Planned) and backup |
-r, --regex |
PATTERN is a Python regular expression. Without it, it is plain text |
-s, --case-sensitive |
Matches upper and lower case exactly. Without it, case does not matter |
-l, --files-with-matches |
Prints only the path of each matching document |
In a terminal the path, the line number and the match are colored; piped, or with NO_COLOR set, the output is plain. A listed knowledge base whose repo.json is gone is skipped with a warning.
kb4it search ends like grep: 0 when something matched, 1 when nothing did, 2 on an error such as a wrong regular expression, an unknown -p or an empty project list.
Help center
kb4it help opens the copy of this help that ships inside the installed package. It needs no network. When the package has no copy, the command prints the online address and ends with 1. When no browser starts, it prints the path of the file to open by hand.
kb4it help --url prints the online address and does nothing else.
Until you dismiss it, every command that runs, except kb4it help, prints a two-line notice on standard error. The notice gives the path of the offline copy and the online address. kb4it help --dismiss hides it for good: it writes the file help-notice-dismissed in ~/.kb4it (or in KB4IT_HOME). Delete that file to see the notice again. The terminal interface shows the first line of the notice as a banner, until you press d there or run this command. The notice never shows when the variable CI has a non-empty value.
Options
Put them before the command.
| Option | Does |
|---|---|
-L LEVEL, --log-level LEVEL |
How much to print: DEBUG, INFO (default), WARNING or ERROR. The log file gets every line at any level |
-v, --version |
Prints the version and exits |
-h, --help |
Prints help; kb4it build --help prints help for one command |
-f is short for --force.
Options of serve
Put them after serve, before or after CONFIG.
| Option | Does |
|---|---|
--host ADDRESS |
Address to listen on. Default 127.0.0.1, this computer only; 0.0.0.0 lets other computers see the preview (WARNING_PUBLIC) |
--port PORT |
First port to try. Default 8642; when it is busy, the next free one is used |
--open |
Opens the site in your browser |
--no-watch |
Serves only; does not rebuild when a file changes |
--no-reload |
Rebuilds, but does not reload pages in the browser |
--interval SECONDS |
Seconds between checks for changes. Default 1.0 |
-f, --force |
Rebuilds everything in the first build |
--trace |
Writes var/log/trace.json with the timings of each build; see Build timings |
Shell completion
KB4IT completes commands, options, the installed themes, the apps of a theme and file paths with Tab. It uses argcomplete, which is installed with KB4IT. Register the command once per shell:
# bash
eval "$(register-python-argcomplete kb4it)"
# zsh, after compinit
eval "$(register-python-argcomplete kb4it)"
# fish
register-python-argcomplete --shell fish kb4it | source
Put the line in ~/.bashrc, ~/.zshrc or ~/.config/fish/config.fish to keep it. activate-global-python-argcomplete enables completion for kb4it and every other argcomplete-aware command at once.
The CONFIG and PROJECT arguments complete the project ids and file paths; search -p completes the ids only. kb4it keys sapblog <Tab> lists the properties and, after one, its values; kb4it search x --where <Tab> completes KEY= and then KEY=VALUE.
kb4it create <Tab> and kb4it apps <Tab> list the installed themes, and kb4it uninstall-theme <Tab> only yours; after a theme, the next word lists its sample apps and folders. Once the app is typed, only folders are offered for the path. The config argument of build, serve, info and verify completes file paths, so config/repo.json is a few keystrokes away. Completion reads the theme folders directly, so a theme installed under ~/.kb4it/opt/resources/themes/ appears without regenerating anything.
Without argcomplete the command line works as before; only Tab completion is missing.
Build timings
kb4it build --trace CONFIG (also kb4it serve --trace CONFIG) times each stage and step of the build and the compilation of each document. It works with any -L level and adds nothing to the log.
At the end of the build it prints a table: time in milliseconds, share of the build, and the step, indented under its stage. Steps under 1% are left out. Documents compiled in parallel are summed in one line.
It also writes <knowledge base>/var/log/trace.json, replaced at each build. Open it in https://ui.perfetto.dev or chrome://tracing to see the build as a timeline, with one row per worker thread.
Exit status
| Status | Meaning |
|---|---|
0 |
Done |
1 |
Something failed (see below) |
kb4it build ends with 1 when:
- the settings are missing or broken, or the theme cannot load;
- a page could not be made: its Markdown, its template or a hook failed. The other pages are still published, the log lists the failed ones after
PAGES_FAILED, and the summary showsfailed=; - documents cannot be read and
"fail_on_invalid": trueis set (without it, they are only reported asinvalid=); - another KB4IT is already building the same knowledge base.
After a failed build the next build compiles again every document that changed since the last successful one, so there is no need for --force.
kb4it verify ends with 1 when it finds a problem in a document, a theme or a link.
kb4it search uses its own statuses, like grep; see Search the sources.
Files KB4IT keeps
| Path | Holds |
|---|---|
~/.kb4it/projects.json |
The list behind kb4it projects and the terminal interface |
~/.kb4it/opt/resources/themes/ |
Your own themes |
~/.kb4it/var/projects.lock |
Held for a moment while projects.json is written |
~/.kb4it/var/themes.lock |
Held while a theme is installed or removed |
~/.kb4it/var/tmp/ |
Downloads and unpacked zips of kb4it install-theme, removed when it ends |
~/.kb4it/help-notice-dismissed |
Written by kb4it help --dismiss; hides the help notice |
<knowledge base>/var/ |
Build cache and logs; safe to delete |
<knowledge base>/var/kb4it.lock |
Stops two builds of the same knowledge base at once |
~ is your home folder: /home/<you> on Linux, /Users/<you> on macOS, C:\Users\<you> on Windows.
Environment variables
| Variable | Effect |
|---|---|
KB4IT_HOME |
Folder for the files above instead of ~/.kb4it. Useful for a portable install or to keep test runs apart |
KB4IT_HELP_INDEX |
Path of the index.html that kb4it help opens, instead of the copy in the package |
CI |
Any non-empty value hides the help notice |