ByteGrad / Professional-React-and-Next.js-Course

This repo contains everything you need as a student of the Professional React & Next.js Course by ByteGrad.com
https://bytegrad.com/courses/professional-react-nextjs
145 stars 71 forks source link

Project Evento: Seed file with 6 popular cities and dynamic image URL (generated using Chat GPT) #9

Open Dev-Dipesh opened 6 months ago

Dev-Dipesh commented 6 months ago

Seed File: seed.ts

Cities Included

7 events are added for each new city.

  1. Austin
  2. London
  3. Los Angeles
  4. New York
  5. Paris
  6. San Francisco
  7. Seattle
  8. Tokyo

The dynamic image URL is created based on the following format:

`https://source.unsplash.com/random/900x700/?${slug}`

Don't forget to add the external URL in the next.config.js

{
    protocol: "https",
    hostname: "source.unsplash.com",
    port: "",
    pathname: "/**",
},

Additional helpful utilities:

This function is used to decode the URI component. For example, if the city is "Los%20Angeles", it will be decoded to "Los Angeles".

export function decodeURIComp(s: string): string {
  return decodeURIComponent(s);
}

This function is used to capitalize the first letter of each word in a string. For example, if the input is "new york", the output will be "New York".

export function capitalize(s: string): string {
  return s.replace(/(^\w{1})|(\s+\w{1})/g, (letter) => letter.toUpperCase());
}

Can be called as follows:

const cityName = capitalize(decodeURIComp(params.city));
ByteGrad commented 6 months ago

Looks good on first sight Dipesh, thanks! Will have to take a look at it again later