-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
254 lines (229 loc) · 6.03 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
'use strict';
const Metalsmith = require('metalsmith');
const lunr = require('metalsmith-lunr');
const prism = require('metalsmith-prism');
const drafts = require('metalsmith-drafts');
const assets = require('metalsmith-assets');
const inspect = require('metalsmith-inspect');
const layouts = require('metalsmith-layouts');
const inPlace = require('metalsmith-in-place');
const paginate = require('metalsmith-paginate');
const gravatar = require('metalsmith-gravatar');
const excerpts = require('metalsmith-excerpts');
const redirect = require('metalsmith-redirect');
const permalinks = require('metalsmith-permalinks');
const collections = require('metalsmith-collections');
const discoverHelpers = require('metalsmith-discover-helpers');
const discoverPartials = require('metalsmith-discover-partials');
const markdownRemarkable = require('metalsmith-markdown-remarkable');
const remarkableEmoji = require('remarkable-emoji');
const remarkableMentions = require('remarkable-mentions');
const striptags = require('striptags');
const {TfIdf} = require('natural');
function relations(options) {
options = Object.assign({
terms: 5,
max: 5,
threshold: 0,
text: document => String(document.contents)
}, options);
if(options.match == null) {
throw new Error("Expected match criteria on which to filter.");
}
function matchDocument(file) {
const {match} = options;
return Object.keys(match).every(key => {
if(file[key] === match[key]) { return true }
if(file[key] && file[key].indexOf) {
return file[key].indexOf(match[key]) > -1;
}
return false;
});
}
return (files, metalsmith, done) => {
const tfidf = new TfIdf();
const keys = Object.keys(files).filter(key => matchDocument(files[key]));
keys.forEach(key => tfidf.addDocument(options.text(files[key]), key));
keys.forEach((key, index) => {
const document = files[key];
const keyTerms = tfidf.listTerms(index)
.slice(0, options.terms)
.map(({term}) => term);
document.relations = keys.reduce((relations, key, d) => {
if(d !== index) {
const frequency = tfidf.tfidf(keyTerms, d);
if(frequency > options.threshold) {
relations.push({key, frequency});
}
}
return relations;
}, [])
.sort((a, b) => a.frequency - b.frequency)
.slice(0, options.max)
.map(({key}) => files[key]);
});
done();
};
}
console.log('ENV:', process.env.NODE_ENV || 'development');
Metalsmith(__dirname)
.metadata({
site: {
// Site Info
title: "Blog Title",
description: "Describe your website here.",
url: process.env.NODE_ENV === 'production' ? "http://peden.software/neo-hpstr-metalsmith-theme" : 'http://localhost:8080',
reading_time: true,
words_per_minute: 200,
disqus: '',
google_analytics: '',
// Site Locale Info
timezone: 'America/Chicago',
locale: 'en_US',
// Site Menu
menu: [{
title: 'GitHub',
url: '#',
submenu: [{
title: 'Install',
url: "https://github.com/tjpeden/neo-hpstr-metalsmith-theme#installation",
}, {
title: 'Fork',
url: "https://github.com/tjpeden/neo-hpstr-metalsmith-theme",
}]
}, {
title: 'About',
url: '/about',
}, {
title: 'Archive',
url: '/posts',
}, {
title: 'Home',
url: '/',
}],
// Generator Info
generator: {
name: 'Matalsmith',
url: "http://www.metalsmith.io/",
},
// Theme Info
theme: {
name: 'Neo-HPSTR Metalsmith Theme',
url: "https://github.com/tjpeden/neo-hpstr-metalsmith-theme",
},
// Owner Info
owner: {
name: "Your name",
url: "http://peden.software",
bio: "Your bio goes here. It shouldn't be super long, but a good couple of sentences should suffice.",
email: "[email protected]",
twitter: 'tjpeden',
networks: [{
name: 'GitHub',
icon: 'github-alt',
url: "https://github.com/tjpeden",
}, {
name: 'CodePen',
icon: 'codepen',
url: "http://codepen.io/tjpeden/",
}, {
name: 'Facebook',
icon: 'facebook-official',
url: "https://www.facebook.com/tj.peden",
}, {
name: 'Twitter',
icon: 'twitter',
url: "https://twitter.com/tjpeden",
}, {
name: 'LinkedIn',
icon: 'linkedin',
url: "https://www.linkedin.com/in/tjpeden",
}, {
name: 'YouTube',
icon: 'youtube-play',
url: "https://www.youtube.com/TheTJPeden",
}, {
name: 'Twitch',
icon: 'twitch',
url: "https://www.twitch.tv/tjpeden",
}],
},
},
})
.use(inspect({
disable: true,
includeMetalsmith: true,
exclude: ['contents', 'excerpt', 'stats', 'next', 'previous'],
}))
.source('./content')
.destination('./public')
.clean(true)
.use(drafts())
.use(collections({
posts: {
sortBy: 'date',
reverse: true,
}
}))
.use(relations({
max: 3,
match: {
collection: 'posts',
}
}))
.use(
markdownRemarkable('full', {
html: true,
linkify: true,
typographer: true,
})
.use(remarkableEmoji)
.use(remarkableMentions())
)
.use(prism({
lineNumbers: true,
}))
.use(excerpts())
.use(gravatar({
owner: "[email protected]",
}))
.use(permalinks({
pattern: ':title',
linksets: [
{
match: { collection: 'posts' },
pattern: ':date/:title',
},
],
}))
.use(paginate({
path: 'page',
}))
.use(discoverHelpers())
.use(discoverPartials())
.use(inPlace())
.use(layouts({
engine: 'handlebars',
default: 'page.html',
}))
.use(lunr({
ref: 'path',
indexPath: 'search/index.json',
fields: {
title: 5,
contents: 1,
tags: 10,
},
preprocess: striptags
}))
// .use(redirect({
// '/old/path': '/new/path',
// }))
.use(assets({
source: './assets',
}))
.build((error, files) => {
if(error) {
throw error;
}
});