Skip to content

Latest commit

 

History

History
99 lines (75 loc) · 3.62 KB

README.md

File metadata and controls

99 lines (75 loc) · 3.62 KB

Leetscrape TS

This is simple Next.js template bootstrapped with create-next-app. Given .mdx files in the solutions directory, this renders each file, which is intended to contain solutions to a single Leetcode question, as a standalone webpage at SITE_URL/solutions/{question-slug}.

This is a companion template for the Leetscrape Python package. You may use that package to generate code stubs for non-premium Leetcode questions to develop locally and then generate .mdx files for use with this project.

Getting Started

Standalone usage

  1. First, bootstrap a Next.js app using create-next-app and this template:

    npx create-next-app -e https://www.github.com/nikhil-ravi/leetscrape-ts
  2. Then, install dependencies:

    npm install
    # or
    yarn
    # or
    pnpm install
    # or
    bun install
  3. Place your .mdx files in the solutions directory. The file's frontmatter should contain the following fields:

    ---
    qid: 1
    title: "Two Sum"
    titleSlug: "two-sum"
    difficulty: "Easy"
    tags: ["array", "hashmap"]
    ---

    The qid field is Leetcode's question ID. The title field is the title of the question. The titleSlug field is the URL slug for the question. The difficulty field is the difficulty of the question. The tags field is a list of topic tags for the question. All these fields can be found in the Leetcode question page.

  4. Populate an .env.local file using example .env.example file:

    NEXT_PUBLIC_SITE_URL=http://localhost:3000
    NEXT_PUBLIC_AUTHOR_NAME=Nikhil Ravi
    NEXT_PUBLIC_SITE_NAME=ScuffedCode
  5. Populate the external links that appear in the nav bar in the external-links.ts file:

    export default {
        github: "https://github.com/nikhil-ravi",
        linkedin: "https://www.linkedin.com/in/nikhil--ravi/",
        <!-- Add more links -->
    } as const;
  6. Then, run the development server:

    npm run dev
    # or
    yarn dev
    # or
    pnpm dev
    # or
    bun dev
  7. Open http://localhost:3000 with your browser to see the result.

Usage with Leetscrape

  1. First, install the Leetscrape Python package:

    pip install leetscrape
  2. Then, run the following command to generate a code stub for a Leetcode question. For example:

    leetscrape question -q 1

    This will generate a file named q_0001_twoSum.py in the current directory. See the Leetscrape repository for more options.

  3. Edit the generated file to add your solution.

  4. Then, run the following command to generate a .mdx file for the question:

    leetscrape solution -i q_0001_twoSum.py -o <path-to-leetcode-ts-project>/src/content/solutions

    This will generate a file named q_0001_twoSum.mdx in the solutions directory. See the Leetscrape repository for more options.

    Alternatively, you can pass the directory path containing your solutions to generate .mdx files for all the solutions in that directory:

    leetscrape solution -i <path-to-solutions-directory> -o <path-to-leetcode-ts-project>/src/content/solutions