eleventy.config.mjs 11 KB

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