quotes-nextjs

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

[quote].js (2398B)


      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 function Quote({ author, cover, data, HTMLStr }) {
      8   const { attributed, lang, misattributed, tags, title, unverified } = data;
      9   return (
     10     <div className="site">
     11       <CommonHead cover={cover} />
     12       <Header noTitle={true} />
     13       <HeadTitle title={title} ogtitle={title} />
     14       <QuoteBody
     15         HTMLStr={HTMLStr}
     16         author={author}
     17         attributed={attributed}
     18         lang={lang}
     19         misattributed={misattributed}
     20         unverified={unverified}
     21         tags={tags}
     22       />
     23       <Footer />
     24     </div>
     25   );
     26 }
     27 
     28 export async function getStaticPaths() {
     29   const { readdir } = require("fs/promises");
     30   const { join } = require("path");
     31 
     32   const {
     33     errHandler,
     34     getDetailsANDQuotes,
     35     makeUri,
     36     readFrontMatter,
     37   } = require("../../../helperFns.js");
     38 
     39   let paths = [];
     40   try {
     41     const authors = await readdir("quotes");
     42     for (const author of authors) {
     43       const allFiles = await readdir(join("quotes", author));
     44       const { quotes } = getDetailsANDQuotes(allFiles);
     45       if (quotes.length < 1) throw new Error(`Not enough quotes`);
     46 
     47       for (const quote of quotes) {
     48         const { data } = await readFrontMatter(author, quote);
     49         const { draft } = data;
     50         if (draft) continue;
     51 
     52         const uri = makeUri(quote);
     53         paths.push({ params: { author, quote: uri } });
     54       }
     55     }
     56     return {
     57       paths,
     58       fallback: false,
     59     };
     60   } catch (err) {
     61     errHandler(err);
     62   }
     63 }
     64 
     65 export async function getStaticProps({ params: { author, quote } }) {
     66   const remark = require("remark");
     67   const html = require("remark-html");
     68 
     69   const {
     70     errHandler,
     71     getCover,
     72     readFrontMatter,
     73   } = require("../../../helperFns.js");
     74   try {
     75     const cover = await getCover(author);
     76     const quoteFile = quote + ".md";
     77     const { content, data } = await readFrontMatter(author, quoteFile);
     78 
     79     let HTMLStr;
     80     remark()
     81       .use(html)
     82       .process(content, function (err, file) {
     83         HTMLStr = String(file);
     84       });
     85 
     86     return { props: { author, cover, data, HTMLStr } };
     87   } catch (err) {
     88     errHandler(err);
     89   }
     90 }
     91 
     92 export default Quote;