Skip to content

Commit 7c8cda6

Browse files
committed
1.2.0
- Add `eleventyPlugin` method - Add `outputFolder` and `templatesFolder` options - Add various CLI options - Add wikitext tables
1 parent 564be68 commit 7c8cda6

20 files changed

+180
-112
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules/
33
wikity-out/
44

55
src/*.js
6+
src/*.d.ts

.npmignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

changelog.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
# Changelog
22

3+
## 1.2.0
4+
*2021-04-01*
5+
- Added function `eleventyPlugin()` for use with Eleventy's `addPlugin` method.
6+
- Added configuration option `outputFolder` to configure the folder the compiled HTML files are placed in.
7+
- Added configuration option `templatesFolder` to configure the folder templates are placed in.
8+
- Added CLI options `--outputFolder`, `--templatesFolder`, `--eleventy`, and `--defaultStyles` to change configuration options.
9+
- Added support for tables.
10+
- Added a warning when the parser detects non-repetition-based `#time` function syntax is being used.
11+
312
## 1.1.0
413
*2021-03-28*
514
- Added `parse` CLI command to implement `parse()`.
6-
- Added support for a table of contents.
15+
- Added a generated table of contents if there are over 4 headings.
716
- Added support for `nowiki` tag.
817
- Added support for `onlyinclude`, `includeonly`, and `noinclude` tags in templates.
918
- Added support for magic words `__TOC__`, `__FORCETOC__`, `__NOTOC__`, and `__NOINDEX__`.

package-lock.json

Lines changed: 4 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wikity",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "Wikitext as a templating language, with built-in Eleventy support.",
55
"main": "src/index.js",
66
"scripts": {
@@ -9,6 +9,10 @@
99
"bin": {
1010
"wikity": "src/cli.js"
1111
},
12+
"files": [
13+
"src/*.js",
14+
"src/*.d.ts"
15+
],
1216
"keywords": [
1317
"eleventy",
1418
"eleventy-plugin",
@@ -18,20 +22,27 @@
1822
"template-language",
1923
"templating-language"
2024
],
25+
"repository": {
26+
"type": "git",
27+
"url": "git+https://github.com/Nixinova/Wikity.git"
28+
},
2129
"author": "Nixinova (https://nixinova.com)",
30+
"bugs": {
31+
"url": "https://github.com/Nixinova/Wikity/issues"
32+
},
33+
"homepage": "https://github.com/Nixinova/Wikity#readme",
2234
"license": "ISC",
2335
"dependencies": {
2436
"dateformat": "^4.5.1",
2537
"escape-html": "^1.0.3",
2638
"glob": "^7.1.6",
27-
"html-formatter": "^0.1.9",
28-
"novasheets": "1.0.0-pre3"
39+
"html-formatter": "^0.1.9"
2940
},
3041
"peerDependencies": {
3142
"@11ty/eleventy": ">=0.10.0"
3243
},
3344
"devDependencies": {
3445
"@types/node": "^14.14.37",
35-
"typescript": "^4.2.3"
46+
"typescript": "~4.2.3"
3647
}
3748
}

readme.md

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,65 @@ Wikity is available [on npm](https://www.npmjs.com/package/wikity).
1212

1313
## API
1414

15-
- `wikity.compile(directory?: string, options?: object)`
16-
- Compile Wikitext files into HTML. Find outputted files in folder `wikity-out/`.
15+
### Node
16+
17+
- `wikity.compile(folder?: string, options?: object): void`
18+
- Compile all Wikitext (`.wiki`) files into HTML.
1719
- `directory?: string`
1820
- The folder to compile (default: `.`, the current directory).
1921
- `options?: object`
22+
- `outputFolder?: string`
23+
- Where outputted HTML files shall be placed (default: `wikity-out`).
24+
- `templatesFolder?: string`
25+
- What folder to place templates in (default: `'templates'`).
2026
- `eleventy?: boolean`
2127
- Whether [front matter](https://www.11ty.dev/docs/data-frontmatter/) will be added to the outputted HTML for Eleventy to read (default: `false`).
2228
- `defaultStyles?: boolean`
2329
- Whether to use default wiki styling (default: `true`).
2430
- `customStyles?: string`
2531
- Custom CSS to style the wiki pages (default: `''`).
26-
- `wikity.clean()`
27-
- Clean up residual folders after compilation.
28-
29-
Calling `wikity()` will compile all `.wiki` files into their corresponding `.html` versions.
30-
Outputted files are located in the `wikity-out/` directory.
32+
- `wikity.eleventyPlugin(folder?: string, options?: object): void`
33+
- An implementation of `compile` for use with Eleventy's `addPlugin` API.
34+
- `wikity.parse(input: string): string`
35+
- Parse raw wikitext input into HTML.
3136

3237
```js
3338
const wikity = require('wikity');
34-
wikity.compile(); // compile all .wiki files inside this directory
39+
40+
// compile all .wiki files inside this directory
41+
wikity.compile();
42+
43+
// parse wikitext from an input string
44+
let html = wikity.parse(`'''bold''' [[link|text]]`); // <b>bold</b> <a href="/link"...>text</a>
3545
```
3646

3747
Use Wikity along with Eleventy to compile your wiki files during the build process:
3848

3949
```js
4050
// .eleventy.js (eleventy's configuration file)
4151
const wikity = require('wikity');
42-
wikity.compile('.', { eleventy: true });
52+
module.exports = function (eleventyConfig) {
53+
eleventyConfig.addPlugin( () => wikity.eleventyPlugin() );
54+
}
55+
```
56+
57+
### Command-line
58+
```cmd
59+
$ wikity help
60+
Display a help message
61+
$ wikity (compile|-c) [<folder>] [-o <folder>] [-t <folder>] [-e] [-d]
62+
Compile Wikity with various options
63+
$ wikity parse <input>
64+
Parse raw input into HTML
65+
$ wikity version
66+
Display the latest version of Wikity
4367
```
4468

4569
## Usage
4670

4771
Use [Wikitext](https://en.wikipedia.org/wiki/Help:Wikitext) (file extension `.wiki`) to create your pages.
4872

49-
Any wiki templates (called using `{{template name}}`) must be inside the `templates/` folder.
73+
Any wiki templates (called using `{{template name}}`) must be inside the `templates/` folder by default.
5074

5175
### Wiki markup
5276

@@ -75,24 +99,29 @@ Any wiki templates (called using `{{template name}}`) must be inside the `templa
7599
| `{{tp name\|arg=val}}` | *(ditto but `{{{arg}}}` is set to 'val')* |
76100
| `{{{arg}}}` | *(value given by template)* |
77101
| `{{{arg\|default val}}}` | *(ditto but 'default val' if unset)* |
102+
| `{\| style="margin:1em"` | *table opening* |
103+
| `! Cell heading` | **Cell heading** |
104+
| `\|- class="new-row"` | *new table row* |
105+
| `\| Cell content` | Cell content |
106+
| `\|}` | *table closing* |
78107
| `{{#if:non-empty-string\|text}}` | text |
79108
| `{{#ifeq:1\|2\|true\|false}}` | false |
80109
| `{{#vardefine:varname\|text}}` | *(saved to memory)* |
81110
| `{{#var:varname}}` | text *(from memory)* |
82111
| `{{#var:varname\|default val}}` | *(ditto but 'default val' if unset)* |
83112
| `{{#switch:a\|a=1\|b=2\|c=3}}` | 1 |
84113
| `{{#time:dd/mm/yy\|2021-03-28}}` | 28/03/21 |
85-
| `{{lc:TEXT}}` | text |
86-
| `{{ucfirst:text}}` | Text |
87-
| `{{len:12345}}` | 5 |
88-
| `{{sub:string|2|4}}` | ring |
89-
| `{{pos:text|x}}` | 2 |
90-
| `{{padleft:text|5|_}}` | _text |
91-
| `{{padright:msg|5|_}}` | msg__ |
92-
| `{{replace:Message|e|3}}` | M3ssag3 |
93-
| `{{explode:A-B-C-D|-|2}}` | C |
94-
| `{{urlencode:t e x t}}` | t%20e%20x%20t |
95-
| `{{urldecode:a%20b%27c}}` | a b'c |
114+
| `{{#lc:TEXT}}` | text |
115+
| `{{#ucfirst:text}}` | Text |
116+
| `{{#len:12345}}` | 5 |
117+
| `{{#sub:string\|2\|4}}` | ring |
118+
| `{{#pos:text\|x}}` | 2 |
119+
| `{{#padleft:text\|5\|_}}` | _text |
120+
| `{{#padright:msg\|5\|_}}` | msg__ |
121+
| `{{#replace:Message\|e\|3}}` | M3ssag3 |
122+
| `{{#explode:A-B-C-D\|-\|2}}` | C |
123+
| `{{#urlencode:t e x t}}` | t%20e%20x%20t |
124+
| `{{#urldecode:a%20b%27c}}` | a b'c |
96125
| `<noinclude>No</noinclude>` | *(blank outside a template)* |
97126
| `<onlyinclude>Yes</onlyinclude>` | Yes |
98127
| `<includeonly>Yes</includeonly>` | Yes *(blank inside a template)* |

src/clean.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import fs from 'fs';
2+
3+
const OUT_FOLDER = 'wikity-out/';
4+
5+
export function clean(): void {
6+
fs.rmdirSync('_site/' + OUT_FOLDER, { recursive: true });
7+
}

src/cli.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,51 @@
22

33
import wikity from './index';
44

5-
const VERSION = '1.1.0';
5+
const VERSION = '1.2.0';
66

77
const indent = (n: number): string => ' '.repeat(n * 4);
88
const usage = (command: string, ...desc: string[]): void => {
99
console.log('\n' + indent(2) + command);
10-
for (let msg of desc) console.log(indent(3) + msg);
10+
desc.forEach((msg: string) => console.log(indent(2.5) + msg));
1111
}
1212
const arg = (n: number): string => process.argv[n + 1] || '';
13-
13+
const args = process.argv.slice(1);
1414

1515
if (!arg(1)) {
1616
console.log('Type `wikity help` for a list of commands.');
1717
}
1818
else if (arg(1).includes('h')) {
1919
console.log(`\n${indent(1)}Wikity CLI commands:`);
20-
usage(`wikity [--]h[elp]`,
20+
usage(`wikity (help|-h)`,
2121
`Display this help message.`,
2222
);
23-
usage(`wikity [--]c[ompile] [<folder>]`,
23+
usage(`wikity (compile|-c) [<folder>] [-o <folder>] [-t <folder>] [-e] [-d]`,
2424
`Compile wikitext files from a given folder.`,
25+
` [<folder>]\n${indent(3.5)}Input folder ('.' (current folder) if unset).`,
26+
` (-o|--outputFolder) <folder>\n${indent(3.5)}Folder that compiled HTML files are placed in ('wikity-out' if unset).`,
27+
` (-t|--templatesFolder) <folder>\n${indent(3.5)}Where to place wiki templates ('templates' if unset).`,
28+
` (-e|--eleventy)\n${indent(3.5)}Compiles files with Eleventy front matter (false if unset).`,
29+
` (-d|--defaultStyles)\n${indent(3.5)}Add default wiki styling to all pages (true if unset).`,
2530
)
26-
usage(`wikity [--]p[arse] "<input>"`,
31+
usage(`wikity (parse|-p) "<input>"`,
2732
`Parse raw wikitext from the command line.`,
2833
)
29-
usage(`wikity [--]v[ersion]`,
34+
usage(`wikity (version|-v)`,
3035
`Display the current version of Wikity.`,
3136
);
3237
}
3338
else if (arg(1).includes('c')) {
34-
wikity.compile(arg(2) || '.', { eleventy: !!arg(3) });
39+
const configArgs = args.slice(2);
40+
const folder = arg(2) || '.';
41+
const outputFolder = configArgs.join(' ').includes('-o') && configArgs.filter((_, i) => configArgs[i - 1]?.includes('-o')).join(' ') || '';
42+
const templatesFolder = configArgs.join(' ').includes('-t') && configArgs.filter((_, i) => configArgs[i - 1]?.includes('-t')).join(' ') || '';
43+
const eleventy = configArgs.join(' ').includes('-e');
44+
const defaultStyles = configArgs.join(' ').includes('-d');
45+
wikity.compile(folder, { outputFolder, templatesFolder, eleventy, defaultStyles });
3546
}
3647
else if (arg(1).includes('p')) {
37-
console.log(wikity.parse(arg(2)));
48+
const input = arg(2);
49+
console.log(wikity.parse(input));
3850
}
3951
else if (arg(1).includes('v')) {
4052
console.log('The current version of Wikity is ' + VERSION);

src/types.ts renamed to src/common.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
export type Metadata = Record<string, any>;
22

33
export type Config = {
4+
outputFolder?: string,
45
eleventy?: boolean,
56
defaultStyles?: boolean,
67
customStyles?: string,
8+
templatesFolder?: string,
79
}
810

911
export class Result extends String {
@@ -13,3 +15,9 @@ export class Result extends String {
1315
this.metadata = {};
1416
}
1517
}
18+
19+
export function RegExpBuilder(regex: string, flag: string = 'mgi') {
20+
return RegExp(regex.replace(/ /g, '').replace(/\|\|.+?\|\|/g, ''), flag);
21+
}
22+
23+
export const RawString = String.raw;

src/compile.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)