eleventy.config.mjs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. import { readFileSync } from 'fs';
  2. import { EleventyRenderPlugin } from "@11ty/eleventy";
  3. /** @type {import('@11ty/eleventy').LocalConfig} */
  4. export default function (eleventyConfig) {
  5. const env = process.env.NODE_ENV || "development";
  6. const isDevelopment = env === "development";
  7. eleventyConfig.setInputDirectory("src/pages");
  8. eleventyConfig.setOutputDirectory(process.env.DIST_DIR || "demo");
  9. eleventyConfig.setLayoutsDirectory("_layouts");
  10. eleventyConfig.setIncludesDirectory("_includes");
  11. eleventyConfig.setWatchThrottleWaitTime(100);
  12. eleventyConfig.addPlugin(EleventyRenderPlugin, {
  13. accessGlobalData: true,
  14. });
  15. eleventyConfig.setLiquidOptions({
  16. timezoneOffset: 0,
  17. jekyllInclude: true,
  18. dynamicPartials: true,
  19. jekyllWhere: true,
  20. });
  21. if (isDevelopment) {
  22. eleventyConfig.addWatchTarget("dist");
  23. }
  24. eleventyConfig.addPassthroughCopy("favicon.ico");
  25. /**
  26. * Data
  27. */
  28. eleventyConfig.addGlobalData("environment", env);
  29. eleventyConfig.addGlobalData("package", JSON.parse(readFileSync("package.json", "utf-8")));
  30. eleventyConfig.addGlobalData("readme", readFileSync("README.md", "utf-8"));
  31. eleventyConfig.addGlobalData("license", readFileSync("LICENSE", "utf-8"));
  32. eleventyConfig.addGlobalData("changelog", readFileSync("CHANGELOG.md", "utf-8"));
  33. eleventyConfig.addGlobalData("site", {
  34. title: "Tabler",
  35. description: "Premium and Open Source dashboard template with responsive and high quality UI.",
  36. themeColor: "#066fd1",
  37. email: "support@tabler.io",
  38. homepage: "https://tabler.io",
  39. githubUrl: "https://github.com/tabler/tabler",
  40. githubSponsorsUrl: "https://github.com/sponsors/codecalm",
  41. changelogUrl: "https://github.com/tabler/tabler/releases",
  42. sponsorUrl: "https://github.com/sponsors/codecalm",
  43. previewUrl: "https://tabler.io/demo",
  44. docsUrl: "https://tabler.io/docs",
  45. mapboxKey: "pk.eyJ1IjoidGFibGVyIiwiYSI6ImNscHh3dnhndjB2M3QycW85bGd0NXRmZ3YifQ.9LfHPsNoEXQH-xzz-81Ffw",
  46. googleMapsKey: "AIzaSyAr5mRB4U1KRkVznIrDWEvZjroYcD202DI",
  47. googleMapsDevKey: "AIzaSyCL-BY8-sq12m0S9H-S_yMqDmcun3A9znw",
  48. npmPackage: "@tabler/core",
  49. tablerCssPlugins: [
  50. "tabler-flags",
  51. "tabler-socials",
  52. "tabler-payments",
  53. "tabler-vendors",
  54. "tabler-marketing",
  55. "tabler-themes",
  56. ],
  57. icons: {
  58. link: "https://tabler.io/icons"
  59. },
  60. emails: {
  61. price: "$29",
  62. buy_link: "https://r.tabler.io/buy-emails"
  63. },
  64. illustrations: {
  65. price: "$59",
  66. count: 50,
  67. buy_link: "https://r.tabler.io/buy-illustrations"
  68. },
  69. colors: {
  70. "blue": {
  71. "class": "blue",
  72. "hex": "#066fd1",
  73. "title": "Blue"
  74. },
  75. "azure": {
  76. "class": "azure",
  77. "hex": "#45aaf2",
  78. "title": "Azure"
  79. },
  80. "indigo": {
  81. "class": "indigo",
  82. "hex": "#6574cd",
  83. "title": "Indigo"
  84. },
  85. "purple": {
  86. "class": "purple",
  87. "hex": "#a55eea",
  88. "title": "Purple"
  89. },
  90. "pink": {
  91. "class": "pink",
  92. "hex": "#f66d9b",
  93. "title": "Pink"
  94. },
  95. "red": {
  96. "class": "red",
  97. "hex": "#fa4654",
  98. "title": "Red"
  99. },
  100. "orange": {
  101. "class": "orange",
  102. "hex": "#fd9644",
  103. "title": "Orange"
  104. },
  105. "yellow": {
  106. "class": "yellow",
  107. "hex": "#f1c40f",
  108. "title": "Yellow"
  109. },
  110. "lime": {
  111. "class": "lime",
  112. "hex": "#7bd235",
  113. "title": "Lime"
  114. },
  115. "green": {
  116. "class": "green",
  117. "hex": "#5eba00",
  118. "title": "Green"
  119. },
  120. "teal": {
  121. "class": "teal",
  122. "hex": "#2bcbba",
  123. "title": "Teal"
  124. },
  125. "cyan": {
  126. "class": "cyan",
  127. "hex": "#17a2b8",
  128. "title": "Cyan"
  129. }
  130. },
  131. skinColors: {
  132. "rose": {
  133. "hex": "#FFCB9D",
  134. "title": "Rose",
  135. "class": "rose"
  136. },
  137. "yellow": {
  138. "hex": "#F0BA60",
  139. "title": "Yellow",
  140. "class": "yellow"
  141. },
  142. "skin-1": {
  143. "hex": "#e2c6a7",
  144. "title": "Skin 1",
  145. "class": "skin-1"
  146. },
  147. "skin-2": {
  148. "hex": "#c7a786",
  149. "title": "Skin 2",
  150. "class": "skin-2"
  151. },
  152. "skin-3": {
  153. "hex": "#a68063",
  154. "title": "Skin 3",
  155. "class": "skin-3"
  156. },
  157. "skin-4": {
  158. "hex": "#926241",
  159. "title": "Skin 4",
  160. "class": "skin-4"
  161. },
  162. "skin-5": {
  163. "hex": "#654c45",
  164. "title": "Skin 5",
  165. "class": "skin-5"
  166. },
  167. "gray": {
  168. "hex": "#d5d7dd",
  169. "title": "Gray",
  170. "class": "gray"
  171. }
  172. },
  173. colorsExtra: {
  174. "white": {
  175. "hex": "#ffffff",
  176. "title": "White"
  177. },
  178. "dark": {
  179. "hex": "#303645",
  180. "title": "Dark"
  181. },
  182. "gray": {
  183. "hex": "#868e96",
  184. "title": "Gray"
  185. }
  186. },
  187. variants: [
  188. {
  189. "name": "success",
  190. "icon": "check"
  191. },
  192. {
  193. "name": "info",
  194. "icon": "info-circle"
  195. },
  196. {
  197. "name": "warning",
  198. "icon": "alert-triangle"
  199. },
  200. {
  201. "name": "danger",
  202. "icon": "alert-circle"
  203. }
  204. ],
  205. "themeColors": {
  206. "primary": {
  207. "class": "primary",
  208. "title": "Primary"
  209. },
  210. "secondary": {
  211. "class": "secondary",
  212. "title": "Secondary"
  213. },
  214. "success": {
  215. "class": "success",
  216. "title": "Success"
  217. },
  218. "warning": {
  219. "class": "warning",
  220. "title": "Warning"
  221. },
  222. "danger": {
  223. "class": "danger",
  224. "title": "Danger"
  225. },
  226. "info": {
  227. "class": "info",
  228. "title": "Info"
  229. },
  230. "dark": {
  231. "class": "dark",
  232. "title": "Dark"
  233. },
  234. "light": {
  235. "class": "light",
  236. "title": "Light"
  237. }
  238. },
  239. "buttonStates": [
  240. {
  241. "class": null,
  242. "title": "Normal"
  243. },
  244. {
  245. "class": "active",
  246. "title": "Active state"
  247. },
  248. {
  249. "class": "disabled",
  250. "title": "Disabled"
  251. }
  252. ],
  253. "socials": {
  254. "x": {
  255. "icon": "brand-x",
  256. "title": "X"
  257. },
  258. "facebook": {
  259. "icon": "brand-facebook",
  260. "title": "Facebook"
  261. },
  262. "twitter": {
  263. "icon": "brand-twitter",
  264. "title": "Twitter"
  265. },
  266. "google": {
  267. "icon": "brand-google",
  268. "title": "Google"
  269. },
  270. "youtube": {
  271. "icon": "brand-youtube",
  272. "title": "Youtube"
  273. },
  274. "vimeo": {
  275. "icon": "brand-vimeo",
  276. "title": "Vimeo"
  277. },
  278. "dribbble": {
  279. "icon": "brand-dribbble",
  280. "title": "Dribbble"
  281. },
  282. "github": {
  283. "icon": "brand-github",
  284. "title": "Github"
  285. },
  286. "instagram": {
  287. "icon": "brand-instagram",
  288. "title": "Instagram"
  289. },
  290. "pinterest": {
  291. "icon": "brand-pinterest",
  292. "title": "Pinterest"
  293. },
  294. "vk": {
  295. "icon": "brand-vk",
  296. "title": "VK"
  297. },
  298. "rss": {
  299. "icon": "rss",
  300. "title": "RSS"
  301. },
  302. "flickr": {
  303. "icon": "brand-flickr",
  304. "title": "Flickr"
  305. },
  306. "bitbucket": {
  307. "icon": "brand-bitbucket",
  308. "title": "Bitbucket"
  309. },
  310. "tabler": {
  311. "icon": "brand-tabler",
  312. "title": "Tabler"
  313. }
  314. },
  315. "months-short": [
  316. "Jan",
  317. "Feb",
  318. "Mar",
  319. "Apr",
  320. "May",
  321. "Jun",
  322. "Jul",
  323. "Aug",
  324. "Sep",
  325. "Oct",
  326. "Nov",
  327. "Dec"
  328. ],
  329. "months-long": [
  330. "January",
  331. "February",
  332. "March",
  333. "April",
  334. "May",
  335. "June",
  336. "July",
  337. "August",
  338. "September",
  339. "October",
  340. "November",
  341. "December"
  342. ]
  343. });
  344. /**
  345. * Filters
  346. */
  347. eleventyConfig.addFilter("miliseconds_to_minutes", function (value) {
  348. // Raturn 3:45 time format
  349. const minutes = Math.floor(value / 60000);
  350. const seconds = ((value % 60000) / 1000).toFixed(0);
  351. return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
  352. });
  353. eleventyConfig.addFilter("relative", (page) => {
  354. const segments = (page.url || '').replace(/^\//).split('/');
  355. if (segments.length === 1) {
  356. return '.';
  357. } else {
  358. return '../'.repeat(segments.length - 1).slice(0, -1);
  359. }
  360. });
  361. eleventyConfig.addFilter("concat_objects", function (object, object2) {
  362. if (
  363. object &&
  364. object2 &&
  365. typeof object === 'object' &&
  366. typeof object2 === 'object' &&
  367. !Array.isArray(object) &&
  368. !Array.isArray(object2)
  369. ) {
  370. return { ...object, ...object2 };
  371. }
  372. return object;
  373. });
  374. eleventyConfig.addFilter("replace_regex", function (input, regStr, replStr) {
  375. const regex = new RegExp(regStr, 'gm');
  376. return input.replace(regex, replStr);
  377. });
  378. eleventyConfig.addFilter("timestamp_to_date", function (timestamp) {
  379. const date = new Date(timestamp * 1000); // Convert timestamp to milliseconds
  380. return date.toISOString().split('T')[0]; // Extract the date in 'YYYY-MM-DD' format
  381. });
  382. eleventyConfig.addFilter("split_to_n", function (arr, n) {
  383. const chunkSize = Math.round(arr.length / n);
  384. const result = [];
  385. for (let i = 0; i < arr.length; i += chunkSize) {
  386. result.push(arr.slice(i, i + chunkSize));
  387. }
  388. return result;
  389. })
  390. eleventyConfig.addFilter("format_number", function (value) {
  391. return value.toString()
  392. .split('')
  393. .reverse()
  394. .reduce((acc, char, index) => {
  395. if (index > 0 && index % 3 === 0) {
  396. acc.push(',');
  397. }
  398. acc.push(char);
  399. return acc;
  400. }, [])
  401. .reverse()
  402. .join('');
  403. });
  404. function randomNumber(x, min = 0, max = 100, round = 0) {
  405. let value = ((x * x * Math.PI * Math.E * (max + 1) * (Math.sin(x) / Math.cos(x * x))) % (max + 1 - min)) + min;
  406. value = value > max ? max : value;
  407. value = value < min ? min : value;
  408. if (round !== 0) {
  409. value = parseFloat(value.toFixed(round));
  410. } else {
  411. value = Math.floor(value);
  412. }
  413. return value;
  414. }
  415. eleventyConfig.addFilter("random_date_ago", function (x, daysAgo = 100) {
  416. const today = new Date();
  417. const randomDaysAgo = randomNumber(x, 0, daysAgo);
  418. today.setDate(today.getDate() - randomDaysAgo);
  419. return today;
  420. });
  421. eleventyConfig.addFilter("random_date", function (x, startDate = null, endDate = null) {
  422. const start = startDate ? new Date(startDate).getTime() : Date.now() - 100 * 24 * 60 * 60 * 1000;
  423. const end = endDate ? new Date(endDate).getTime() : Date.now();
  424. const randomTimestamp = randomNumber(x, start, end);
  425. return new Date(randomTimestamp);
  426. });
  427. eleventyConfig.addFilter("random_item", function (x, items) {
  428. const index = randomNumber(x, 0, items.length - 1);
  429. return items[index];
  430. });
  431. eleventyConfig.addFilter("random_number", randomNumber);
  432. eleventyConfig.addFilter("first_letters", function capitalizeFirstLetter(string) {
  433. return string.split(' ').map(word => word.charAt(0)).join('');
  434. })
  435. eleventyConfig.addFilter("size", function (elem) {
  436. if (elem instanceof Object) {
  437. return Object.keys(elem).length;
  438. }
  439. return elem.length;
  440. })
  441. eleventyConfig.addFilter("first", function (elem) {
  442. if (elem instanceof Object) {
  443. return elem[Object.keys(elem)[0]];
  444. }
  445. return elem[0];
  446. })
  447. // time ago from today
  448. eleventyConfig.addFilter("timeago", function (date) {
  449. const seconds = Math.floor((new Date() - date) / 1000);
  450. let interval = Math.floor(seconds / 31536000);
  451. if (interval > 1) {
  452. return interval + " years ago";
  453. }
  454. interval = Math.floor(seconds / 2592000);
  455. if (interval > 1) {
  456. return interval + " months ago";
  457. }
  458. interval = Math.floor(seconds / 86400);
  459. if (interval > 1) {
  460. return interval + " days ago";
  461. }
  462. interval = Math.floor(seconds / 3600);
  463. if (interval > 1) {
  464. return interval + " hours ago";
  465. }
  466. interval = Math.floor(seconds / 60);
  467. if (interval > 1) {
  468. return interval + " minutes ago";
  469. }
  470. if (seconds > 0) {
  471. return Math.floor(seconds) + " seconds ago";
  472. }
  473. return "now";
  474. })
  475. /**
  476. * Shortcodes
  477. */
  478. const tags = ["capture_global", "endcapture_global", "highlight", "endhighlight"];
  479. tags.forEach(tag => {
  480. eleventyConfig.addLiquidTag(tag, function (liquidEngine) {
  481. return {
  482. parse: function (tagToken, remainingTokens) {
  483. this.str = tagToken.args;
  484. },
  485. render: function (scope, hash) {
  486. return "";
  487. },
  488. };
  489. });
  490. });
  491. /**
  492. * Transforms
  493. */
  494. function prettifyHTML(content, outputPath) {
  495. return outputPath.endsWith('.html')
  496. ? content
  497. .replace(/\/\/ @formatter:(on|off)\n+/gm, '')
  498. : content
  499. }
  500. eleventyConfig.addTransform('htmlformat', prettifyHTML)
  501. };