Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 32f9ea74f1 | |||
| 9d1fb69fee | |||
| 24a02d862f | |||
| cfe9965d03 | |||
| d260b9d2f8 | |||
| 9ec55b3c01 | |||
| c693d96339 | |||
| 8bb6b6db66 | |||
| 849cdf2a19 | |||
| d0d3f94049 | |||
| 613e663c13 | |||
| bd10871da9 | |||
| 671a4314d7 | |||
| 1cee7094f3 | |||
| 2284d46bb5 | |||
| 7245876b07 | |||
| 7a35aec7ad | |||
| 870701b6c6 | |||
| 3be86dec58 | |||
| 48d9535007 | |||
| ae2eb52cf8 | |||
| 7e9e1e19fa | |||
| c9ef93088b | |||
| 99e4bb5c4d | |||
| dd5af2b865 | |||
| 4671253147 | |||
| add01b28fe | |||
| a27a53e238 | |||
| 6aff9b4d93 | |||
| c9f57233a4 | |||
| 90c343c752 | |||
| ff7542af70 |
@@ -1,5 +1,7 @@
|
||||
[](https://travis-ci.org/Klemek/GitBlog.md)
|
||||
[](https://coveralls.io/github/Klemek/GitBlog.md?branch=master)
|
||||
[](https://lgtm.com/projects/g/Klemek/GitBlog.md/context:javascript)
|
||||
[](https://lgtm.com/projects/g/Klemek/GitBlog.md/alerts/)
|
||||
|
||||
# GitBlog.md
|
||||
|
||||
@@ -245,7 +247,7 @@ Any URL like `/year/month/day/anything/` will redirect to this article (and link
|
||||
* **PlantUML**
|
||||
It allows you to add UML diagrams with PlantUML Syntax between `@startuml` and `@enduml` (more info [here](http://www.plantuml.com))
|
||||
* **fa-diagrams**
|
||||
It allows you to define SVG diagrams with Font-Awesome icons in YAML between `@startfad` and `@endfad` (more info [here](https://github.com/Klemek/fa-diagrams))
|
||||
It allows you to define SVG diagrams with Font-Awesome icons in [TOML](https://github.com/toml-lang/toml) between `@startfad` and `@endfad` (more info [here](https://github.com/Klemek/fa-diagrams))
|
||||
|
||||
|
||||
## Configuration
|
||||
@@ -260,6 +262,8 @@ Any URL like `/year/month/day/anything/` will redirect to this article (and link
|
||||
the directory where will be located the git repo with templates and articles
|
||||
* `view_engine` (default: ejs)
|
||||
the Express view engine used to render pages from templates
|
||||
* `rate_limit` (default: 100)
|
||||
number of requests allowed in a time-frame of 15 minutes
|
||||
* `access_log` (default: access.log)
|
||||
log file where to save access requests (empty to disable)
|
||||
* `error_log` (default: error.log)
|
||||
|
||||
Generated
+1268
-5143
File diff suppressed because it is too large
Load Diff
+3
-5
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "gitblog.md",
|
||||
"version": "1.2.6",
|
||||
"version": "1.2.8",
|
||||
"description": "A static blog using Markdown pulled from your git repository.",
|
||||
"main": "src/server.js",
|
||||
"dependencies": {
|
||||
"@iarna/toml": "^2.2.3",
|
||||
"body-parser": "^1.19.0",
|
||||
"crypto": "^1.0.1",
|
||||
"ejs": "^2.6.2",
|
||||
"express": "^4.17.1",
|
||||
"express-rate-limit": "^5.0.0",
|
||||
"fa-diagrams": "^1.0.3",
|
||||
"js-yaml": "^3.13.1",
|
||||
"mathjax-node": "^2.1.1",
|
||||
"ncp": "^2.0.0",
|
||||
"node-prismjs": "^0.1.2",
|
||||
@@ -18,8 +18,6 @@
|
||||
"showdown": "^1.9.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"coveralls": "^3.0.4",
|
||||
"jest": "^24.8.0",
|
||||
"superagent": "^5.1.0",
|
||||
|
||||
@@ -257,26 +257,30 @@ express -up-> web : 5. html
|
||||
### Diagrams
|
||||
[Back to top](#top)
|
||||
|
||||
You can use [fa-diagrams](https://github.com/Klemek/fa-diagrams) with `@startfad` and `@endfad` tags and using YAML inside
|
||||
You can use [fa-diagrams](https://github.com/Klemek/fa-diagrams) with `@startfad` and `@endfad` tags and using [TOML](https://github.com/toml-lang/toml) inside
|
||||
|
||||
@startuml
|
||||
nodes:
|
||||
- name: node1
|
||||
icon: laptop-code
|
||||
color: '#4E342E'
|
||||
bottom: my app
|
||||
- name: node2
|
||||
icon: globe
|
||||
color: '#455A64'
|
||||
bottom: world
|
||||
links:
|
||||
- from: node1
|
||||
to: node2
|
||||
color: '#333333'
|
||||
top:
|
||||
icon: envelope
|
||||
bottom: '"hello"'
|
||||
@enduml
|
||||
@startfad
|
||||
[[nodes]]
|
||||
name = "node1"
|
||||
icon = "laptop-code"
|
||||
color = "#4E342E"
|
||||
bottom = "my app"
|
||||
|
||||
[[nodes]]
|
||||
name = "node2"
|
||||
icon = "globe"
|
||||
color = "#455A64"
|
||||
bottom = "world"
|
||||
|
||||
[[links]]
|
||||
from = "node1"
|
||||
to = "node2"
|
||||
color = "#333333"
|
||||
bottom = '"hello"'
|
||||
|
||||
[links.top]
|
||||
icon = "envelope"
|
||||
@endfad
|
||||
|
||||
### Youtube Videos
|
||||
[Back to top](#top)
|
||||
|
||||
@@ -3,6 +3,7 @@ const app = express();
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const pjson = require('../package.json');
|
||||
const rateLimit = require('express-rate-limit');
|
||||
|
||||
app.enable('trust proxy');
|
||||
|
||||
@@ -122,6 +123,13 @@ module.exports = (config) => {
|
||||
next();
|
||||
});
|
||||
|
||||
//rate limit for safer server
|
||||
const limiter = rateLimit({
|
||||
windowMs: 15 * 60 * 1000, // 15 minutes
|
||||
max: config['rate_limit']
|
||||
});
|
||||
app.use(limiter);
|
||||
|
||||
//log request at result end
|
||||
app.use((req, res, next) => {
|
||||
if (config['access_log']) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"host": "",
|
||||
"data_dir": "data",
|
||||
"view_engine": "ejs",
|
||||
"rate_limit": 100,
|
||||
"access_log": "access.log",
|
||||
"error_log": "error.log",
|
||||
"modules": {
|
||||
|
||||
+3
-3
@@ -150,10 +150,10 @@ module.exports = (config) => {
|
||||
};
|
||||
|
||||
let faDiagrams;
|
||||
let yaml;
|
||||
let toml;
|
||||
if (config['modules']['fa-diagrams']) {
|
||||
faDiagrams = require('fa-diagrams');
|
||||
yaml = require('js-yaml');
|
||||
toml = require('@iarna/toml');
|
||||
}
|
||||
|
||||
const renderFaDiagrams = (data, cb) => {
|
||||
@@ -167,7 +167,7 @@ module.exports = (config) => {
|
||||
const code = match[1].trim();
|
||||
let output;
|
||||
try {
|
||||
const diagData = yaml.safeLoad(code);
|
||||
const diagData = toml.parse(code);
|
||||
const findLineBreaks = (data) => {
|
||||
Object.keys(data).forEach(key => {
|
||||
if (typeof data[key] === 'object')
|
||||
|
||||
+11
-8
@@ -241,26 +241,29 @@ describe('Test MathJax', () => {
|
||||
describe('Test fa-diagrams', () => {
|
||||
test('no fa-diagrams', (done) => {
|
||||
config['modules']['fa-diagrams'] = false;
|
||||
renderer.renderFaDiagrams('@startfad\noptions:\n\trendering:\t\tcolor:red\n\n@endfad', (data) => {
|
||||
expect(data).toBe('@startfad\noptions:\n\trendering:\t\tcolor:red\n\n@endfad');
|
||||
renderer.renderFaDiagrams('@startfad\noptions.rendering.color=\'red\'\n@endfad', (data) => {
|
||||
expect(data).toBe('@startfad\noptions.rendering.color=\'red\'\n@endfad');
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('no fa-diagrams in code', (done) => {
|
||||
renderer.renderFaDiagrams('code:\n```\n@startfad\noptions:\n\trendering:\t\tcolor:red\n\n@endfad\n```', (data) => {
|
||||
expect(data).toBe('code:\n```\n@startfad\noptions:\n\trendering:\t\tcolor:red\n\n@endfad\n```');
|
||||
renderer.renderFaDiagrams('code:\n```\n@startfad\noptions.rendering.color=\'red\'\n@endfad\n```', (data) => {
|
||||
expect(data).toBe('code:\n```\n@startfad\noptions.rendering.color=\'red\'\n@endfad\n```');
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('valid fa-diagrams', (done) => {
|
||||
renderer.renderFaDiagrams('before\n@startfad\noptions:\n rendering:\n color: red\n@endfad\nafter', (data) => {
|
||||
renderer.renderFaDiagrams('before\n@startfad\noptions.rendering.color=\'red\'\n@endfad\nafter', (data) => {
|
||||
expect(data).toBe('before\n<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 0 0" width="0" height="0" font-family="Arial" font-size="15" fill="red" stroke-width="0"></svg>\nafter');
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('invalid yaml', (done) => {
|
||||
renderer.renderFaDiagrams('before\n@startfad\noptions:\n@endfad\nafter', (data) => {
|
||||
expect(data).toBe('before\n<b style="color:red">TypeError: Cannot convert undefined or null to object</b>\nafter');
|
||||
test('invalid toml', (done) => {
|
||||
renderer.renderFaDiagrams('before\n@startfad\noptions.rendering.color=red\n@endfad\nafter', (data) => {
|
||||
expect(data).toBe('before\n<b style="color:red">TomlError: Unexpected character, expecting string, number, datetime, boolean, inline array or inline table at row 1, col 26, pos 25:\n' +
|
||||
'1> options.rendering.color=red\n' +
|
||||
' ^\n' +
|
||||
'\n</b>\nafter');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 20 KiB |
@@ -10,6 +10,7 @@ node nodejs {
|
||||
}
|
||||
|
||||
package data {
|
||||
[template.ejs]
|
||||
package "2019/06/18" {
|
||||
component index [
|
||||
index.md
|
||||
@@ -22,6 +23,7 @@ package data {
|
||||
web -down-> TCP : 1. /2019/06/18/title
|
||||
express -down-> index : 2. fetch
|
||||
index -up-> showdown : 3. markdown
|
||||
template.ejs -up-> express : 4
|
||||
showdown -left-> express : 4. html
|
||||
express -up-> web : 5. html
|
||||
|
||||
|
||||
Reference in New Issue
Block a user