Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suport for image files and ignore directories #9

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 17 additions & 7 deletions app.js
Expand Up @@ -5,7 +5,7 @@ var express = require('express'),
cookieParser = require('cookie-parser'),
bodyParser = require('body-parser'),
fs = require('fs'),
marked = require('marked'),
marked = require('marked'),
moment = require('moment'),
raneto = require('./raneto'),
config = require('./config'),
Expand Down Expand Up @@ -41,12 +41,22 @@ app.all('*', function(req, res, next){
body_class: 'page-search'
});
}
else if(req.params[0]){
else if(req.params[0]){
var slug = req.params[0];
var filePath, pageList;

//We're serving an image here, withoud preprocessing
if (raneto.allowedImageTypes.indexOf(path.extname(slug)) >= 0) {
filePath = __dirname +'/content'+ slug;
res.sendfile(filePath);
return true;
}

//if not an image, we'll process as markdown page
if(slug == '/') slug = '/index';

var filePath = __dirname +'/content'+ slug +'.md',
pageList = raneto.getPages(slug, config);
filePath = __dirname +'/content'+ slug +'.md';
pageList = raneto.getPages(slug, config);

if(slug == '/index' && !fs.existsSync(filePath)){
return res.render('home', {
Expand Down Expand Up @@ -81,9 +91,9 @@ app.all('*', function(req, res, next){
});
});
}
} else {
next();
}
} else {
next();
}
});

// development error handler
Expand Down
9 changes: 9 additions & 0 deletions raneto.js
Expand Up @@ -10,6 +10,8 @@ var raneto = {

metaRegex: /^\/\*([\s\S]*?)\*\//i,

allowedImageTypes: ['.jpg', '.jpeg', '.png', '.gif', '.svg'],

cleanString: function(str, underscore){
var u = underscore || false;
if(u){
Expand Down Expand Up @@ -93,6 +95,12 @@ var raneto = {

if(stat.isDirectory()){
var sort = 0;

//ignore directories that has an ignore file under it
if (fs.existsSync(__dirname +'/content/'+ shortPath +'/ignore')) {
return true;
}

if(category_sort){
try {
var sortFile = fs.readFileSync(__dirname +'/content/'+ shortPath +'/sort');
Expand All @@ -112,6 +120,7 @@ var raneto = {
files: []
});
}

if(stat.isFile() && path.extname(shortPath) == '.md'){
try {
var file = fs.readFileSync(filePath),
Expand Down