Wikity
Wikity is a tool that allows you to use Wikitext (used by Wikipedia, Fandom, etc) as a templating language to create HTML pages, useful in build tools such as Eleventy.
Install
Wikity is available on npm.
Local install | Global install |
---|
npm install wikity | npm install -g wikity |
API
wikity.compile(directory?: string, options?: object)
- Compile Wikitext files into HTML. Find outputted files in folder
wikity-out/
. directory?: string
- The folder to compile (default:
.
, the current directory).
options?: object
eleventy?: boolean
- Whether front matter will be added to the outputted HTML for Eleventy to read (default:
false
).
defaultStyles?: boolean
- Whether to use default wiki styling (default:
true
).
customStyles?: string
- Custom CSS to style the wiki pages (default:
''
).
wikity.clean()
- Clean up residual folders after compilation.
Calling wikity()
will compile all .wiki
files into their corresponding .html
versions.
Outputted files are located in the wikity-out/
directory.
const wikity = require('wikity');
wikity.compile();
Use Wikity along with Eleventy to compile your wiki files during the build process:
const wikity = require('wikity');
wikity.compile('.', { eleventy: true });
Usage
Use Wikitext (file extension .wiki
) to create your pages.
Any wiki templates (called using {{template name}}
) must be inside the templates/
folder.
Wiki markup
Markup | Preview |
---|
'''bold''' | bold |
''italic'' | italic |
'''''bold italic''''' | bold italic |
``code`` | code |
```code block``` | code block |
=heading= | heading |
==subheading== | subheading |
*bulleted | |
**sub-bulleted | |
#numbered | - numbered
|
##sub-numbered | - sub-numbered
|
;term | term |
:definition | definition |
<ref>Text</ref> | [1] |
<references/> | 1. ↑ Text |
[[internal link]] | internal link |
[[link|display text]] | display text |
[external-link] | [1] |
[external-link display text] | display text |
{{tp name}} | (contents of templates/tp_name.wiki ) |
{{tp name|arg=val}} | (ditto but {{{arg}}} is set to 'val') |
{{{arg}}} | (value given by template) |
{{{arg|default val}}} | (ditto but 'default val' if unset) |
{{#if:non-empty-string|text}} | text |
{{#ifeq:1|2|true|false}} | false |
{{#vardefine:varname|text}} | (saved to memory) |
{{#var:varname}} | text (from memory) |
{{#var:varname|default val}} | (ditto but 'default val' if unset) |
{{#switch:a|a=1|b=2|c=3}} | 1 |
{{#time:dd/mm/yy|2021-03-28}} | 28/03/21 |
{{lc:TEXT}} | text |
{{ucfirst:text}} | Text |
{{len:12345}} | 5 |
`{{sub:string | 2 |
`{{pos:text | x}}` |
`{{padleft:text | 5 |
`{{padright:msg | 5 |
`{{replace:Message | e |
`{{explode:A-B-C-D | - |
{{urlencode:t e x t}} | t%20e%20x%20t |
{{urldecode:a%20b%27c}} | a b'c |
<noinclude>No</noinclude> | (blank outside a template) |
<onlyinclude>Yes</onlyinclude> | Yes |
<includeonly>Yes</includeonly> | Yes (blank inside a template) |
<nowiki>[[no link]]</nowiki> | [[no link]] |