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
2.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":null,"metadata":{},"sourceType":"module"}