Skip to content

Commit 9204a82

Browse files
author
Spazcool
committed
move marked to google.js, break function into two functions
1 parent 3726327 commit 9204a82

2 files changed

Lines changed: 32 additions & 14 deletions

File tree

app.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
const express = require('express');
22

3-
const marked = require('marked');
4-
53
const qr = require('qr-image');
64

7-
const { loadDatabase, searchDatabase } = require('./googleSpreadsheet');
5+
const {
6+
loadDatabase,
7+
searchDatabase,
8+
addMarkdown,
9+
addSimilarItems,
10+
} = require('./googleSpreadsheet');
811

912
const app = express();
1013

@@ -24,16 +27,6 @@ function logScanned(uuid, fixture) {
2427
allScans.unshift({ time: now, fixture, uuid });
2528
}
2629

27-
function modifyContent(obj, allObj) {
28-
obj.HOWTO = marked(obj.HOWTO);
29-
obj.details = marked(obj.details);
30-
obj.Troubleshooting = marked(obj.Troubleshooting);
31-
obj.similarItems = searchDatabase({ fixture: obj.fixture }, allObj)
32-
.filter(item => item.uuid !== obj.uuid)
33-
.splice(0, 3);
34-
return obj;
35-
}
36-
3730
app.set('view engine', 'ejs');
3831

3932
app.use(express.static(`${__dirname}/public`));
@@ -68,6 +61,7 @@ app.get('/recent', (req, res) => {
6861

6962
app.get('/:uuid', (req, res) => {
7063
loadDatabase((allItems) => {
64+
addMarkdown(allItems);
7165
const matches = searchDatabase(req.params, allItems);
7266
if (matches.length === 0) {
7367
logScanned(req.params.uuid);
@@ -77,8 +71,10 @@ app.get('/:uuid', (req, res) => {
7771
});
7872
return;
7973
}
74+
addSimilarItems(matches[0], allItems);
8075
logScanned(req.params.uuid, matches[0].fixture);
81-
res.render('item', modifyContent(matches[0], allItems));
76+
// modifyContent(matches[0], allItems
77+
res.render('item', matches[0]);
8278
});
8379
});
8480

googleSpreadsheet.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const google = require('googleapis');
22
const keys = require('./config/keys');
3+
const marked = require('marked');
34

45
function rowToObject(val, lab) {
56
const o = {};
@@ -33,7 +34,28 @@ function searchDatabase(query, rows) {
3334
return matches;
3435
}
3536

37+
function addSimilarItems(object, objects) {
38+
const obj = object;
39+
const allObj = objects;
40+
obj.similarItems = searchDatabase({ fixture: obj.fixture }, allObj)
41+
.filter(item => item.uuid !== obj.uuid)
42+
.splice(0, 3);
43+
return obj;
44+
}
45+
46+
function addMarkdown(objects) {
47+
const objs = objects;
48+
for (let i = 0; i < objs.length; i += 1) {
49+
objs[i].HOWTO = marked(objs[i].HOWTO);
50+
objs[i].details = marked(objs[i].details);
51+
objs[i].Troubleshooting = marked(objs[i].Troubleshooting);
52+
}
53+
return objs;
54+
}
55+
3656
module.exports = {
3757
loadDatabase,
3858
searchDatabase,
59+
addMarkdown,
60+
addSimilarItems,
3961
};

0 commit comments

Comments
 (0)