Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bedd6a2953 | |||
| 52d37d56cd | |||
| fc7bc63c46 |
@@ -192,6 +192,14 @@ Here are the steps for Github, if you use another platform adapt it your way (he
|
||||
* Update your webhook on github to include the secret
|
||||
* Check if Github successfully reached the endpoint
|
||||
|
||||
#### 8. Keep your server always up and running (optionnal)
|
||||
|
||||
This project `package.json` comes with a [nodemon](https://github.com/remy/nodemon) config.
|
||||
|
||||
After installing (`npm i -g nodemon`) you can then run the app with juste the `nodemon` command in the working directory.
|
||||
|
||||
With this method, you can do a simple `git pull` to update your server.
|
||||
|
||||
## Writing an article
|
||||
[back to top](#gitblog-md)
|
||||
|
||||
|
||||
+12
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gitblog.md",
|
||||
"version": "1.2.1",
|
||||
"version": "1.2.2",
|
||||
"description": "A static blog using Markdown pulled from your git repository.",
|
||||
"main": "src/server.js",
|
||||
"dependencies": {
|
||||
@@ -46,5 +46,16 @@
|
||||
"!src/postinstall.js",
|
||||
"!src/lib/*.js"
|
||||
]
|
||||
},
|
||||
"nodemonConfig": {
|
||||
"ignore": [
|
||||
"test/*",
|
||||
"sample_data/*",
|
||||
"data/*",
|
||||
"uml/*",
|
||||
"*.log",
|
||||
"README.md"
|
||||
],
|
||||
"delay": "2500"
|
||||
}
|
||||
}
|
||||
|
||||
+13
-14
@@ -94,17 +94,16 @@ module.exports = (config) => {
|
||||
/**
|
||||
* Show an error with the correct page
|
||||
* @param req
|
||||
* @param resPath - the page of the original error
|
||||
* @param code - error code
|
||||
* @param res
|
||||
* @param code - error code
|
||||
*/
|
||||
const showError = (req, resPath, code, res) => {
|
||||
const showError = (req, res, code) => {
|
||||
const errorPath = path.join(config['data_dir'], config['home']['error']);
|
||||
fs.access(errorPath, fs.constants.R_OK, (err) => {
|
||||
if (err)
|
||||
res.sendStatus(code);
|
||||
else
|
||||
render(req, res, errorPath, {error: code, path: resPath}, code);
|
||||
render(req, res, errorPath, {error: code, path: req.path}, code);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -137,7 +136,7 @@ module.exports = (config) => {
|
||||
const homePath = path.join(config['data_dir'], config['home']['index']);
|
||||
fs.access(homePath, fs.constants.R_OK, (err) => {
|
||||
if (err)
|
||||
showError(req.path, 404, res);
|
||||
showError(req, res, 404);
|
||||
else
|
||||
render(req, res, homePath, {articles: Object.values(articles).sort((a, b) => ('' + b.path).localeCompare(a.path))});
|
||||
});
|
||||
@@ -150,15 +149,15 @@ module.exports = (config) => {
|
||||
const feed = new Rss({
|
||||
'title': config['rss']['title'],
|
||||
'description': config['rss']['description'],
|
||||
'feed_url': 'http://' + req.headers.host + req.url,
|
||||
'site_url': 'http://' + req.headers.host
|
||||
'feed_url': host + req.url,
|
||||
'site_url': host
|
||||
});
|
||||
Object.values(articles)
|
||||
.slice(0, config['rss']['length'])
|
||||
.forEach((article) => {
|
||||
feed.item({
|
||||
title: article.title,
|
||||
url: 'http://' + req.headers.host + article.url,
|
||||
url: host + article.url,
|
||||
date: article.date
|
||||
});
|
||||
});
|
||||
@@ -166,7 +165,7 @@ module.exports = (config) => {
|
||||
}
|
||||
res.type(req.headers['user-agent'].match(/Mozilla/) ? 'text/xml' : 'rss').send(lastRSS);
|
||||
} else {
|
||||
showError(req.path, 404, res);
|
||||
showError(req, res, 404);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -209,19 +208,19 @@ module.exports = (config) => {
|
||||
const articlePath = req.path.substr(1, 10);
|
||||
const article = articles[articlePath];
|
||||
if (!article)
|
||||
showError(req.path, 404, res);
|
||||
showError(req, res, 404);
|
||||
else {
|
||||
renderer.render(path.join(article.realPath, config['article']['index']), (err, html) => {
|
||||
if (err) {
|
||||
console.log(cons.error, `failed to render article ${req.path} : ${err}`);
|
||||
return showError(req.path, 500, res);
|
||||
return showError(req, res, 500);
|
||||
}
|
||||
article.content = html;
|
||||
const templatePath = path.join(config['data_dir'], config['article']['template']);
|
||||
fs.access(templatePath, fs.constants.R_OK, (err) => {
|
||||
if (err) {
|
||||
console.log(cons.error, `no template found at ${templatePath}`);
|
||||
showError(req.path, 500, res);
|
||||
showError(req, res, 500);
|
||||
} else
|
||||
render(req, res, templatePath, {article: article});
|
||||
});
|
||||
@@ -235,7 +234,7 @@ module.exports = (config) => {
|
||||
// catch all hidden file type and return 404
|
||||
app.get('*', (req, res, next) => {
|
||||
if (config['home']['hidden'].includes(path.extname(req.path)))
|
||||
showError(req.path, 404, res);
|
||||
showError(req, res, 404);
|
||||
else
|
||||
next();
|
||||
});
|
||||
@@ -244,7 +243,7 @@ module.exports = (config) => {
|
||||
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);
|
||||
showError(req, res, 404);
|
||||
});
|
||||
|
||||
// catch all other methods and return 400
|
||||
|
||||
Reference in New Issue
Block a user