Compare commits

...

13 Commits

Author SHA1 Message Date
Klemek e8e8024021 Merge pull request #10 from Klemek/dev
v1.1.5
2019-06-23 15:15:45 +02:00
Klemek 1806d60ca7 Fixed meta tags being wrong 2019-06-23 15:14:47 +02:00
Klemek 2c5f2e589f Merge pull request #9 from Klemek/dev
v1.1.4
2019-06-23 15:09:27 +02:00
Klemek 847d228c0a Updated templates 2019-06-23 15:06:15 +02:00
Klemek 576948acee ViewPort property 2019-06-23 15:05:06 +02:00
Klemek fa6d91db20 updated README.md 2019-06-23 15:04:15 +02:00
Klemek 989bcdf130 Pages metadata by default 2019-06-23 15:02:33 +02:00
Klemek 000104c99d Merge pull request #8 from Klemek/dev
v1.1.3
2019-06-23 14:46:52 +02:00
Klemek f2bd0ec10e Fixed config merge 2019-06-23 14:44:32 +02:00
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
11 changed files with 84 additions and 15 deletions
+6
View File
@@ -232,6 +232,12 @@ Any URL like `/year/month/day/anything/` will redirect to this article (and link
* `plantuml` (default: true) * `plantuml` (default: true)
activate PlantUML diagram rendering activate PlantUML diagram rendering
* `home` * `home`
* `title` (default: GitBlog.md)
the title of your blog, **strongly advised to be changed**
given to the template to complete page title and metadata
* `description` (default: A static blog using Markdown pulled from your git repository)
the description of your blog, **strongly advised to be changed**
given to the template to complete page title and metadata
* `index` (default: index.ejs) * `index` (default: index.ejs)
the name of the home page template on the data directory the name of the home page template on the data directory
it will receive `articles`, a list of articles for rendering it will receive `articles`, a list of articles for rendering
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "gitblog.md", "name": "gitblog.md",
"version": "1.1", "version": "1.1.5",
"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": {
+11 -1
View File
@@ -2,7 +2,17 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Error <%= error %></title> <title><%= info.title %> - Error <%= error %></title>
<meta name="twitter:card" content="summary_large_image">
<%- `<meta property="og:title" content="${info.title} - Home">` %>
<%- `<meta property="twitter:title" content="${info.title} - Home">` %>
<%- `<meta property="og:description" content="${info.description}">` %>
<%- `<meta property="twitter:description" content="${info.description}">` %>
<%- `<meta property="org:url" content="${info.host}/">` %>
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<link rel="stylesheet" type="text/css" href="/style.css"> <link rel="stylesheet" type="text/css" href="/style.css">
</head> </head>
<body> <body>
+13 -3
View File
@@ -2,13 +2,23 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>GitBlog.md - Home</title> <title><%= info.title %> - Home</title>
<meta name="twitter:card" content="summary_large_image">
<%- `<meta property="og:title" content="${info.title} - Home">` %>
<%- `<meta property="twitter:title" content="${info.title} - Home">` %>
<%- `<meta property="og:description" content="${info.description}">` %>
<%- `<meta property="twitter:description" content="${info.description}">` %>
<%- `<meta property="org:url" content="${info.host}/">` %>
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<link rel="stylesheet" type="text/css" href="style.css"> <link rel="stylesheet" type="text/css" href="style.css">
</head> </head>
<body> <body>
<main> <main>
<h1>GitBlog.md</h1> <h1><%= info.title %></h1>
A static blog using Markdown pulled from your git repository <%= info.description %>
<h2>Articles in this blog :</h2> <h2>Articles in this blog :</h2>
<% articles.forEach((article) => { %> <% articles.forEach((article) => { %>
<div class="article"> <div class="article">
+15 -1
View File
@@ -2,7 +2,21 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>GitBlog.md - <%= article.title %></title> <title><%= info.title %> - <%= article.title %></title>
<meta name="twitter:card" content="summary_large_image">
<%- `<meta property="og:title" content="${info.title} - ${article.title}">` %>
<%- `<meta property="twitter:title" content="${info.title} - ${article.title}">` %>
<%- `<meta property="og:description" content="${info.description}">` %>
<%- `<meta property="twitter:description" content="${info.description}">` %>
<%- `<meta property="org:url" content="${info.host + article.url}">` %>
<% if (article.thumbnail) { %>
<%- `<meta property="org:image" content="${info.host + article.thumbnail}">` %>
<%- `<meta property="twitter:image" content="${info.host + article.thumbnail}">` %>
<% } %>
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<link rel="stylesheet" type="text/css" href="/prism.css"> <link rel="stylesheet" type="text/css" href="/prism.css">
<link rel="stylesheet" type="text/css" href="/style.css"> <link rel="stylesheet" type="text/css" href="/style.css">
</head> </head>
+13 -1
View File
@@ -36,6 +36,7 @@ module.exports = (config) => {
const articles = {}; const articles = {};
let lastRSS = ''; let lastRSS = '';
let host;
/** /**
* Fetch articles from the data folder and send success as a response * Fetch articles from the data folder and send success as a response
@@ -73,6 +74,9 @@ module.exports = (config) => {
*/ */
const render = (res, vPath, data, code = 200) => { const render = (res, vPath, data, code = 200) => {
data.info = { data.info = {
title: config['home']['title'],
description: config['home']['description'],
host: host,
version: pjson.version version: pjson.version
}; };
res.render(vPath, data, (err, html) => { res.render(vPath, data, (err, html) => {
@@ -100,6 +104,14 @@ module.exports = (config) => {
}); });
}; };
app.use((req, res, next) => {
if (!host) {
host = 'http://' + req.headers.host;
console.log(cons.ok, 'Currently hosted on ' + host);
}
next();
});
//log request at result end //log request at result end
app.use((req, res, next) => { app.use((req, res, next) => {
if (config['access_log']) { if (config['access_log']) {
@@ -225,7 +237,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);
+2
View File
@@ -12,6 +12,8 @@
"plantuml": true "plantuml": true
}, },
"home": { "home": {
"title": "GitBlog.md",
"description": "A static blog using Markdown pulled from your git repository",
"index": "index.ejs", "index": "index.ejs",
"error": "error.ejs", "error": "error.ejs",
"hidden": [ "hidden": [
+4
View File
@@ -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]));
-4
View File
@@ -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
View File
@@ -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();
}); });
+14
View File
@@ -65,3 +65,17 @@ test('wrong config fixed', () => {
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']);
});