Skip to content

benson00077/tlog-front

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

78 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“” Table of Contents

1. ๐Ÿ‘‰ About the porject

My personal blog for front-end SPA leveraging Next.js's SSG feature.

1.1. Build with

1.1.1. Tech Stack

TypeScript React Styled Component GraphQL MongoDB

1.1.2. Features

1.1.2.1. Parallel struture on paragraph (when viewpoint with > 1440px)

  • Plain text v.s. code syntax block (#codeBlock or .columnRight)
  • Native Language v.s. Foreign Language (#foreignLanguageBlock or .languageRight)

1.1.2.2. Heading thread line style

  • Support browser: Notice that the css for Subtitle theard line only works for browsers supporting :has() selector(Only Chrome^105 and Safari support)
  • Support heading: Only work for heading 2 and heading 3 in fron-end intendedly. Any heading 1 in blog post content could slightly break UI, which is why we convert heading 1 in markdown db into heading 2 as per previos chapter explains.

(back to top)

2. ๐Ÿ‘‰ Getting Started

2.1. Prerequisites

Node version v14.17.0

2.2. Installation

  1. Clone the repo

    git clone https://github.com/benson00077/tlog-front
  2. Install NPM packages

    npm install
  3. Set up .env

     # /.env.local
     #   connect to backend api listening on port 3001
     NEXT_PUBLIC_API_URL_DEV=http://localhost:3001/graphql
     NEXT_PUBLIC_API_URL_PRO=https://<myDomain>/graphql
  4. Be aware of that mongo db have different URI format by version. The backend logic this porject connect to uses the second one.

    # 1. mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
    # 2. mongodb+srv://[username:password@]host[/[database][?options]]

2.3. Deployment / Hosting

  • Use pm2 to manamge muiltiple node apps.
    $ npm run build # as docs suggested
    $ pm2 start npm --name <myAppServerName> -- start
  • P.S. Building as docs' suggest is a bit weird though. See this Q&A.

2.4. Lint

  • Using Conventional Commits.
    • Set up following conventional-changelog. Include .husky/commit-msg.
    • See convention here
    • try locally echo "foo: dummy commit msg" | ./node_modules/.bin/commitlint

(back to top)

3. ๐Ÿ‘‰ Usage

3.1. Patterns to follow for parallel struture in Blog post data

Foreign language in db is stored like what you do in makrdown codeblock but adding a hint text language-foreign, like bellow:

Hello, this paragraph is parallel w/ the below text

```language-foreign
ไฝ ๅฅฝ๏ผŒ้€™ๆฎตๆ–‡ๅญ—ๅธŒๆœ›ๅฏไปฅ่ทŸไธŠ้ข็š„ๆ–‡ๅญ—ไธฆๅˆ—(viewpiont width > 1440px)ใ€‚้€™ๅœจๅ‰็ซฏๆธฒๆŸ“ๆ™‚ html ๆœ€็ต‚ๆœƒ่ฎŠๆˆ <p> ่€Œไธๆ˜ฏ <pre> ๅ…ง็š„ <code>
```

</br> is what you want if you want to break row in a same paragraph in db. In other words, break rows by 'enter' would create a new paragraph in final html. </br> is what you want to keep parallel feature in same paragraph. Example as below only paragaprh <2> and <4> would be parallel w/ each other :

<1> This paragraph would NOT parallel
<2> This paragraph would parallel w/ below block</br> <3> And this snippet as well !

```language-foreign
<4> ้€™ๆฎตๅญ˜ๅœจ DB ็š„ๆ–‡ๅญ—๏ผŒๅธŒๆœ›ๆœ€็ต‚ๅ‘ˆ็พๅœจ UI ไธŠๅฏไปฅ่ทŸไธŠ้ข็š„ๆ–‡ๅญ—ไธฆๅˆ—ใ€‚
```

3.2. Patterns to follor for better heading in blog post detail pages

  • Start your markdown files from heading 1.
  • Don't use heading 6.
  • Do NOT skip heading number. Make sure keep heading tags in ascending order, esspecially h1 , h2 in markdown file / db.

3.3. Heading 1 be converted to 2 automatically in front-end

  • Only the title of blog post would be rendered as heading 1 in front-end, regarding that multiple HTML h1 tag is bad for SEO.

    # 3. ๐Ÿ˜ข Heading 1 in db
    
    ## 3.1. ๐Ÿ˜Š be converted to Heading 2 in front-end
    ### 3.1.1. ๐Ÿ˜Š Heading 2 > Heading 3, and so on
    

    (back to top)

3.4 About blckquote / quote

  • Use following two type of quote in markdown
        1. quote starts w/ two tabs 
    
        > 2. quote starts with symbol '>'
        >> 3. quote inside quote
    
  • They are redered as below
    <div class="quote">
      <pre> <code> 1. quote starts w/ two tabs <code> </pre>
    </div>
    
    <blockquote>
      <p> 2. quote starts with symbol '>' </p>
      <blockquote>
        <p> 3. quote inside quote </p>
      </blockquote>  
    </blockquote>

4. ๐Ÿ‘‰ Roadmap

  • Implement better Post List page
  • Archive page
  • About me page
  • Optimize loading animation. Consider using React Spring with next router obj see me. Or Framer Motion.
  • Set mermaid diagrams as remarkPlugins. see me
  • Collect the TODOs scatterd around this project
  • Highlight line in code block

(back to top)

5. ๐Ÿ‘‰ Acknowledgments

5.1. Dev Note

  • Debounce and Throttle. see BackToTopBtn.tsx
  • SSR styled components - w/ babel-plugin-styled-components stackoverflow
  • scrollTop w/ requestAnimationFrame

5.2. Problem (Pending): slow dev exp using getStaticProps with { fallback: true }

5.3. Problem (Solved): SSR w/ Apollo cache

5.3.1. Reference:

  • here describe the problem and logic duplication between getServerSideProps and useQuery
  • here is the discusstions thread
  • here is the solution provided in that thread

5.3.2. Problem

  • What if I use getServerSideProps with useQuery() ?
    • The client is a different instance because there are TWO clients - one one server, that get's reinstated on every request and one on client, that gets hydrated with the data you send yourself in getServerSideProps. If you did not do it, you would refetch all the data on the client again, as the client cache wouldn't be populated.
  • P.S. What about the ssrMode option in apollo docs ? Here referring a solution use next-with-apollo package.

5.4. Solution

5.4.1. SSR

Has the flag method getServerSideProps that lets the lib know you want that specific page to be server-side rendered whilst providing the page component with the data (prefilled in its props argument)

5.4.2. Apollo

Has that special method called getDataFromTree that finds in your page tree all components that use the hook useQuery. They then execute all queries at once to allow you to send your page prefilled with data to the browser.

My decision

see comments in code apollo.ts

(back to top)

About

Front-end for personal blog

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages