-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from zyriab/chore/refactor-snippets-and-skills
chore: refactor snippets and skills
- Loading branch information
Showing
5 changed files
with
119 additions
and
113 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package utils | ||
package datastructure | ||
|
||
type Deque[T any] struct { | ||
items []T | ||
|
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 |
---|---|---|
@@ -1,49 +1,55 @@ | ||
function colorizeCode() { | ||
const element = document.getElementsByTagName('code')[0]; | ||
|
||
if (element == null) { | ||
return; | ||
} | ||
|
||
const text = element.innerText; | ||
const language = element.classList[0]; | ||
|
||
const keywords = { | ||
js: javascriptKeywords, | ||
ts: typescriptKeywords, | ||
html: htmlKeywords, | ||
css: cssKeywords, | ||
go: goKeywords, | ||
c: cKeywords, | ||
gql: graphqlKeywords, | ||
sql: sqlKeywords, | ||
jsx: reactKeywords, | ||
jest: testKeywords, | ||
sh: bashKeywords, | ||
yml: yamlKeywords, | ||
ino: arduinoKeywords, | ||
}[language]; | ||
|
||
if (keywords == null) { | ||
return; | ||
} | ||
|
||
let coloredText = text | ||
|
||
keywords.forEach((subKeywords, i) => { | ||
const regex = new RegExp(`\\b(${subKeywords.join('|')})\\b`, 'g'); | ||
coloredText = coloredText.replaceAll(regex, (match) => | ||
`<span class="${COLORS[i]}">${match}</span>` | ||
); | ||
}) | ||
|
||
element.innerHTML = coloredText; | ||
const element = document.getElementsByTagName("code")[0]; | ||
|
||
if (element == null) { | ||
return; | ||
} | ||
|
||
const text = element.innerText; | ||
const language = element.classList[0]; | ||
|
||
const keywords = { | ||
js: javascriptKeywords, | ||
ts: typescriptKeywords, | ||
html: htmlKeywords, | ||
css: cssKeywords, | ||
go: goKeywords, | ||
c: cKeywords, | ||
gql: graphqlKeywords, | ||
sql: sqlKeywords, | ||
jsx: reactKeywords, | ||
jest: testKeywords, | ||
sh: bashKeywords, | ||
yml: yamlKeywords, | ||
ino: arduinoKeywords, | ||
}[language]; | ||
|
||
if (keywords == null) { | ||
return; | ||
} | ||
|
||
let coloredText = text; | ||
|
||
keywords.forEach( | ||
(/** @type {[]string} **/ subKeywords, /** @type {number} **/ i) => { | ||
const regex = new RegExp(`\\b(${subKeywords.join("|")})\\b`, "g"); | ||
coloredText = coloredText.replaceAll( | ||
regex, | ||
(match) => `<span class="${COLORS[i]}">${match}</span>`, | ||
); | ||
}, | ||
); | ||
|
||
element.innerHTML = coloredText; | ||
} | ||
|
||
/** | ||
* @param {string} snippet | ||
* @returns {Promise<string>} | ||
*/ | ||
async function getCodeSnippet(snippet) { | ||
const response = await fetch(`../data/snippets/snippet.${snippet}`) | ||
const text = await response.text(); | ||
const response = await fetch(`../data/snippets/snippet.${snippet}`); | ||
const text = await response.text(); | ||
|
||
return text; | ||
return text; | ||
} | ||
|
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 |
---|---|---|
@@ -1,49 +1,49 @@ | ||
function colorizeCode(): void { | ||
const element = document.getElementsByTagName('code')[0]; | ||
|
||
if (element == null) { | ||
return; | ||
} | ||
|
||
const text = element.innerText; | ||
const language = element.classList[0]; | ||
|
||
const keywords = { | ||
js: javascriptKeywords, | ||
ts: typescriptKeywords, | ||
html: htmlKeywords, | ||
css: cssKeywords, | ||
go: goKeywords, | ||
c: cKeywords, | ||
gql: graphqlKeywords, | ||
sql: sqlKeywords, | ||
jsx: reactKeywords, | ||
jest: testKeywords, | ||
sh: bashKeywords, | ||
yml: yamlKeywords, | ||
ino: arduinoKeywords, | ||
}[language]; | ||
|
||
if (keywords == null) { | ||
return; | ||
} | ||
|
||
let coloredText = text | ||
|
||
keywords.forEach((subKeywords, i) => { | ||
const regex = new RegExp(`\\b(${subKeywords.join('|')})\\b`, 'g'); | ||
coloredText = coloredText.replaceAll(regex, (match: string) => | ||
`<span class="${COLORS[i]}">${match}</span>` | ||
); | ||
}) | ||
|
||
element.innerHTML = coloredText; | ||
const element = document.getElementsByTagName("code")[0]; | ||
|
||
if (element == null) { | ||
return; | ||
} | ||
|
||
const text = element.innerText; | ||
const language = element.classList[0]; | ||
|
||
const keywords = { | ||
js: javascriptKeywords, | ||
ts: typescriptKeywords, | ||
html: htmlKeywords, | ||
css: cssKeywords, | ||
go: goKeywords, | ||
c: cKeywords, | ||
gql: graphqlKeywords, | ||
sql: sqlKeywords, | ||
jsx: reactKeywords, | ||
jest: testKeywords, | ||
sh: bashKeywords, | ||
yml: yamlKeywords, | ||
ino: arduinoKeywords, | ||
}[language]; | ||
|
||
if (keywords == null) { | ||
return; | ||
} | ||
|
||
let coloredText = text; | ||
|
||
keywords.forEach((subKeywords: string[], i: number) => { | ||
const regex = new RegExp(`\\b(${subKeywords.join("|")})\\b`, "g"); | ||
coloredText = coloredText.replaceAll( | ||
regex, | ||
(match: string) => `<span class="${COLORS[i]}">${match}</span>`, | ||
); | ||
}); | ||
|
||
element.innerHTML = coloredText; | ||
} | ||
|
||
async function getCodeSnippet(snippet): Promise<string> { | ||
const response = await fetch(`../data/snippets/snippet.${snippet}`) | ||
const text = await response.text(); | ||
async function getCodeSnippet(snippet: string): Promise<string> { | ||
const response = await fetch(`../data/snippets/snippet.${snippet}`); | ||
const text = await response.text(); | ||
|
||
return text; | ||
return text; | ||
} | ||
|
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