quotes-nextjs

My favourite quotes. (nextjs)
git clone http://git.hanabi.in/repos/quotes-nextjs.git
Log | Files | Refs | LICENSE

index.js (1461B)


      1 import CommonHead from "../../components/CommonHead.js";
      2 import Footer from "../../components/Footer.js";
      3 import Header from "../../components/Header.js";
      4 import HeadTitle from "../../components/HeadTitle.js";
      5 import WordCloud from "../../components/WordCloud.js";
      6 
      7 function Authors({ authors }) {
      8   return (
      9     <div className="site">
     10       <CommonHead />
     11       <HeadTitle title="Authors" ogtitle="Authors" />
     12       <Header pageTitle={`Authors (${authors.length})`} />
     13       <WordCloud arr={authors} prefix="authors" />
     14       <Footer />
     15     </div>
     16   );
     17 }
     18 
     19 export async function getStaticProps() {
     20   const { readdir } = require("fs/promises");
     21   const { join } = require("path");
     22 
     23   const {
     24     errHandler,
     25     getDetailsANDQuotes,
     26     readFrontMatter,
     27   } = require("../../helperFns.js");
     28 
     29   try {
     30     const allAuthors = await readdir("quotes");
     31 
     32     const authors = [];
     33     for (const author of allAuthors) {
     34       const allFiles = await readdir(join("quotes", author));
     35       const { quotes } = getDetailsANDQuotes(allFiles);
     36 
     37       let count = 0;
     38       for (const quote of quotes) {
     39         const {
     40           data: { draft },
     41         } = await readFrontMatter(author, quote);
     42         if (draft) continue;
     43         count++;
     44       }
     45       if (count) authors.push({ name: author, count });
     46     }
     47 
     48     authors.sort((a, b) => a.name.localeCompare(b.name));
     49 
     50     return { props: { authors } };
     51   } catch (err) {
     52     errHandler(err);
     53   }
     54 }
     55 
     56 export default Authors;