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.
-
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
-
Then, install dependencies:
npm install # or yarn # or pnpm install # or bun install
-
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. Thetitle
field is the title of the question. ThetitleSlug
field is the URL slug for the question. Thedifficulty
field is the difficulty of the question. Thetags
field is a list of topic tags for the question. All these fields can be found in the Leetcode question page. -
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
-
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;
-
Then, run the development server:
npm run dev # or yarn dev # or pnpm dev # or bun dev
-
Open http://localhost:3000 with your browser to see the result.
-
First, install the Leetscrape Python package:
pip install leetscrape
-
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. -
Edit the generated file to add your solution.
-
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