{"ast":null,"code":"import fs from \"fs\";\nimport { join } from \"path\";\nimport hljs from \"highlight.js\";\nconst POSTS_DIRECTORY = join(process.cwd(), \"sigma/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  };\n}\n/**\n * Returns the list of all posts.\n */\n\nexport function getExamples() {\n  return fs.readdirSync(POSTS_DIRECTORY, {\n    withFileTypes: true\n  }).filter(dirent => dirent.isFile()).map(dirent => getExample(join(POSTS_DIRECTORY, dirent.name)));\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/sigmajs.org/lib/examples-api.ts"],"names":["fs","join","hljs","POSTS_DIRECTORY","process","cwd","getExample","path","slug","match","rawFileContent","readFileSync","name","codeRaw","codeHTML","highlightAuto","value","codePath","htmlPath","getExamples","readdirSync","withFileTypes","filter","dirent","isFile","map","getExampleParams","example","findExample","examples","find"],"mappings":"AAAA,OAAOA,EAAP,MAAe,IAAf;AACA,SAASC,IAAT,QAAqB,MAArB;AACA,OAAOC,IAAP,MAAiB,cAAjB;AAIA,MAAMC,eAAe,GAAGF,IAAI,CAACG,OAAO,CAACC,GAAR,EAAD,EAAgB,gBAAhB,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,GAAGV,EAAE,CAACW,YAAH,CAAgBJ,IAAhB,EAAsB,MAAtB,CAAvB;AAEA,SAAO;AACLK,IAAAA,IAAI,EAAEJ,IADD;AAELK,IAAAA,OAAO,EAAEH,cAFJ;AAGLI,IAAAA,QAAQ,EAAEZ,IAAI,CAACa,aAAL,CAAmBL,cAAnB,EAAmCM,KAHxC;AAILC,IAAAA,QAAQ,EAAEV,IAJL;AAKLW,IAAAA,QAAQ,EAAEX;AALL,GAAP;AAOD;AAED;AACA;AACA;;AACA,OAAO,SAASY,WAAT,GAAkC;AACvC,SAAOnB,EAAE,CACNoB,WADI,CACQjB,eADR,EACyB;AAAEkB,IAAAA,aAAa,EAAE;AAAjB,GADzB,EAEJC,MAFI,CAEGC,MAAM,IAAIA,MAAM,CAACC,MAAP,EAFb,EAGJC,GAHI,CAGCF,MAAD,IAAYjB,UAAU,CAACL,IAAI,CAACE,eAAD,EAAkBoB,MAAM,CAACX,IAAzB,CAAL,CAHtB,CAAP;AAID;AAED;AACA;AACA;;AACA,OAAO,SAASc,gBAAT,CAA0BC,OAA1B,EAA4C;AACjD,SAAO;AACLA,IAAAA,OAAO,EAAEA,OAAO,CAACf;AADZ,GAAP;AAGD;AAED;AACA;AACA;;AACA,OAAO,SAASgB,WAAT,CAAqBhB,IAArB,EAAwD;AAC7D,QAAMiB,QAAQ,GAAGV,WAAW,EAA5B;AAEA,SAAOU,QAAQ,CAACC,IAAT,CAAeH,OAAD,IAAaA,OAAO,CAACf,IAAR,KAAiBA,IAA5C,CAAP;AACD","sourcesContent":["import fs from \"fs\";\nimport { join } from \"path\";\nimport hljs from \"highlight.js\";\n\nimport { Example } from \"./types\";\n\nconst POSTS_DIRECTORY = join(process.cwd(), \"sigma/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  };\n}\n\n/**\n * Returns the list of all posts.\n */\nexport function getExamples(): Example[] {\n  return fs\n    .readdirSync(POSTS_DIRECTORY, { withFileTypes: true })\n    .filter(dirent => dirent.isFile())\n    .map((dirent) => getExample(join(POSTS_DIRECTORY, dirent.name)));\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"}