mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 05:55:48 +01:00
Merge branch 'master' of github.com:designcreateplay/NodeBB
This commit is contained in:
5
app.js
5
app.js
@@ -97,6 +97,8 @@
|
|||||||
|
|
||||||
translator.loadServer();
|
translator.loadServer();
|
||||||
|
|
||||||
|
var customTemplates = meta.config['theme:templates'] ? path.join(__dirname, 'node_modules', meta.config['theme:id'], meta.config['theme:templates']) : false;
|
||||||
|
|
||||||
// todo: replace below with read directory code, derp.
|
// todo: replace below with read directory code, derp.
|
||||||
templates.init([
|
templates.init([
|
||||||
'header', 'footer', 'logout', 'outgoing', 'admin/header', 'admin/footer', 'admin/index',
|
'header', 'footer', 'logout', 'outgoing', 'admin/header', 'admin/footer', 'admin/index',
|
||||||
@@ -104,7 +106,8 @@
|
|||||||
'emails/header', 'emails/footer',
|
'emails/header', 'emails/footer',
|
||||||
|
|
||||||
'noscript/header', 'noscript/home', 'noscript/category', 'noscript/topic'
|
'noscript/header', 'noscript/home', 'noscript/category', 'noscript/topic'
|
||||||
]);
|
], customTemplates);
|
||||||
|
|
||||||
|
|
||||||
templates.ready(webserver.init);
|
templates.ready(webserver.init);
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ define(function() {
|
|||||||
|
|
||||||
topicsListEl.innerHTML += html;
|
topicsListEl.innerHTML += html;
|
||||||
btnEl.innerHTML = 'Load More Topics';
|
btnEl.innerHTML = 'Load More Topics';
|
||||||
|
$('span.timeago').timeago();
|
||||||
} else {
|
} else {
|
||||||
// Exhausted all topics
|
// Exhausted all topics
|
||||||
btnEl.className += ' disabled';
|
btnEl.className += ' disabled';
|
||||||
|
|||||||
@@ -57,13 +57,14 @@
|
|||||||
return template;
|
return template;
|
||||||
};
|
};
|
||||||
|
|
||||||
function loadTemplates(templatesToLoad) {
|
function loadTemplates(templatesToLoad, customTemplateDir) {
|
||||||
function loadServer() {
|
function loadServer() {
|
||||||
var loaded = templatesToLoad.length;
|
var loaded = templatesToLoad.length;
|
||||||
|
|
||||||
|
function getTemplates(directory) {
|
||||||
for (var t in templatesToLoad) {
|
for (var t in templatesToLoad) {
|
||||||
(function (file) {
|
(function (file) {
|
||||||
fs.readFile(__dirname + '/../templates/' + file + '.tpl', function (err, html) {
|
fs.readFile(directory + '/' + file + '.tpl', function (err, html) {
|
||||||
var template = function () {
|
var template = function () {
|
||||||
this.toString = function () {
|
this.toString = function () {
|
||||||
return this.html;
|
return this.html;
|
||||||
@@ -82,6 +83,16 @@
|
|||||||
}(templatesToLoad[t]));
|
}(templatesToLoad[t]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (customTemplateDir) {
|
||||||
|
fs.exists(customTemplateDir, function (exists) {
|
||||||
|
var directory = (exists ? customTemplateDir : __dirname + '/../templates');
|
||||||
|
getTemplates(directory);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
getTemplates(__dirname + '/../templates');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function loadClient() {
|
function loadClient() {
|
||||||
jQuery.when(jQuery.getJSON(RELATIVE_PATH + '/templates/config.json'), jQuery.getJSON(RELATIVE_PATH + '/api/get_templates_listing')).done(function (config_data, templates_data) {
|
jQuery.when(jQuery.getJSON(RELATIVE_PATH + '/templates/config.json'), jQuery.getJSON(RELATIVE_PATH + '/api/get_templates_listing')).done(function (config_data, templates_data) {
|
||||||
@@ -96,8 +107,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
templates.init = function (templates_to_load) {
|
templates.init = function (templates_to_load, custom_templates) {
|
||||||
loadTemplates(templates_to_load || []);
|
loadTemplates(templates_to_load || [], custom_templates || false);
|
||||||
}
|
}
|
||||||
|
|
||||||
templates.getTemplateNameFromUrl = function (url) {
|
templates.getTemplateNameFromUrl = function (url) {
|
||||||
@@ -227,6 +238,10 @@
|
|||||||
return new RegExp("<!-- BEGIN " + block + " -->[\\s\\S]*<!-- END " + block + " -->", 'g');
|
return new RegExp("<!-- BEGIN " + block + " -->[\\s\\S]*<!-- END " + block + " -->", 'g');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makeConditionalRegex(block) {
|
||||||
|
return new RegExp("<!-- IF " + block + " -->[\\s\\S]*<!-- ENDIF " + block + " -->", 'g');
|
||||||
|
}
|
||||||
|
|
||||||
function getBlock(regex, block, template) {
|
function getBlock(regex, block, template) {
|
||||||
data = template.match(regex);
|
data = template.match(regex);
|
||||||
if (data == null) return;
|
if (data == null) return;
|
||||||
@@ -240,6 +255,19 @@
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getConditionalBlock(regex, block, template) {
|
||||||
|
data = template.match(regex);
|
||||||
|
if (data == null) return;
|
||||||
|
|
||||||
|
if (self.blocks && block !== undefined) self.blocks[block] = data[0];
|
||||||
|
|
||||||
|
data = data[0]
|
||||||
|
.replace("<!-- IF " + block + " -->", "")
|
||||||
|
.replace("<!-- ENDIF " + block + " -->", "");
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
function setBlock(regex, block, template) {
|
function setBlock(regex, block, template) {
|
||||||
return template.replace(regex, block);
|
return template.replace(regex, block);
|
||||||
}
|
}
|
||||||
@@ -289,6 +317,14 @@
|
|||||||
block = parse(data[d], namespace, block);
|
block = parse(data[d], namespace, block);
|
||||||
template = setBlock(regex, block, template);
|
template = setBlock(regex, block, template);
|
||||||
} else {
|
} else {
|
||||||
|
var conditional = makeConditionalRegex(d),
|
||||||
|
block = getConditionalBlock(conditional, namespace, template);
|
||||||
|
|
||||||
|
if (block && !data[d]) {
|
||||||
|
template = template.replace(conditional, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template = replace(namespace + d, data[d], template);
|
template = replace(namespace + d, data[d], template);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<a target="_blank" href="{relative_path}/topic/{topics.slug}">{topics.title}</a>
|
<a target="_blank" href="{relative_path}/topic/{topics.slug}">{topics.title}</a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><i class="icon-time"></i> Posted {topics.relativeTime} ago by {topics.username}</li>
|
<li><i class="icon-time"></i> Posted <span class="timeago" title="{topics.relativeTime}"></span> by {topics.username}</li>
|
||||||
<li><i class="icon-comments"></i> {topics.postcount} post(s)</li>
|
<li><i class="icon-comments"></i> {topics.postcount} post(s)</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
|
|||||||
@@ -130,9 +130,8 @@ var utils = require('./../public/src/utils.js'),
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(config, next) {
|
function(config, next) {
|
||||||
if (config.staticDir) {
|
themeData['theme:staticDir'] = config.staticDir ? config.staticDir : '';
|
||||||
themeData['theme:staticDir'] = config.staticDir;
|
themeData['theme:templates'] = config.templates ? config.templates : '';
|
||||||
}
|
|
||||||
|
|
||||||
RDB.hmset('config', themeData, next);
|
RDB.hmset('config', themeData, next);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,12 @@ var RDB = require('./redis.js'),
|
|||||||
Topics.getTopicData = function(tid, callback) {
|
Topics.getTopicData = function(tid, callback) {
|
||||||
RDB.hgetall('topic:' + tid, function(err, data) {
|
RDB.hgetall('topic:' + tid, function(err, data) {
|
||||||
if (err === null) {
|
if (err === null) {
|
||||||
if(data)
|
if(data) {
|
||||||
data.title = validator.sanitize(data.title).escape();
|
data.title = validator.sanitize(data.title).escape();
|
||||||
|
if(data.timestamp) {
|
||||||
|
data.relativeTime = new Date(parseInt(data.timestamp, 10)).toISOString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
callback(data);
|
callback(data);
|
||||||
} else {
|
} else {
|
||||||
@@ -327,8 +331,6 @@ var RDB = require('./redis.js'),
|
|||||||
topicData['lock-icon'] = topicData.locked === '1' ? 'icon-lock' : 'none';
|
topicData['lock-icon'] = topicData.locked === '1' ? 'icon-lock' : 'none';
|
||||||
topicData['deleted-class'] = topicData.deleted === '1' ? 'deleted' : '';
|
topicData['deleted-class'] = topicData.deleted === '1' ? 'deleted' : '';
|
||||||
|
|
||||||
topicData.relativeTime = new Date(parseInt(topicData.timestamp, 10)).toISOString();
|
|
||||||
|
|
||||||
topicData.username = topicInfo.username;
|
topicData.username = topicInfo.username;
|
||||||
topicData.badgeclass = (topicInfo.hasread && current_user != 0) ? '' : 'badge-important';
|
topicData.badgeclass = (topicInfo.hasread && current_user != 0) ? '' : 'badge-important';
|
||||||
topicData.teaser_text = topicInfo.teaserInfo.text || '',
|
topicData.teaser_text = topicInfo.teaserInfo.text || '',
|
||||||
@@ -455,7 +457,6 @@ var RDB = require('./redis.js'),
|
|||||||
hasRead = results[1],
|
hasRead = results[1],
|
||||||
teaser = results[2];
|
teaser = results[2];
|
||||||
|
|
||||||
topicData.relativeTime = new Date(parseInt(topicData.timestamp,10)).toISOString();
|
|
||||||
topicData.badgeclass = hasRead ? '' : 'badge-important';
|
topicData.badgeclass = hasRead ? '' : 'badge-important';
|
||||||
topicData.teaser_text = teaser.text || '';
|
topicData.teaser_text = teaser.text || '';
|
||||||
topicData.teaser_username = teaser.username || '';
|
topicData.teaser_username = teaser.username || '';
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ var express = require('express'),
|
|||||||
cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
|
cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
|
||||||
pluginCSS: plugins.cssFiles.map(function(file) { return { path: file } }),
|
pluginCSS: plugins.cssFiles.map(function(file) { return { path: file } }),
|
||||||
title: meta.config.title || '',
|
title: meta.config.title || '',
|
||||||
|
description: meta.config.description || '',
|
||||||
'brand:logo': meta.config['brand:logo'] || '',
|
'brand:logo': meta.config['brand:logo'] || '',
|
||||||
'brand:logo:display': meta.config['brand:logo']?'':'hide',
|
'brand:logo:display': meta.config['brand:logo']?'':'hide',
|
||||||
browserTitle: meta.config.title || 'NodeBB',
|
browserTitle: meta.config.title || 'NodeBB',
|
||||||
@@ -165,7 +166,7 @@ var express = require('express'),
|
|||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
// Theme configuration
|
// Theme configuration
|
||||||
RDB.hmget('config', 'theme:type', 'theme:id', 'theme:staticDir', function(err, themeData) {
|
RDB.hmget('config', 'theme:type', 'theme:id', 'theme:staticDir', 'theme:templates', function(err, themeData) {
|
||||||
var themeId = (themeData[1] || 'nodebb-theme-vanilla');
|
var themeId = (themeData[1] || 'nodebb-theme-vanilla');
|
||||||
|
|
||||||
// Detect if a theme has been selected, and handle appropriately
|
// Detect if a theme has been selected, and handle appropriately
|
||||||
@@ -183,6 +184,13 @@ var express = require('express'),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (themeData[3]) {
|
||||||
|
app.use('/templates', express.static(path.join(__dirname, '../node_modules', themeData[1], themeData[3])));
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
winston.info('Custom templates directory routed for theme: ' + themeData[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app.use(require('less-middleware')({
|
app.use(require('less-middleware')({
|
||||||
src: path.join(__dirname, '../node_modules/' + themeId),
|
src: path.join(__dirname, '../node_modules/' + themeId),
|
||||||
dest: path.join(__dirname, '../public/css'),
|
dest: path.join(__dirname, '../public/css'),
|
||||||
|
|||||||
Reference in New Issue
Block a user