-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy path_util.js
More file actions
32 lines (27 loc) · 833 Bytes
/
_util.js
File metadata and controls
32 lines (27 loc) · 833 Bytes
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
const path = require('path');
const fs = require('fs');
const routes = require('../eleventy/routes');
const markdown = require('../eleventy/markdown');
function codeSnippet(filename, lang) {
const filePath = path.join(__dirname, `./_snippets/${filename}`);
if (lang && lang === 'json') {
const jsonObj = require(filePath);
return '```json\n' + JSON.stringify(jsonObj, null, 4) + '\n```';
} else {
return '```\n' + require(filePath) + '\n```';
}
}
function snippet(filename) {
const filePath = path.join(__dirname, `./_snippets/${filename}`);
const fileContents = fs.readFileSync(filePath);
return fileContents;
}
function route(name, locale) {
return routes.find(name, locale);
}
module.exports = {
md: markdown.render,
codeSnippet,
snippet,
route,
};