-
Notifications
You must be signed in to change notification settings - Fork 686
Expand file tree
/
Copy path.eleventy.js
More file actions
142 lines (120 loc) · 4 KB
/
.eleventy.js
File metadata and controls
142 lines (120 loc) · 4 KB
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
const markdownIt = require("markdown-it");
module.exports = function (eleventyConfig) {
// Markdown configuration
const md = markdownIt({
html: true,
breaks: false,
linkify: true
});
eleventyConfig.setLibrary("md", md);
// Pass through copy for static assets
eleventyConfig.addPassthroughCopy("src/img");
eleventyConfig.addPassthroughCopy("src/css");
eleventyConfig.addPassthroughCopy("src/js");
eleventyConfig.addPassthroughCopy("src/CNAME");
eleventyConfig.addPassthroughCopy("src/ads.txt");
eleventyConfig.addPassthroughCopy("src/.nojekyll");
eleventyConfig.addPassthroughCopy({ "src/img/favicon.png": "favicon.png" });
// Custom filter to get page slug from URL
eleventyConfig.addFilter("getSlug", function (url) {
if (!url) return "";
const parts = url.split('/').filter(p => p);
return parts[parts.length - 1] || "";
});
eleventyConfig.addFilter("htmlDateString", (dateObj) => {
return new Date(dateObj).toISOString().split('T')[0];
});
// Custom filter to check if URL starts with a path
eleventyConfig.addFilter("startsWith", function (url, path) {
if (!url) return false;
return url.startsWith(path);
});
// Custom filter for getting tutorial name from URL
eleventyConfig.addFilter("getTutorialName", function (url) {
if (!url) return "";
const parts = url.split('/').filter(p => p);
if (parts[0] === 'tutorial' && parts.length > 1) {
return parts[1];
}
return "";
});
// Custom filter for URL encoding
eleventyConfig.addFilter("urlencode", function (str) {
return encodeURIComponent(str);
});
// Collections
eleventyConfig.addCollection("tutorials", function (collectionApi) {
return collectionApi.getFilteredByGlob("src/tutorial/*.md").sort((a, b) => {
return (a.data.order || 0) - (b.data.order || 0);
});
});
eleventyConfig.addCollection("enTutorials", function (collectionApi) {
return collectionApi.getFilteredByGlob("src/en/tutorial/*.md").sort((a, b) => {
return (a.data.order || 0) - (b.data.order || 0);
});
});
eleventyConfig.addCollection("articles", function (collectionApi) {
const items = collectionApi.getFilteredByGlob("src/[0-9][0-9][0-9][0-9]/**/*.md");
function getSortTime(item) {
if (item?.data?.date) {
const parsed = new Date(item.data.date);
if (!Number.isNaN(parsed.getTime())) return parsed.getTime();
}
const url = item?.url || "";
const match = url.match(/^\/(\d{4})\/(\d{2})\//);
if (match) {
const year = match[1];
const month = match[2];
const parsed = new Date(`${year}-${month}-01T00:00:00Z`);
if (!Number.isNaN(parsed.getTime())) return parsed.getTime();
}
return 0;
}
// Newest first
return items.sort((a, b) => getSortTime(b) - getSortTime(a));
});
// Format "Januari 2026" from URL like /2026/01/slug/
eleventyConfig.addFilter("getMonthYearFromUrl", function (url) {
if (!url) return "";
const match = url.match(/^\/(\d{4})\/(\d{2})\//);
if (!match) return "";
const year = match[1];
const month = match[2];
const monthNames = {
"01": "Januari",
"02": "Februari",
"03": "Maret",
"04": "April",
"05": "Mei",
"06": "Juni",
"07": "Juli",
"08": "Agustus",
"09": "September",
"10": "Oktober",
"11": "November",
"12": "Desember",
};
return `${monthNames[month] || month} ${year}`;
});
// Watch targets
eleventyConfig.addWatchTarget("./src/css/");
eleventyConfig.addWatchTarget("./tailwind.css");
// BrowserSync config for live reload on CSS changes
eleventyConfig.setServerOptions({
watch: ["_site/css/**/*.css"],
liveReload: true,
});
return {
dir: {
input: "src",
output: "_site",
includes: "_includes",
layouts: "_layouts",
data: "_data"
},
templateFormats: ["md", "njk", "html"],
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
passthroughFileCopy: true
};
};