Second frontend, written in Next.JS + Typescript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1 lines
6.9 KiB

{"ast":null,"code":"function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }\n\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\nimport fs from \"fs\";\nimport path from \"path\";\nimport matter from \"gray-matter\";\nimport remark from \"remark\";\nimport html from \"remark-html\";\nconst postsDirectory = path.join(process.cwd(), \"posts\");\nexport function getSortedPostsData() {\n // Get file names under /posts\n const fileNames = fs.readdirSync(postsDirectory);\n const allPostsData = fileNames.map(fileName => {\n // Remove \".md\" from file name to get id\n const id = fileName.replace(/\\.md$/, \"\"); // Read markdown file as string\n\n const fullPath = path.join(postsDirectory, fileName);\n const fileContents = fs.readFileSync(fullPath, \"utf8\"); // Use gray-matter to parse the post metadata section\n\n const matterResult = matter(fileContents); // Combine the data with the id\n\n return _objectSpread({\n id\n }, matterResult.data);\n }); // Sort posts by date\n\n return allPostsData.sort((a, b) => {\n if (a.date < b.date) {\n return 1;\n } else {\n return -1;\n }\n });\n}\nexport function getAllPostIds() {\n const fileNames = fs.readdirSync(postsDirectory);\n return fileNames.map(fileName => {\n return {\n params: {\n id: fileName.replace(/\\.md$/, \"\")\n }\n };\n });\n}\nexport async function getPostData(id) {\n const fullPath = path.join(postsDirectory, `${id}.md`);\n const fileContents = fs.readFileSync(fullPath, \"utf8\"); // Use gray-matter to parse the post metadata section\n\n const matterResult = matter(fileContents); // Use remark to convert markdown into HTML string\n\n const processedContent = await remark().use(html).process(matterResult.content);\n const contentHtml = processedContent.toString(); // Combine the data with the id and contentHtml\n\n return _objectSpread({\n id,\n contentHtml\n }, matterResult.data);\n}","map":{"version":3,"sources":["/data/projects/react/rpdata-frontend2/lib/posts.ts"],"names":["fs","path","matter","remark","html","postsDirectory","join","process","cwd","getSortedPostsData","fileNames","readdirSync","allPostsData","map","fileName","id","replace","fullPath","fileContents","readFileSync","matterResult","data","sort","a","b","date","getAllPostIds","params","getPostData","processedContent","use","content","contentHtml","toString"],"mappings":";;;;;;AAAA,OAAOA,EAAP,MAAe,IAAf;AACA,OAAOC,IAAP,MAAiB,MAAjB;AACA,OAAOC,MAAP,MAAmB,aAAnB;AACA,OAAOC,MAAP,MAAmB,QAAnB;AACA,OAAOC,IAAP,MAAiB,aAAjB;AAEA,MAAMC,cAAc,GAAGJ,IAAI,CAACK,IAAL,CAAUC,OAAO,CAACC,GAAR,EAAV,EAAyB,OAAzB,CAAvB;AAEA,OAAO,SAASC,kBAAT,GAA8B;AACnC;AACA,QAAMC,SAAS,GAAGV,EAAE,CAACW,WAAH,CAAeN,cAAf,CAAlB;AACA,QAAMO,YAAY,GAAGF,SAAS,CAACG,GAAV,CAAcC,QAAQ,IAAI;AAC7C;AACA,UAAMC,EAAE,GAAGD,QAAQ,CAACE,OAAT,CAAiB,OAAjB,EAA0B,EAA1B,CAAX,CAF6C,CAI7C;;AACA,UAAMC,QAAQ,GAAGhB,IAAI,CAACK,IAAL,CAAUD,cAAV,EAA0BS,QAA1B,CAAjB;AACA,UAAMI,YAAY,GAAGlB,EAAE,CAACmB,YAAH,CAAgBF,QAAhB,EAA0B,MAA1B,CAAr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KAGMZ,YAAY,CAACC,IAHnB;AAKD","sourcesContent":["import fs from \"fs\"\nimport path from \"path\"\nimport matter from \"gray-matter\"\nimport remark from \"remark\"\nimport html from \"remark-html\"\n\nconst postsDirectory = path.join(process.cwd(), \"posts\")\n\nexport function getSortedPostsData() {\n // Get file names under /posts\n const fileNames = fs.readdirSync(postsDirectory)\n const allPostsData = fileNames.map(fileName => {\n // Remove \".md\" from file name to get id\n const id = fileName.replace(/\\.md$/, \"\")\n\n // Read markdown file as string\n const fullPath = path.join(postsDirectory, fileName)\n const fileContents = fs.readFileSync(fullPath, \"utf8\")\n\n // Use gray-matter to parse the post metadata section\n const matterResult = matter(fileContents)\n\n // Combine the data with the id\n return {\n id,\n ...(matterResult.data as { date: string; title: string })\n }\n })\n // Sort posts by date\n return allPostsData.sort((a, b) => {\n if (a.date < b.date) {\n return 1\n } else {\n return -1\n }\n })\n}\n\nexport function getAllPostIds() {\n const fileNames = fs.readdirSync(postsDirectory)\n return fileNames.map(fileName => {\n return {\n params: {\n id: fileName.replace(/\\.md$/, \"\")\n }\n }\n })\n}\n\nexport async function getPostData(id: string) {\n const fullPath = path.join(postsDirectory, `${id}.md`)\n const fileContents = fs.readFileSync(fullPath, \"utf8\")\n\n // Use gray-matter to parse the post metadata section\n const matterResult = matter(fileContents)\n\n // Use remark to convert markdown into HTML string\n const processedContent = await remark()\n .use(html)\n .process(matterResult.content)\n const contentHtml = processedContent.toString()\n\n // Combine the data with the id and contentHtml\n return {\n id,\n contentHtml,\n ...(matterResult.data as { date: string; title: string })\n }\n}"]},"metadata":{},"sourceType":"module"}