{"ast":null,"code":"import fs from \"fs\";\nimport { join } from \"path\";\nimport hljs from \"highlight.js\";\nimport examples from \"../../examples/.examples.json\";\nconst POSTS_DIRECTORY = join(process.cwd(), \"../examples\");\n/**\n * Returns a cleaned ExampleType object from a full path.\n */\n\nexport function getExample(path) {\n  const slug = (path.match(/([^\\/\\.]+)(\\.[^\\.\\/]+)?$/) || [])[1];\n  const rawFileContent = fs.readFileSync(path, \"utf8\");\n  return {\n    name: slug,\n    codeRaw: rawFileContent,\n    codeHTML: hljs.highlightAuto(rawFileContent).value,\n    codePath: path,\n    htmlPath: path,\n    iframePath: `/demos/${slug}.html`\n  };\n}\n/**\n * Returns the list of all posts.\n */\n\nexport function getExamples() {\n  return Object.values(examples).map(example => getExample(join(POSTS_DIRECTORY, example.id + \".ts\")));\n}\n/**\n * Returns for a example the params required to build its permalink.\n */\n\nexport function getExampleParams(example) {\n  return {\n    example: example.name\n  };\n}\n/**\n * Finds and returns the example for a given name.\n */\n\nexport function findExample(name) {\n  const examples = getExamples();\n  return examples.find(example => example.name === name);\n}","map":{"version":3,"sources":["/home/alexis/code/sigma/website/lib/examples-api.ts"],"names":["fs","join","hljs","examples","POSTS_DIRECTORY","process","cwd","getExample","path","slug","match","rawFileContent","readFileSync","name","codeRaw","codeHTML","highlightAuto","value","codePath","htmlPath","iframePath","getExamples","Object","values","map","example","id","getExampleParams","findExample","find"],"mappings":"AAAA,OAAOA,EAAP,MAAe,IAAf;AACA,SAASC,IAAT,QAAqB,MAArB;AACA,OAAOC,IAAP,MAAiB,cAAjB;AAGA,OAAOC,QAAP,MAAqB,+BAArB;AAEA,MAAMC,eAAe,GAAGH,IAAI,CAACI,OAAO,CAACC,GAAR,EAAD,EAAgB,aAAhB,CAA5B;AAEA;AACA;AACA;;AACA,OAAO,SAASC,UAAT,CAAoBC,IAApB,EAA2C;AAChD,QAAMC,IAAI,GAAG,CAACD,IAAI,CAACE,KAAL,CAAW,0BAAX,KAA0C,EAA3C,EAA+C,CAA/C,CAAb;AACA,QAAMC,cAAc,GAAGX,EAAE,CAACY,YAAH,CAAgBJ,IAAhB,EAAsB,MAAtB,CAAvB;AAEA,SAAO;AACLK,IAAAA,IAAI,EAAEJ,IADD;AAELK,IAAAA,OAAO,EAAEH,cAFJ;AAGLI,IAAAA,QAAQ,EAAEb,IAAI,CAACc,aAAL,CAAmBL,cAAnB,EAAmCM,KAHxC;AAILC,IAAAA,QAAQ,EAAEV,IAJL;AAKLW,IAAAA,QAAQ,EAAEX,IALL;AAMLY,IAAAA,UAAU,EAAG,UAASX,IAAK;AANtB,GAAP;AAQD;AAED;AACA;AACA;;AACA,OAAO,SAASY,WAAT,GAAkC;AACvC,SAAOC,MAAM,CAACC,MAAP,CAA6CpB,QAA7C,EAAuDqB,GAAvD,CAA4DC,OAAD,IAChElB,UAAU,CAACN,IAAI,CAACG,eAAD,EAAkBqB,OAAO,CAACC,EAAR,GAAa,KAA/B,CAAL,CADL,CAAP;AAGD;AAED;AACA;AACA;;AACA,OAAO,SAASC,gBAAT,CAA0BF,OAA1B,EAA4C;AACjD,SAAO;AACLA,IAAAA,OAAO,EAAEA,OAAO,CAACZ;AADZ,GAAP;AAGD;AAED;AACA;AACA;;AACA,OAAO,SAASe,WAAT,CAAqBf,IAArB,EAAwD;AAC7D,QAAMV,QAAQ,GAAGkB,WAAW,EAA5B;AAEA,SAAOlB,QAAQ,CAAC0B,IAAT,CAAeJ,OAAD,IAAaA,OAAO,CAACZ,IAAR,KAAiBA,IAA5C,CAAP;AACD","sourcesContent":["import fs from \"fs\";\nimport { join } from \"path\";\nimport hljs from \"highlight.js\";\n\nimport { Example } from \"./types\";\nimport examples from \"../../examples/.examples.json\";\n\nconst POSTS_DIRECTORY = join(process.cwd(), \"../examples\");\n\n/**\n * Returns a cleaned ExampleType object from a full path.\n */\nexport function getExample(path: string): Example {\n  const slug = (path.match(/([^\\/\\.]+)(\\.[^\\.\\/]+)?$/) || [])[1] as string;\n  const rawFileContent = fs.readFileSync(path, \"utf8\");\n\n  return {\n    name: slug,\n    codeRaw: rawFileContent,\n    codeHTML: hljs.highlightAuto(rawFileContent).value,\n    codePath: path,\n    htmlPath: path,\n    iframePath: `/demos/${slug}.html`,\n  };\n}\n\n/**\n * Returns the list of all posts.\n */\nexport function getExamples(): Example[] {\n  return Object.values<{ id: string; title: string }>(examples).map((example) =>\n    getExample(join(POSTS_DIRECTORY, example.id + \".ts\")),\n  );\n}\n\n/**\n * Returns for a example the params required to build its permalink.\n */\nexport function getExampleParams(example: Example) {\n  return {\n    example: example.name,\n  };\n}\n\n/**\n * Finds and returns the example for a given name.\n */\nexport function findExample(name: string): Example | undefined {\n  const examples = getExamples();\n\n  return examples.find((example) => example.name === name);\n}\n"]},"metadata":{},"sourceType":"module"}