quotes-nextjs

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

random.js (1779B)


      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 QuoteBody from "../components/QuoteBody.js";
      6 
      7 import { site } from "../config.js";
      8 
      9 function Random({ author, cover, data, HTMLStr }) {
     10   const { attributed, lang, misattributed, tags, title, unverified } = data;
     11   return (
     12     <div className="site">
     13       <CommonHead cover={cover} />
     14       <Header noTitle={true} />
     15       <HeadTitle title={title} ogtitle={title} />
     16       <QuoteBody
     17         HTMLStr={HTMLStr}
     18         author={author}
     19         attributed={attributed}
     20         lang={lang}
     21         misattributed={misattributed}
     22         unverified={unverified}
     23         tags={tags}
     24       />
     25       <Footer />
     26     </div>
     27   );
     28 }
     29 
     30 export async function getServerSideProps() {
     31   const { readdir } = require("fs/promises");
     32   const { join } = require("path");
     33 
     34   const remark = require("remark");
     35   const html = require("remark-html");
     36 
     37   const {
     38     createQuoteObj,
     39     errHandler,
     40     getCover,
     41     getDetailsANDQuotes,
     42     readFrontMatter,
     43     shuffleAndGiveRandom,
     44   } = require("../helperFns.js");
     45 
     46   try {
     47     const quotesANDauthors = require("../random-quotes.js");
     48     const randomQuote = shuffleAndGiveRandom(quotesANDauthors);
     49 
     50     const { author, uri } = randomQuote;
     51     const mdFile = uri + ".md";
     52     const cover = await getCover(author);
     53     const { content, data } = await readFrontMatter(author, mdFile);
     54 
     55     let HTMLStr;
     56     remark()
     57       .use(html)
     58       .process(content, function (err, file) {
     59         HTMLStr = String(file);
     60       });
     61 
     62     return { props: { author, cover, data, HTMLStr } };
     63   } catch (err) {
     64     errHandler(err);
     65   }
     66 }
     67 
     68 export default Random;