Fixes syntax highlighting
This commit is contained in:
1
TODO.md
1
TODO.md
@@ -4,6 +4,7 @@
|
|||||||
- [ ] Improve table rendering
|
- [ ] Improve table rendering
|
||||||
- [ ] More image-flow options
|
- [ ] More image-flow options
|
||||||
- [ ] Fix capitalization in notes values/headers. Only the first letter is capitalized, but it should follow the capitalization of the folder. E.g. "NixOS" not "Nixos"
|
- [ ] Fix capitalization in notes values/headers. Only the first letter is capitalized, but it should follow the capitalization of the folder. E.g. "NixOS" not "Nixos"
|
||||||
|
- [x] Code Highlighting
|
||||||
|
|
||||||
## Interaction
|
## Interaction
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ So now that I had these notes, I needed to rebuild the structure so I could rend
|
|||||||
|
|
||||||
I created a type like the following. Note that TypeScript does not support self-referential recursive types! It does allow self-referential interfaces though. Hence the odd syntax.
|
I created a type like the following. Note that TypeScript does not support self-referential recursive types! It does allow self-referential interfaces though. Hence the odd syntax.
|
||||||
|
|
||||||
```TypeScript
|
```typescript
|
||||||
interface Hierarchy extends Record<string, Hierarchy> {}
|
interface Hierarchy extends Record<string, Hierarchy> {}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ However, after messing around with it for a while I realized I needed a little m
|
|||||||
|
|
||||||
This lead me to create the following data structure. Some nodes would have children, others not, and they may or may not have an ID or title. (I could write both of these as `type` declarations because they are _mutually recursive_ types. TypeScript is weird.)
|
This lead me to create the following data structure. Some nodes would have children, others not, and they may or may not have an ID or title. (I could write both of these as `type` declarations because they are _mutually recursive_ types. TypeScript is weird.)
|
||||||
|
|
||||||
```TypeScript
|
```typescript
|
||||||
interface HierarchyNode {
|
interface HierarchyNode {
|
||||||
id: string | null;
|
id: string | null;
|
||||||
title: string | null;
|
title: string | null;
|
||||||
@@ -45,7 +45,7 @@ type Hierarchy = Record<string, HierarchyNode>;
|
|||||||
|
|
||||||
I started with algorithm of splitting all the paths into their parts, then going through and recursively grouping. However, I found this would be much simpler if I just did this as a fold/reduce so I could just focus on adding one path at a time. This gave me the following simple algorithm. Please ignore the repetition, it didn't seem worth cleaning up at the time.
|
I started with algorithm of splitting all the paths into their parts, then going through and recursively grouping. However, I found this would be much simpler if I just did this as a fold/reduce so I could just focus on adding one path at a time. This gave me the following simple algorithm. Please ignore the repetition, it didn't seem worth cleaning up at the time.
|
||||||
|
|
||||||
```TypeScript
|
```typescript
|
||||||
function addToHierarchy(
|
function addToHierarchy(
|
||||||
tree: Hierarchy,
|
tree: Hierarchy,
|
||||||
[noteId, title]: [string, string],
|
[noteId, title]: [string, string],
|
||||||
@@ -82,7 +82,7 @@ export function makeHierarchy(notes: Array<[string, string]>): Hierarchy {
|
|||||||
|
|
||||||
So now I had to render the links. Astro thankfully _does_ support recursive components through `Astro.self`, so I was able to write a single component to render the hierarchy.
|
So now I had to render the links. Astro thankfully _does_ support recursive components through `Astro.self`, so I was able to write a single component to render the hierarchy.
|
||||||
|
|
||||||
```Astro
|
```astro
|
||||||
---
|
---
|
||||||
import { type Hierarchy } from "../lib/hierarchy.ts";
|
import { type Hierarchy } from "../lib/hierarchy.ts";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user