-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
47 lines (38 loc) · 1.89 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
This is a file of data and helper functions that we can expose and use in our templating function
*/
// FS is a built in module to node that let's us read files from the system we're running on
const fs = require('fs');
// Day.js 2KB immutable date library alternative to Moment.js with the same modern API
// we need this in our templates to display things like "Posted 5 minutes ago"
const dayjs = require('dayjs');
const relativeTime = require('dayjs/plugin/relativeTime');
// const advancedFormat = require('dayjs/plugin/advancedFormat');
// const isLeapYear = require('dayjs/plugin/relativeTime');
// const weekOfYear = require('dayjs/plugin/weekOfYear');
// const isBetween = require('dayjs/plugin/isBetween');
// const isSameOrAfter = require('dayjs/plugin/isSameOrAfter');
// const isSameOrBefore = require('dayjs/plugin/isSameOrBefore');
dayjs.extend(relativeTime);
// dayjs.extend(advancedFormat);
// dayjs.extend(isLeapYear);
// dayjs.extend(weekOfYear);
// dayjs.extend(isBetween);
// dayjs.extend(isSameOrAfter);
// dayjs.extend(isSameOrBefore);
exports.moment = dayjs;
// Dump is a handy debugging function we can use to sort of "console.log" our data
exports.dump = obj => JSON.stringify(obj, null, 2);
// Making a static map is really long - this is a handy helper function to make one
exports.staticMap = ([lng, lat]) => `https://maps.googleapis.com/maps/api/staticmap?center=${lat},${lng}&zoom=14&size=800x150&key=${process.env.MAP_KEY}&markers=${lat},${lng}&scale=2`;
// inserting an SVG
exports.icon = name => fs.readFileSync(`./public/images/icons/${name}.svg`);
// Some details about the site
exports.siteName = 'That Be Delicious!';
exports.menu = [
{ slug: '/stores', title: 'Stores', icon: 'store' },
{ slug: '/tags', title: 'Tags', icon: 'tag' },
{ slug: '/top', title: 'Top', icon: 'top' },
{ slug: '/add', title: 'Add', icon: 'add' },
{ slug: '/map', title: 'Map', icon: 'map' },
];