Skip to content

Commit 356e7c2

Browse files
committed
Add new note category for glossary
1 parent 4d40392 commit 356e7c2

File tree

12 files changed

+134
-39
lines changed

12 files changed

+134
-39
lines changed

app/(subpages)/notes/[category]/category.module.css

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,22 @@
99
gap: 1.5rem;
1010
}
1111

12-
.noteList > a {
12+
.noteList > a, .glossaryList > a {
1313
border: 2px solid var(--gray);
1414
padding: 1rem;
1515
background-color: var(--bg-2);
1616
color: var(--gray);
17-
height: 8rem;
1817
border-radius: var(--radius);
1918
}
2019

21-
.noteList > a:hover {
20+
.glossaryList > a {
21+
border: 2px solid transparent;
22+
color: var(--fg);
23+
font-size: larger;
24+
line-height: normal;
25+
}
26+
27+
.noteList > a:hover, .glossaryList > a:hover {
2228
color: var(--fg);
2329
border: 2px solid var(--link);
2430
}
@@ -27,8 +33,29 @@
2733
color: var(--gray);
2834
}
2935

36+
.glossaryList {
37+
display: grid;
38+
grid-template-columns: repeat(4, 1fr);
39+
gap: 1rem;
40+
}
41+
42+
.noteList > a > span {
43+
display: flex;
44+
flex-direction: column;
45+
gap: 1rem;
46+
}
47+
48+
.glossaryList > a > span > svg {
49+
margin-bottom: 2rem;
50+
}
51+
52+
.glossaryDesc {
53+
color: var(--gray);
54+
margin-bottom: 2rem;
55+
}
56+
3057
@media screen and (max-width: 768px) {
31-
.noteList {
58+
.noteList, .glossaryList {
3259
grid-template-columns: repeat(1, 1fr);
3360
}
3461
}

app/(subpages)/notes/[category]/note/[slug]/note.module.css

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22
grid-column-start: 1;
33
grid-column-end: 3;
44
border: 2px solid var(--link);
5-
padding: 1rem 2rem 0 2rem;
5+
padding: 1rem 2rem;
66
background-color: var(--bg-2);
77
margin-top: 1rem;
88
}
99

10+
.glossaryEntry > p {
11+
padding: 0 0 2rem 0;
12+
}
13+
1014
.tags {
1115
display: flex;
1216
gap: 1rem;
1317
margin-top: 1rem;
1418
position: absolute;
1519
z-index: 1;
1620
top: 10rem;
17-
left: 23rem;
21+
padding-left: 3.5rem;
1822
}
1923

2024
.tags > li {
@@ -33,6 +37,5 @@
3337

3438
.tags {
3539
flex-wrap: wrap;
36-
left: 2rem;
3740
}
3841
}

app/(subpages)/notes/[category]/note/[slug]/page.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import styles from './note.module.css';
1111
import { convertMDWithInlineCodeToHTML } from '@lib/utils';
1212

1313
import '../../../../../../public/assets/katex/katex.min.css';
14-
import { NoteEntry } from '@lib/types';
14+
import { GlossaryEntry, NoteEntry } from '@lib/types';
15+
import Link from '@components/link';
1516

1617
const firaCode = Fira_Code({
1718
subsets: ['latin'],
@@ -22,7 +23,7 @@ const firaCode = Fira_Code({
2223

2324
export async function generateStaticParams() {
2425
const categories = getNoteCategories();
25-
const allNotes = [];
26+
const allNotes: { category: string; slug: string; date?: string }[] = [];
2627
categories.forEach((category) => {
2728
let notes = getNotesInCategory(category);
2829
notes.forEach((note) => {
@@ -64,7 +65,7 @@ export default async function Page({
6465
}: {
6566
category: string;
6667
slug: string;
67-
}): NoteEntry {
68+
}): NoteEntry | GlossaryEntry {
6869
const notes = getNotesInCategory(category);
6970
const noteIndex = notes.findIndex((n) => n?.slug === slug);
7071
const note = notes[noteIndex];
@@ -79,21 +80,31 @@ export default async function Page({
7980

8081
return (
8182
<>
82-
<ul className={styles.tags}>
83-
{tags.length > 1 ? (
84-
tags.map((tag) => <li key={tag}>{tag}</li>)
85-
) : (
86-
<li>{tags}</li>
87-
)}
88-
</ul>
89-
<div className={`${firaCode.className} ${styles.note}`}>
83+
{/* Don't display tags for glossary entries for now */}
84+
{params.category !== 'glossary' && (
85+
<ul className={styles.tags}>
86+
{tags.length > 1 ? (
87+
tags.map((tag) => <li key={tag}>{tag}</li>)
88+
) : (
89+
<li>{tags}</li>
90+
)}
91+
</ul>
92+
)}
93+
<div
94+
className={`${firaCode.className} ${styles.note} ${
95+
params.category === 'glossary' ? styles.glossaryEntry : ''
96+
}`}
97+
>
9098
<h1
9199
className={styles.title}
92100
dangerouslySetInnerHTML={{
93101
__html: convertMDWithInlineCodeToHTML(title),
94102
}}
95103
></h1>
96104
<EntryContent mdxFunctionBody={mdxFunctionBody} />
105+
{params.category === 'glossary' && (
106+
<Link href="/notes/glossary">← Back to Glossary</Link>
107+
)}
97108
</div>
98109
</>
99110
);

app/(subpages)/notes/[category]/page.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getNoteCategories, getNotesInCategory } from '@lib/get-entries';
22
import { capitalizeFirstLetter } from '@lib/utils';
33
import styles from './category.module.css';
44
import NoteBlock from '@components/note-block';
5+
import { GlossaryEntry, NoteEntry } from '@lib/types';
56

67
export async function generateStaticParams() {
78
const categories = getNoteCategories();
@@ -24,8 +25,17 @@ export default function Page({ params }: { params: { category: string } }) {
2425
category.replace(/-/g, ' ').replace(/script/, 'Script')
2526
)}
2627
</h1>
27-
<div className={styles.noteList}>
28-
{notes.map((note) => (
28+
{category === 'glossary' && (
29+
<div className={styles.glossaryDesc}>
30+
<p>Very simple definitions of terms, idioms, etc.</p>
31+
</div>
32+
)}
33+
<div
34+
className={
35+
category === 'glossary' ? styles.glossaryList : styles.noteList
36+
}
37+
>
38+
{notes.map((note: NoteEntry | GlossaryEntry) => (
2939
<NoteBlock key={note.title} note={note} category={category} />
3040
))}
3141
</div>

app/(subpages)/notes/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default async function Notes() {
1818

1919
return (
2020
<Suspense fallback={<LoaderIcon />}>
21-
<p><em>Total of {noteCount} notes</em></p>
21+
<p><em>Total of {noteCount} entries</em></p>
2222
{categories
2323
.sort((a: string, b: string) => b.charCodeAt(0) - a.charCodeAt(0))
2424
.map((category) => {

app/components/note-block/index.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
import { NoteEntry } from '@lib/types';
1+
import { GlossaryEntry, NoteEntry } from '@lib/types';
22
import Link from '@components/link';
33

44
export default function NoteBlock({
55
note,
66
category,
77
}: {
8-
note: NoteEntry;
8+
note: NoteEntry | GlossaryEntry;
99
category: string;
1010
}) {
1111
return (
1212
<Link key={note.slug} href={`/notes/${category}/note/${note.slug}`}>
1313
<span>
14-
<svg
15-
xmlns="http://www.w3.org/2000/svg"
16-
width="24"
17-
height="24"
18-
fill="var(--gray)"
19-
viewBox="0 0 256 256"
20-
>
21-
<path d="M88,96a8,8,0,0,1,8-8h64a8,8,0,0,1,0,16H96A8,8,0,0,1,88,96Zm8,40h64a8,8,0,0,0,0-16H96a8,8,0,0,0,0,16Zm32,16H96a8,8,0,0,0,0,16h32a8,8,0,0,0,0-16ZM224,48V156.69A15.86,15.86,0,0,1,219.31,168L168,219.31A15.86,15.86,0,0,1,156.69,224H48a16,16,0,0,1-16-16V48A16,16,0,0,1,48,32H208A16,16,0,0,1,224,48ZM48,208H152V160a8,8,0,0,1,8-8h48V48H48Zm120-40v28.7L196.69,168Z"></path>
22-
</svg>
14+
{category !== 'glossary' && (
15+
<svg
16+
xmlns="http://www.w3.org/2000/svg"
17+
width="24"
18+
height="24"
19+
fill="var(--gray)"
20+
viewBox="0 0 256 256"
21+
>
22+
<path d="M88,96a8,8,0,0,1,8-8h64a8,8,0,0,1,0,16H96A8,8,0,0,1,88,96Zm8,40h64a8,8,0,0,0,0-16H96a8,8,0,0,0,0,16Zm32,16H96a8,8,0,0,0,0,16h32a8,8,0,0,0,0-16ZM224,48V156.69A15.86,15.86,0,0,1,219.31,168L168,219.31A15.86,15.86,0,0,1,156.69,224H48a16,16,0,0,1-16-16V48A16,16,0,0,1,48,32H208A16,16,0,0,1,224,48ZM48,208H152V160a8,8,0,0,1,8-8h48V48H48Zm120-40v28.7L196.69,168Z"></path>
23+
</svg>
24+
)}
2325
<br />
2426
<span>{note.title}</span>
2527
</span>

app/lib/get-entries.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import matter from 'gray-matter';
22
import fs from 'node:fs';
33
import path from 'node:path';
4-
import type { NoteEntry, PostEntry } from './types';
4+
import type { GlossaryEntry, NoteEntry, PostEntry } from './types';
55

66
const thirdPartyPosts: PostEntry[] = [
77
{
@@ -13,7 +13,8 @@ const thirdPartyPosts: PostEntry[] = [
1313
slug: '',
1414
tags: ['TypeScript'],
1515
isThirdParty: true,
16-
thirdPartyPostHref: 'https://www.freecodecamp.org/news/recursive-types-in-typescript-a-brief-exploration',
16+
thirdPartyPostHref:
17+
'https://www.freecodecamp.org/news/recursive-types-in-typescript-a-brief-exploration',
1718
},
1819
];
1920

@@ -51,7 +52,9 @@ export function getNoteCategories(): string[] {
5152
.filter((dir) => !dir.startsWith('.'));
5253
}
5354

54-
export function getNotesInCategory(category: string): NoteEntry[] {
55+
export function getNotesInCategory(
56+
category: string
57+
): NoteEntry[] | GlossaryEntry[] {
5558
const categories = getNoteCategories();
5659
if (!categories.includes(category)) {
5760
console.error('Note category does not exist');
@@ -67,11 +70,15 @@ export function getNotesInCategory(category: string): NoteEntry[] {
6770
const entryContent = fs.readFileSync(filePath, 'utf8');
6871
const { data, content } = matter(entryContent);
6972
return { ...data, body: content } as NoteEntry;
70-
});
73+
})
74+
.filter((entry) => entry !== null);
7175

72-
return notesWithMetadata
73-
.filter((entry) => entry !== null)
74-
.sort((a, b) =>
76+
// Sort glossary entries alphabetically, other notes by date
77+
if (category === 'glossary') {
78+
return notesWithMetadata.sort() as GlossaryEntry[];
79+
} else {
80+
return notesWithMetadata.sort((a, b) =>
7581
a && b ? new Date(b.date).getTime() - new Date(a.date).getTime() : 0
7682
) as NoteEntry[];
83+
}
7784
}

app/lib/types.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export interface PostEntryData extends PostEntry {
1919

2020
export interface NoteEntry extends Entry {}
2121

22+
export interface GlossaryEntry {
23+
title: string,
24+
slug: string,
25+
tags?: string[]
26+
}
27+
2228
interface BaseProject {
2329
title: string,
2430
description: string | ReactNode,

notes-to-self/glossary/arity.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Arity
3+
slug: arity
4+
---
5+
6+
The arity of a function is the number of arguments it requires.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Challenge-response authentication
3+
slug: challenge-response
4+
---
5+
6+
Challenge-response authentication is a family of security protocols where one party presents a challenge that the other party must provide a valid response to in order to be authenticated.
7+
8+
A simple example is where the challenge is asking for the password, and the response is to provide the correct password.

0 commit comments

Comments
 (0)