Skip to content

Commit cd49b7a

Browse files
authored
Merge pull request #54 from healeycodes/type-fixes
add package manager post
2 parents ec3521e + 0c00671 commit cd49b7a

File tree

12 files changed

+339
-13
lines changed

12 files changed

+339
-13
lines changed

components/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default function Layout({ children, title, description }) {
4747
:root {
4848
--text: #1d1d27;
4949
--input-background: #fff;
50-
--link: #0265d5;
50+
--link: #1772ea;
5151
--link-hover: #496495;
5252
--light-text: #73738b;
5353
--border: #b6b6c2;

components/postList.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Link from "next/link";
22
import Date_ from "./date";
33
import { postStars } from '../data/posts'
44
import siteConfig from '../siteConfig.json'
5+
import { ReactElement } from "react";
56

67
const PostStar = <>
78
<span className="star-container" title="star">*</span>
@@ -24,7 +25,7 @@ const PostStar = <>
2425
`}</style>
2526
</>
2627

27-
export default function PostList({ posts, showYears=false }) {
28+
export default function PostList({ posts, showYears = false }) {
2829
const years: Record<number, any> = {};
2930
posts.forEach(post => {
3031
const postDate = new Date(post.date);
@@ -36,7 +37,7 @@ export default function PostList({ posts, showYears=false }) {
3637
});
3738

3839
if (showYears) {
39-
const ret = [];
40+
const ret: ReactElement[] = []
4041
Object.keys(years)
4142
.sort((a, z) => parseInt(z) - parseInt(a))
4243
.forEach((year, i) => {

components/visuals/mazes/components.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async function wilsonsAlgorithm(maze: Maze, ctx: CanvasRenderingContext2D, cance
7272

7373
// Continue until all cells have been visited
7474
while (unvisited.size > 0) {
75-
let path = [];
75+
let path: Cell[] = [];
7676
let current = randomMember(unvisited);
7777

7878
// Perform a random walk until reaching a cell already in the maze
@@ -238,15 +238,15 @@ export const IntroMaze = () => {
238238
renderMaze(maze, null, [], mazeCtx)
239239
renderDebug(maze, null, [], debugCtx)
240240
await sleep(1000);
241-
a.carveEdge(b)
241+
if (a && b) a.carveEdge(b)
242242
renderMaze(maze, b, [], mazeCtx)
243243
renderDebug(maze, null, [], debugCtx)
244244
await sleep(1000);
245-
b.carveEdge(c)
245+
if (b && c) b.carveEdge(c)
246246
renderMaze(maze, c, [], mazeCtx)
247247
renderDebug(maze, null, [], debugCtx)
248248
await sleep(1000);
249-
c.carveEdge(d)
249+
if (c && d) c.carveEdge(d)
250250
renderMaze(maze, d, [], mazeCtx)
251251
renderDebug(maze, null, [], debugCtx)
252252
await sleep(1000);

components/visuals/mazes/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ async function bfsFurthestCell(
6262
await new Promise((r) => setTimeout(r, stepTime));
6363
}
6464

65-
const { cell, dist } = queue.shift();
65+
const item = queue.shift();
66+
let cell;
67+
let dist;
68+
if (item) {
69+
cell = item.cell
70+
dist = item.dist
71+
}
72+
6673
if (dist > maxDist) {
6774
maxDist = dist;
6875
furthestCell = cell;

components/visuals/mazes/maze.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ export function solveMazeWithRandomDPS(maze: Maze) {
8080
visited.add(`${x},${y}`);
8181

8282
const current = maze.getCell(x, y);
83+
if (!current) {
84+
return
85+
}
86+
8387
current.carveEdge(last);
8488

8589
const neighbors: Cell[] = shuffle(current.uncarvedEdges());

components/visuals/mazes/render.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export function renderMaze(
178178

179179
export function renderBFSOverlay(
180180
maze: Maze,
181-
visited: Set<Cell>,
181+
visited: Set<Cell | null>,
182182
ctx: CanvasRenderingContext2D,
183183
) {
184184
const canvas = ctx.canvas;
@@ -196,7 +196,7 @@ export function renderBFSOverlay(
196196
for (let x = 0; x < width; x++) {
197197
const cell = maze.getCell(x, y);
198198

199-
if (visited.has(cell)) {
199+
if (visited.has(cell) && cell) {
200200
const centerX = x * cellSize + cellSize / 2;
201201
const centerY = y * cellSize + cellSize / 2;
202202

@@ -226,7 +226,7 @@ export function renderBFSOverlay(
226226

227227
export async function renderDebug(
228228
maze: Maze,
229-
currentCell: Cell,
229+
currentCell: Cell | null,
230230
currentPath: Cell[],
231231
ctx: CanvasRenderingContext2D,
232232
) {

data/posts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const popularPosts = [
77

88
// Starred posts (not in any specific order)
99
export const postStars = [
10+
"installing-npm-packages-very-quickly",
1011
"compiling-lisp-to-bytecode-and-running-it",
1112
"making-python-less-random",
1213
"lisp-compiler-optimizations",

data/projects.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ export default [
3232
desc: "A server-side web framework that deploys to Vercel.",
3333
to: "/my-own-python-web-framework",
3434
},
35+
{
36+
name: "caladan",
37+
link: "https://github.com/healeycodes/caladan",
38+
desc: "Experimental npm package manager. Installs from lockfile and runs bin scripts.",
39+
to: "/installing-npm-packages-very-quickly",
40+
},
3541
{
3642
name: "untrusted-python",
3743
link: "https://github.com/healeycodes/untrusted-python",

next-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference types="next/navigation-types/compat/navigation" />
34

45
// NOTE: This file should not be edited
56
// see https://nextjs.org/docs/basic-features/typescript for more information.

pages/[id].tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,30 @@ export async function getStaticProps({ params }) {
6969
let prevPost = null;
7070
let nextPost = null;
7171
const nextAndPrevPosts = getNextAndPrevPosts(params.id);
72+
// @ts-ignore
7273
if (nextAndPrevPosts.previous !== null) {
74+
// @ts-ignore
7375
prevPost = {
76+
// @ts-ignore
7477
id: nextAndPrevPosts.previous,
78+
// @ts-ignore
7579
...getPostData(nextAndPrevPosts.previous),
7680
};
7781
}
82+
// @ts-ignore
7883
if (nextAndPrevPosts.next !== null) {
84+
// @ts-ignore
7985
nextPost = {
86+
// @ts-ignore
8087
id: nextAndPrevPosts.next,
88+
// @ts-ignore
8189
...getPostData(nextAndPrevPosts.next),
8290
};
8391
}
8492

8593
return {
8694
props: {
95+
// @ts-ignore
8796
id: params.id,
8897
source: postData.content,
8998
imageMetadata,

0 commit comments

Comments
 (0)