Rename files to make it easier to move files around
This commit is contained in:
parent
f7c472d762
commit
180ea98786
46
bin/deck
46
bin/deck
@ -11,6 +11,10 @@ var handlebars = require('handlebars');
|
||||
var app = express();
|
||||
var staticHandler = express['static'].bind(express);
|
||||
|
||||
function toInt(num) {
|
||||
return parseInt(num, 10);
|
||||
}
|
||||
|
||||
app.use((function log() {
|
||||
var text = '{{date}} {{req.method}} {{req.url}}';
|
||||
var logTemplate = handlebars.compile(text);
|
||||
@ -50,17 +54,27 @@ function index(req, res) {
|
||||
|
||||
app.get('/', index);
|
||||
|
||||
app.get('/slides', function showHandler(req, res) {
|
||||
function getMarkdownFiles(cb) {
|
||||
fs.readdir(pathToFile('data', 'slide'), function (err, files) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
files.sort();
|
||||
var jsonFiles = _.filter(files, function (file) {
|
||||
var markdownFiles = _.filter(files, function (file) {
|
||||
return /^\d+\.md$/.test(file);
|
||||
});
|
||||
cb(null, markdownFiles);
|
||||
});
|
||||
}
|
||||
|
||||
res.send(_.map(jsonFiles, function (file) {
|
||||
return {
|
||||
id: parseInt(file.replace(/\.md$/, ''), 10)
|
||||
};
|
||||
app.get('/slides', function showHandler(req, res) {
|
||||
getMarkdownFiles(function (err, files) {
|
||||
if (err) {
|
||||
return renderError(res, err);
|
||||
}
|
||||
|
||||
res.send(_.map(files, function (file, index) {
|
||||
return {id: index + 1};
|
||||
}));
|
||||
});
|
||||
});
|
||||
@ -71,33 +85,23 @@ app.get(/slide\/(\d+)/, function showHandler(req, res, next) {
|
||||
return;
|
||||
}
|
||||
|
||||
var slideIndex = req.params[0];
|
||||
var slideIndex = toInt(req.params[0]);
|
||||
|
||||
fs.readdir(pathToFile('data', 'slide'), function (err, files) {
|
||||
getMarkdownFiles(function (err, files) {
|
||||
if (err) {
|
||||
return renderError(res, err);
|
||||
}
|
||||
|
||||
files.sort();
|
||||
var markdownFiles = _.filter(files, function (file) {
|
||||
return /\.md$/.test(file);
|
||||
});
|
||||
|
||||
if (slideIndex > markdownFiles.length) {
|
||||
if (slideIndex > files.length) {
|
||||
return next();
|
||||
}
|
||||
|
||||
var markdownFile = markdownFiles[slideIndex - 1];
|
||||
var markdownFile = files[slideIndex - 1];
|
||||
var markdownPath = pathToFile('data', 'slide', markdownFile);
|
||||
fs.readFile(markdownPath, {encoding: 'utf8'}, function (err, content) {
|
||||
if (err) {
|
||||
return renderError(res, err);
|
||||
}
|
||||
|
||||
res.send({
|
||||
id: parseInt(slideIndex, 10),
|
||||
copy: content
|
||||
});
|
||||
res.send({id: toInt(slideIndex), copy: content});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user