Compare commits

...

7 Commits

Author SHA1 Message Date
Klemek 97dab302d8 Merge pull request #7 from Klemek/dev
v1.1.2
2019-06-23 14:19:24 +02:00
Klemek 55e258e093 Fixed Express.static mime type 2019-06-23 14:14:35 +02:00
Klemek 7b22a4773d Merge pull request #6 from Klemek/dev
v1.1.1
2019-06-23 13:58:34 +02:00
Klemek 14cd1436c3 Better without infinite loop 2019-06-23 13:56:31 +02:00
Klemek c112e1ea62 Merge pull request #5 from Klemek/dev
v1.1
2019-06-23 13:52:24 +02:00
Klemek bd8385ea60 [skip CI] updated version 2019-06-23 13:51:07 +02:00
Klemek 6dbc7f359b PlantUML integration 2019-06-23 13:48:28 +02:00
14 changed files with 1885 additions and 25 deletions
+2
View File
@@ -0,0 +1,2 @@
/node_modules
/src/lib
-5
View File
@@ -6,13 +6,8 @@ cache:
npm: true
directories:
- node_modules
addons:
apt:
packages:
- graphviz
install:
- npm install
- npm install node-plantuml
before_script:
- npm install -g jshint
script:
+6 -2
View File
@@ -81,7 +81,7 @@ On the `/rss` endpoint, the servers gives you a RSS feed based on the list of ar
#### 1. Download and install the latest version from the repo
```bash
git clone https://github.com/klemek/gitblog.md.git
npm install
npm install --production
```
#### 2. Create your config file
```bash
@@ -203,7 +203,9 @@ Any URL like `/year/month/day/anything/` will redirect to this article (and link
* **Prism**
It highlight code blocks to be more readable (more info [here](https://prismjs.com/), you will need the corresponding CSS file on your templates)
* **MathJax**
It allows you to add math equations to your articles by simply writing LaTeX between $$ for full size (and between $ for inline) (more info [here](https://www.mathjax.org/))
It allows you to add math equations to your articles by simply writing LaTeX between `$$` for full size (and between $ for inline) (more info [here](https://www.mathjax.org/))
* **PlantUML**
It allows you to add UML diagrams with PlantUML Syntax between `@startuml` and `@enduml` (more info [here](http://www.plantuml.com))
## Configuration
[back to top](#gitblog-md)
@@ -227,6 +229,8 @@ Any URL like `/year/month/day/anything/` will redirect to this article (and link
activate Prism code highlighting
* `mathjax` (default: true)
activate MathJax equations formatting
* `plantuml` (default: true)
activate PlantUML diagram rendering
* `home`
* `index` (default: index.ejs)
the name of the home page template on the data directory
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "gitblog.md",
"version": "1.0.2",
"version": "1.0.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
+3 -2
View File
@@ -1,6 +1,6 @@
{
"name": "gitblog.md",
"version": "1.0.3",
"version": "1.1.2",
"description": "A static blog using Markdown pulled from your git repository.",
"main": "src/server.js",
"dependencies": {
@@ -43,7 +43,8 @@
"src/**/*.js",
"!/node_modules/",
"!src/server.js",
"!src/postinstall.js"
"!src/postinstall.js",
"!src/lib/*.js"
]
}
}
+28
View File
@@ -18,6 +18,7 @@ If you see this page, that means it's working
* [Check Boxes](#checkboxes)
* [Spoilers](#spoilers)
* [Math Equations](#mathequations)
* [UML](#uml)
* [Youtube Videos](#youtubevideos)
### Headers
@@ -224,6 +225,33 @@ $$
Where $\alpha$ is cool
### UML
[Back to top](#top)
You can use PlantUML diagrams with `@startuml` and `@enduml` tags :
@startuml
title Article
cloud web
node nodejs {
TCP -right- [express]
[showdown]
}
package data {
package "2019/06/18" {
component index [
index.md
image.png
...
]
}
}
web -down-> TCP : 1. /2019/06/18/title
express -down-> index : 2. fetch
index -up-> showdown : 3. markdown
showdown -left-> express : 4. html
express -up-> web : 5. html
@enduml
### Youtube Videos
[Back to top](#top)
+1 -1
View File
@@ -225,7 +225,7 @@ module.exports = (config) => {
});
// serve all static files via get
app.get('*', express.static(config['data_dir']));
app.get('*', express.static(path.join(__dirname, '..', config['data_dir'])));
// catch express.static errors (mostly not found) by displaying 404
app.get('*', (req, res) => {
showError(req.path, 404, res);
+5 -1
View File
@@ -8,7 +8,8 @@
"rss": true,
"webhook": true,
"prism": true,
"mathjax": true
"mathjax": true,
"plantuml": true
},
"home": {
"index": "index.ejs",
@@ -47,5 +48,8 @@
"mathjax": {
"output_format": "svg",
"speak_text": true
},
"plantuml": {
"output_format": "svg"
}
}
File diff suppressed because it is too large Load Diff
+29 -10
View File
@@ -1,4 +1,5 @@
const fs = require('fs');
const path = require('path');
const showdown = require('showdown');
module.exports = (config) => {
@@ -21,12 +22,27 @@ module.exports = (config) => {
while ((match = codeRegex.exec(data))) {
const lang = match[1].trim();
const code = match[2].trim();
try {
const block = Prism.highlight(code, Prism.languages[lang] || Prism.languages.autoit, lang);
data = data.slice(0, match.index) + `<pre><code class="${lang} language-${lang}">` + block + '</code></pre>' + data.slice(match.index + match[0].length);
} catch (err) {
console.error(err);
}
const block = Prism.highlight(code, Prism.languages[lang] || Prism.languages.autoit, lang);
data = data.slice(0, match.index) + `<pre><code class="${lang} language-${lang}">` + block + '</code></pre>' + data.slice(match.index + match[0].length);
}
cb(data);
};
if (config['modules']['plantuml']) {
require('./script_loader')(path.join(__dirname, 'lib', 'plantuml_synchro.js'));
}
const renderPlantUML = (data, cb) => {
if (!config['modules']['plantuml'])
return cb(data);
const umlRegex = /@startuml\r?\n((?:(?!@enduml)[\s\S])*)\r?\n@enduml/m;
let match;
while ((match = umlRegex.exec(data))) {
const code = match[1].trim();
const s = unescape(encodeURIComponent(code)); // jshint ignore:line
const compressed = global['zip_deflate'](s);
const url = `http://www.plantuml.com/plantuml/${config['plantuml']['output_format']}/${encode64(compressed)}`;// jshint ignore:line
data = data.slice(0, match.index) + `<img alt="generated PlantUML diagram" src="${url}">` + data.slice(match.index + match[0].length);
}
cb(data);
};
@@ -81,16 +97,19 @@ module.exports = (config) => {
return {
renderShowDown: config['test'] ? renderShowDown : undefined,
renderPrism: config['test'] ? renderPrism : undefined,
renderPlantUML: config['test'] ? renderPlantUML : undefined,
renderMathJax: config['test'] ? renderMathJax : undefined,
render: (file, cb) => {
fs.readFile(file, {encoding: 'UTF-8'}, (err, data) => {
if (err)
return cb(err);
renderPrism(data, (data2) => {
renderMathJax(data2, (data3) => {
renderShowDown(data3, (html) => {
cb(null, html);
renderPrism(data, (data) => {
renderPlantUML(data, (data) => {
renderMathJax(data, (data) => {
renderShowDown(data, (html) => {
cb(null, html);
});
});
});
});
+10
View File
@@ -0,0 +1,10 @@
const fs = require('fs');
/**
* Import client-side script into the "global" var
* @param scriptPath
*/
module.exports = (scriptPath) => {
eval.call(global, fs.readFileSync(scriptPath, {encoding: 'UTF-8'}));
};
+3 -2
View File
@@ -385,9 +385,10 @@ describe('Test static files', () => {
});
});
test('200 valid file', (done) => {
fs.writeFileSync(path.join(dataDir, 'somefile.txt'), 'filecontent');
request(app).get('/somefile.txt').then((response) => {
fs.writeFileSync(path.join(dataDir, 'somefile.css'), 'filecontent');
request(app).get('/somefile.css').then((response) => {
expect(response.statusCode).toBe(200);
expect(response.type).toBe('text/css');
expect(response.text).toBe('filecontent');
done();
});
+31 -1
View File
@@ -10,7 +10,8 @@ const config = {
'test': true,
'modules': {
'prism': true,
'mathjax': true
'mathjax': true,
'plantuml': true
},
'showdown': {
'simplifiedAutoLink': true,
@@ -19,6 +20,9 @@ const config = {
'mathjax': {
'output_format': 'html',
'speak_text': false
},
'plantuml': {
'output_format': 'svg'
}
};
@@ -27,6 +31,7 @@ const renderer = require('../src/renderer')(config);
beforeEach(() => {
config['modules']['prism'] = true;
config['modules']['mathjax'] = true;
config['modules']['plantuml'] = true;
utils.deleteFolderSync(dataDir);
fs.mkdirSync(dataDir);
});
@@ -91,6 +96,31 @@ describe('Test Prism', () => {
});
});
describe('Test PlantUML', () => {
test('no plantuml', (done) => {
config['modules']['plantuml'] = false;
renderer.renderPlantUML('@startuml\nBob -> Alice : hello\n@enduml', (data) => {
expect(data).toBe('@startuml\nBob -> Alice : hello\n@enduml');
done();
});
});
test('plantuml correct', (done) => {
renderer.renderPlantUML('@startuml\nBob -> Alice : hello\n@enduml', (data) => {
expect(data).toBe('<img alt="generated PlantUML diagram" src="http://www.plantuml.com/plantuml/svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000">');
done();
});
});
test('plantuml multiple uml', (done) => {
renderer.renderPlantUML('@startuml\nBob -> Alice : hello\n@enduml\n@startuml\nBob -> Alice : hello\n@enduml', (data) => {
expect(data).toBe('<img alt="generated PlantUML diagram" src="http://www.plantuml.com/plantuml/svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000">\n<img alt="generated PlantUML diagram" src="http://www.plantuml.com/plantuml/svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000">');
done();
});
});
});
describe('Test MathJax', () => {
test('no mathjax', (done) => {
config['modules']['mathjax'] = false;
+51
View File
@@ -0,0 +1,51 @@
/* jshint -W117 */
const fs = require('fs');
const path = require('path');
const utils = require('./test_utils');
const dataDir = 'test_data';
beforeEach(() => {
utils.deleteFolderSync(dataDir);
fs.mkdirSync(dataDir);
});
afterAll(() => {
if (fs.existsSync(dataDir)) {
utils.deleteFolderSync(dataDir);
}
});
test('load 1 script', () => {
const file = path.join(dataDir, 'test.js');
fs.writeFileSync(file, `
var a = 5;
function b(){
return a;
}`);
require('../src/script_loader')(file);
expect(global['b']).toBeDefined();
expect(global['b']()).toBe(5);
});
test('load 2 script', () => {
const file1 = path.join(dataDir, 'test.js');
fs.writeFileSync(file1, `
var a = 5;
function b(){
return a;
}`);
const file2 = path.join(dataDir, 'test2.js');
fs.writeFileSync(file2, `
var a = 9;
function b(){
return a;
}`);
require('../src/script_loader')(file1);
expect(global['b']).toBeDefined();
expect(global['b']()).toBe(5);
require('../src/script_loader.js')(file2);
expect(global['b']).toBeDefined();
expect(global['b']()).toBe(9);
});