Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 000104c99d | |||
| f2bd0ec10e | |||
| 97dab302d8 | |||
| 55e258e093 | |||
| 7b22a4773d | |||
| 14cd1436c3 |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gitblog.md",
|
"name": "gitblog.md",
|
||||||
"version": "1.1",
|
"version": "1.1.3",
|
||||||
"description": "A static blog using Markdown pulled from your git repository.",
|
"description": "A static blog using Markdown pulled from your git repository.",
|
||||||
"main": "src/server.js",
|
"main": "src/server.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
+1
-1
@@ -225,7 +225,7 @@ module.exports = (config) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// serve all static files via get
|
// 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
|
// catch express.static errors (mostly not found) by displaying 404
|
||||||
app.get('*', (req, res) => {
|
app.get('*', (req, res) => {
|
||||||
showError(req.path, 404, res);
|
showError(req.path, 404, res);
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ const fs = require('fs');
|
|||||||
const merge = (ref, src) => {
|
const merge = (ref, src) => {
|
||||||
if (typeof ref !== typeof src) {
|
if (typeof ref !== typeof src) {
|
||||||
return ref;
|
return ref;
|
||||||
|
} else if (ref.length && !src.length) {
|
||||||
|
return ref;
|
||||||
|
} else if (ref.length && src.length) {
|
||||||
|
return src;
|
||||||
} else if (typeof ref === 'object') {
|
} else if (typeof ref === 'object') {
|
||||||
const out = {};
|
const out = {};
|
||||||
Object.keys(ref).forEach((key) => out[key] = merge(ref[key], src[key]));
|
Object.keys(ref).forEach((key) => out[key] = merge(ref[key], src[key]));
|
||||||
|
|||||||
+2
-6
@@ -22,12 +22,8 @@ module.exports = (config) => {
|
|||||||
while ((match = codeRegex.exec(data))) {
|
while ((match = codeRegex.exec(data))) {
|
||||||
const lang = match[1].trim();
|
const lang = match[1].trim();
|
||||||
const code = match[2].trim();
|
const code = match[2].trim();
|
||||||
try {
|
const block = Prism.highlight(code, Prism.languages[lang] || Prism.languages.autoit, lang);
|
||||||
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);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cb(data);
|
cb(data);
|
||||||
};
|
};
|
||||||
|
|||||||
+3
-2
@@ -385,9 +385,10 @@ describe('Test static files', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('200 valid file', (done) => {
|
test('200 valid file', (done) => {
|
||||||
fs.writeFileSync(path.join(dataDir, 'somefile.txt'), 'filecontent');
|
fs.writeFileSync(path.join(dataDir, 'somefile.css'), 'filecontent');
|
||||||
request(app).get('/somefile.txt').then((response) => {
|
request(app).get('/somefile.css').then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
|
expect(response.type).toBe('text/css');
|
||||||
expect(response.text).toBe('filecontent');
|
expect(response.text).toBe('filecontent');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -64,4 +64,18 @@ test('wrong config fixed', () => {
|
|||||||
expect(config).toBeDefined();
|
expect(config).toBeDefined();
|
||||||
expect(config['node_port']).toBe(3000);
|
expect(config['node_port']).toBe(3000);
|
||||||
expect(config['data_dir']).toBe('data2');
|
expect(config['data_dir']).toBe('data2');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('array parsing', () => {
|
||||||
|
fs.writeFileSync(configFile, '{"home":{"hidden":["item1","item2"]}}');
|
||||||
|
const config = require('../src/config')();
|
||||||
|
expect(config).toBeDefined();
|
||||||
|
expect(config['home']['hidden']).toEqual(['item1', 'item2']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('array fix', () => {
|
||||||
|
fs.writeFileSync(configFile, '{"home":{"hidden":{}}}');
|
||||||
|
const config = require('../src/config')();
|
||||||
|
expect(config).toBeDefined();
|
||||||
|
expect(config['home']['hidden']).toEqual(['.ejs']);
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user