-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: about page + custom attr markdown parser
- Loading branch information
1 parent
0b17f38
commit c14b1b5
Showing
14 changed files
with
252 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: "About :: Ridho Azhar" | ||
description: "Software Developer based on Depok city, Indonesia" | ||
--- | ||
|
||
![ridho](/img/me.jpg){style="float:right;max-width:200px;margin:25px 10px;"} | ||
|
||
Hi my name is Ridho. I am a versatile software developer, with a specific focus on web development. Passionate about informatics, I am dedicated to crafting seamless user experiences and delivering my work with effective communication. | ||
Grounded in the principles of honesty and simplicity, I approach any problem from an adaptive to a technical perspective with commitment to swift and efficient resolution. | ||
|
||
Hi my name is Ridho. I am a versatile software developer, with a specific focus on web development. Passionate about informatics, I am dedicated to crafting seamless user experiences and delivering my work with effective communication. | ||
Grounded in the principles of honesty and simplicity, I approach any problem from an adaptive to a technical perspective with commitment to swift and efficient resolution. | ||
|
||
Hi my name is Ridho. I am a versatile software developer, with a specific focus on web development. Passionate about informatics, I am dedicated to crafting seamless user experiences and delivering my work with effective communication. | ||
Grounded in the principles of honesty and simplicity, I approach any problem from an adaptive to a technical perspective with commitment to swift and efficient resolution. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import "highlight.js/styles/monokai.css"; | ||
import "./markdown.css"; | ||
|
||
type Props = { | ||
content: string; | ||
}; | ||
|
||
export default function Markdown(props: Props) { | ||
return ( | ||
<div | ||
className="markdown-body" | ||
dangerouslySetInnerHTML={{ __html: props.content }} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,7 +118,7 @@ | |
} | ||
|
||
.markdown-body figure { | ||
margin: 1em 40px; | ||
margin: 25px 0; | ||
} | ||
|
||
.markdown-body hr { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type About = { | ||
title: string; | ||
description: string; | ||
content: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// ref: | ||
// - https://github.com/arobase-che/remark-attr/issues/22#issuecomment-1013672211 | ||
// - https://gist.github.com/cah4a/9b75c531540e2891599453863dd24881 | ||
|
||
import parseAttributes from "./util"; | ||
|
||
type Iteratee = (node: any, index: number | null, parent: any) => any; | ||
const map = (tree: any, iteratee: Iteratee) => { | ||
const preorder: Iteratee = (node, index, parent) => { | ||
const newNode = iteratee(node, index, parent); | ||
|
||
if (Array.isArray(newNode.children)) { | ||
newNode.children = newNode.children.map((child: any, index: number) => { | ||
return preorder(child, index, node); | ||
}); | ||
} | ||
|
||
return newNode; | ||
}; | ||
|
||
return preorder(tree, null, null); | ||
}; | ||
|
||
export default function remarkAttrs(): any { | ||
return (tree: any) => { | ||
return map(tree, (node, index, parent) => { | ||
if (node.type == "text" && node.value[0] == "{" && parent && index) { | ||
const endof = node.value.indexOf("}"); | ||
const prev = parent.children[index - 1]; | ||
const attrs = | ||
endof && prev && parseAttributes(node.value.slice(1, endof)); | ||
|
||
if (attrs) { | ||
prev.data = { | ||
...prev.data, | ||
hProperties: attrs, | ||
}; | ||
return { | ||
...node, | ||
value: node.value.slice(endof + 1), | ||
}; | ||
} | ||
} | ||
|
||
return node; | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
class Cursor { | ||
pos = 0; | ||
|
||
constructor(private readonly input: string) {} | ||
|
||
isEof() { | ||
return this.pos >= this.input.length; | ||
} | ||
|
||
get char() { | ||
return this.input[this.pos]; | ||
} | ||
|
||
match(char: string | RegExp): boolean { | ||
const current = this.char; | ||
|
||
if (char instanceof RegExp) { | ||
return !!current && char.test(current); | ||
} else { | ||
return current === char; | ||
} | ||
} | ||
|
||
consumeTrivia() { | ||
while (this.accept(/\s|\n|\r/)) { | ||
// | ||
} | ||
} | ||
|
||
advance() { | ||
const char = this.char; | ||
this.pos++; | ||
return char; | ||
} | ||
|
||
accept(char: string | RegExp): boolean { | ||
if (this.match(char)) { | ||
this.pos++; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
function parseKey(cursor: Cursor): string { | ||
cursor.consumeTrivia(); | ||
|
||
if (!cursor.match(/\w/)) { | ||
return ""; | ||
} | ||
|
||
let key = cursor.advance(); | ||
|
||
while (cursor.match(/[\w-]/)) { | ||
key += cursor.advance(); | ||
} | ||
|
||
cursor.consumeTrivia(); | ||
|
||
return key; | ||
} | ||
|
||
function parseValue(cursor: Cursor): string { | ||
let value = ""; | ||
let eos = " "; | ||
|
||
if (cursor.accept('"')) { | ||
eos = '"'; | ||
} else if (cursor.accept("'")) { | ||
eos = "'"; | ||
} | ||
|
||
while (!cursor.isEof() && !cursor.accept(eos)) { | ||
value += cursor.advance(); | ||
} | ||
|
||
cursor.consumeTrivia(); | ||
|
||
return value.trim(); | ||
} | ||
|
||
/// simple recursive decent parser for strings like: | ||
/// 1) something=true | ||
/// 2) target="_blank" | ||
/// 2) hello='there' | ||
/// 3) easy peasy data-value=5 | ||
export default function parseAttributes( | ||
input: string | ||
): Record<string, string> | null { | ||
const result: Record<string, string> = {}; | ||
const cursor = new Cursor(input); | ||
|
||
cursor.consumeTrivia(); | ||
|
||
while (!cursor.isEof()) { | ||
const key = parseKey(cursor); | ||
|
||
if (!key && !cursor.isEof()) { | ||
// something goes wrong. Parsing failed | ||
return null; | ||
} | ||
|
||
if (key) { | ||
result[key] = cursor.accept("=") ? parseValue(cursor) : ""; | ||
} | ||
} | ||
|
||
return result; | ||
} |