-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.hygen.js
38 lines (31 loc) · 1.03 KB
/
.hygen.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
const { v4: uuidv4 } = require("uuid");
const today = new Date();
const getYear = today.getFullYear();
const getMonth = today.getMonth() + 1;
const getDay = today.getDate();
const padLeft = (num) => (num < 10 ? "0" + num : "" + num);
const getDate = `${getYear}-${padLeft(getMonth)}-${padLeft(getDay)}`;
const IMAGE_PATH = "/_images/";
const DEFAULT_THUMB = IMAGE_PATH + "default-thumb.png";
module.exports = {
helpers: {
getPostFileName: (locals, yearFolder = false) => {
if (locals.isDraft === "yes") {
return `DRAFT-${locals.permalink ? locals.permalink : uuidv4()}`;
}
const permalink =
locals.permalink ||
locals.title.toLowerCase().replaceAll(/[^\w]/g, "-").replaceAll(/-+/g, "-");
let postYear = getYear;
let postDate = getDate;
if (locals.date) {
postYear = locals.date.split("-")[0];
postDate = locals.date;
}
return `${yearFolder ? `${getYear}/` : ""}${postDate}-${permalink}`;
},
getYear,
IMAGE_PATH,
DEFAULT_THUMB,
},
};