eleventy.config.mjs 13 KB

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