Skip to content

Commit 84ae60d

Browse files
authored
Merge pull request #51 from coderbunker/markdown
Add Markdown support for spreadsheet item objects.
2 parents d1359e5 + 31ef4fc commit 84ae60d

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

app.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ const express = require('express');
22

33
const qr = require('qr-image');
44

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

712
const app = express();
813

@@ -56,20 +61,19 @@ app.get('/recent', (req, res) => {
5661

5762
app.get('/:uuid', (req, res) => {
5863
loadDatabase((allItems) => {
59-
const matches = searchDatabase(req.params, allItems);
60-
if (matches.length === 0) {
64+
const match = searchDatabase(req.params, allItems)[0];
65+
if (match.length === 0) {
6166
logScanned(req.params.uuid);
6267
res.status(404).render('notFound', {
6368
item: '',
6469
id: req.params.uuid,
6570
});
6671
return;
6772
}
68-
logScanned(req.params.uuid, matches[0].fixture);
69-
matches[0].similarItems = searchDatabase({ fixture: matches[0].fixture }, allItems)
70-
.filter(item => item.uuid !== matches[0].uuid)
71-
.splice(0, 3);
72-
res.render('item', matches[0]);
73+
addMarkdown(match);
74+
addSimilarItems(match, allItems);
75+
logScanned(req.params.uuid, match.fixture);
76+
res.render('item', match);
7377
});
7478
});
7579

googleSpreadsheet.js

Lines changed: 17 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,23 @@ function searchDatabase(query, rows) {
3334
return matches;
3435
}
3536

37+
function addSimilarItems(obj, allObj) {
38+
obj.similarItems = searchDatabase({ fixture: obj.fixture }, allObj)
39+
.filter(item => item.uuid !== obj.uuid)
40+
.splice(0, 3);
41+
return obj;
42+
}
43+
44+
function addMarkdown(obj) {
45+
obj.HOWTO = marked(obj.HOWTO);
46+
obj.details = marked(obj.details);
47+
obj.Troubleshooting = marked(obj.Troubleshooting);
48+
return obj;
49+
}
50+
3651
module.exports = {
3752
loadDatabase,
3853
searchDatabase,
54+
addMarkdown,
55+
addSimilarItems,
3956
};

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"express-session": "^1.15.5",
2222
"googleapis": "^21.3.0",
2323
"jquery": "^3.2.1",
24+
"marked": "^0.3.7",
2425
"qr-image": "^3.2.0",
2526
"url-regex": "^4.1.1",
2627
"uuid-regexp": "^0.3.0"

views/notFound.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<article style='margin-top:2em'class="col-xs-12 col-lg-4 col-lg-offset-4">
55
<p>Sorry, item not found with the id:</p>
66
<p>
7-
<strong><%= id %></strong>
7+
<strong><%- id %></strong>
88
</p>
99
</article>
1010

0 commit comments

Comments
 (0)