Browse Source

Setup nunjuck filters and add filter for node bandwidth

pm2
Luke Childs 9 years ago
parent
commit
855edae7a3
  1. 12
      index.js
  2. 9
      lib/nunjuck-filters.js
  3. 1
      package.json
  4. 2
      views/listing.html

12
index.js

@ -1,10 +1,12 @@
const nunjucks = require('nunjucks');
const express = require('express');
const viewModel = require('./viewModels');
const app = express();
const port = process.env.port || 3000;
const nunjucks = require('nunjucks');
const express = require('express');
const nunjuckFilters = require('./lib/nunjuck-filters');
const viewModel = require('./viewModels');
const app = express();
const port = process.env.port || 3000;
app.set('nunjucksEnv', nunjucks.configure('views', { express: app }));
nunjuckFilters(app);
app.use((req, res, next) => {
req.app.settings.nunjucksEnv

9
lib/nunjuck-filters.js

@ -0,0 +1,9 @@
const humanize = require('humanize');
const filters = {
bandwidth: node => `${humanize.filesize(node.advertised_bandwidth)}/s`
};
module.exports = app => Object.keys(filters).forEach(filter => {
app.settings.nunjucksEnv.addFilter(filter, filters[filter])
});

1
package.json

@ -5,6 +5,7 @@
"main": "index.js",
"dependencies": {
"express": "^4.14.0",
"humanize": "0.0.9",
"nunjucks": "^2.4.2",
"onionoo": "^0.3.1"
},

2
views/listing.html

@ -16,7 +16,7 @@
{% for node in nodes %}
<tr>
<td><a href="/node/{{ node.fingerprint if node.fingerprint else node.hashed_fingerprint }}">{{ node.nickname }}</a></td>
<td>{{ node.advertised_bandwidth }}</td>
<td>{{ node | bandwidth }}</td>
<td>{{ node.last_restarted if node.running else 'Down' }}</td>
<td>{{ node.country_name }}</td>
<td>{{ node.flags | join(', ') }}</td>

Loading…
Cancel
Save