-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.js
82 lines (72 loc) · 2.09 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
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
const slugify = require('slugify');
const dayjs = require('dayjs');
const utc = require('dayjs/plugin/utc');
const timezone = require('dayjs/plugin/timezone');
dayjs.extend(utc);
dayjs.extend(timezone);
function getSlug(fslug) {
// test for my note files from micropub, which look like this:
// 20200810123845.md
if (/^\d\d\d\d\d\d\d\d\d\d\d\d\d\d(.*)/.test(fslug)) {
// pick up the time portion of the timestamp
return fslug.substring(8);
} else {
// otherwise just return the filename
return fslug;
}
}
function dateFormat(date, format) {
return dayjs(date).tz('America/Montreal').format(format);
}
function makePermalink(page) {
const date_part = dateFormat(page.date, 'YYYY/MM/DD');
const slug = getSlug(page.fileSlug);
const url = `${date_part}/${slug}`;
return page.album ? `${url}/index` : url;
}
function postTypes(collection, postTypes) {
return collection.filter(item => postTypes.includes(item.data.postType));
}
function getPosts(collection) {
return collection.getFilteredByGlob("./src/posts/feed/**/*.md")
.filter(item => !item.data.excludeFromPosts)
.reverse();
}
function getRecipes(collection) {
return collection.getFilteredByGlob("./src/recipes/feed/**/*.md").reverse();
}
function getLeafAlbums(collection) {
return collection.getFilteredByGlob("./src/posts/feed/**/*.md")
.filter(item => item.data.album && item.data.photo)
.reverse();
}
function getDrafts(collection) {
return collection.getFilteredByGlob("./src/drafts/**/*.md").reverse();
}
function navigation(root, data) {
if (!data.parent) {
return undefined;
}
const parentList = data.parent.slice().reverse();
let path = root;
const navList = parentList.map(p => {
const slug = slugify(p.title, { lower: true, strict: true } );
path += '/' + slug;
return {
title: p.title,
description: p.description,
permalink: path
};
});
return navList;
}
module.exports = {
dateFormat,
makePermalink,
postTypes,
getPosts,
getRecipes,
getLeafAlbums,
getDrafts,
navigation
}