Skip to content

Commit e5fee03

Browse files
Merge pull request #83 from madhusudhan1234/feature/codemirror-integration-9518149390473446564
2 parents b76d688 + ebade23 commit e5fee03

File tree

8 files changed

+500
-15
lines changed

8 files changed

+500
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ pnpm-debug.log*
2222

2323
# jetbrains setting folder
2424
.idea/
25+
dev_server.log

package-lock.json

Lines changed: 381 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,20 @@
1313
"@astrojs/mdx": "^4.2.1",
1414
"@astrojs/rss": "^4.0.11",
1515
"@astrojs/sitemap": "^3.3.0",
16+
"@babel/runtime": "^7.28.4",
17+
"@codemirror/lang-css": "^6.3.1",
18+
"@codemirror/lang-html": "^6.4.11",
19+
"@codemirror/lang-javascript": "^6.2.4",
20+
"@codemirror/lang-json": "^6.0.2",
21+
"@codemirror/lang-markdown": "^6.5.0",
22+
"@codemirror/lang-python": "^6.2.1",
23+
"@codemirror/lang-yaml": "^6.1.2",
24+
"@codemirror/state": "^6.5.3",
25+
"@codemirror/view": "^6.39.9",
1626
"@tailwindcss/vite": "^4.1.18",
27+
"@uiw/codemirror-theme-vscode": "^4.25.4",
1728
"astro": "^5.5.2",
29+
"codemirror": "^6.0.2",
1830
"lucide-astro": "^0.556.0",
1931
"sharp": "^0.34.1",
2032
"tailwindcss": "^4.1.18"

src/content/blog/getting-started-with-ansible.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ your-folder-name/
4545
First, define the server host machines and ensure they are accessible via SSH. Set up the necessary SSH configuration using private/public keys, then specify the hosts in the inventory/hosts file like this:
4646

4747
inventory/hosts
48-
```
48+
```ini
4949
[web_servers]
5050
your-host-ip # for example: 192.168.1.10
5151
```
5252

5353
Define the ansible.cfg file like this:
5454

5555
ansible.cfg
56-
```
56+
```ini
5757
[defaults]
5858
inventory = inventory/hosts
5959
remote_user = ubuntu
@@ -95,7 +95,7 @@ Here is the breakdown of the ansible.cfg settings:
9595
Ansible uses simple, human-readable scripts called playbooks to automate tasks. Now add the playbook file in the following location:
9696

9797
playbooks/provision.yml
98-
```
98+
```yaml
9999
- name: Provision PHP
100100
hosts: web_servers
101101
become: true
@@ -143,7 +143,7 @@ The roles/ directory is where Ansible stores reusable automation logic. Each rol
143143
Now let's configure the `common` role. This role is mainly useful for common tasks like updating the apt cache, installing packages, setting timezone, etc.
144144

145145
roles/common/tasks/main.yml
146-
```
146+
```yaml
147147
- name: Install common packages
148148
apt:
149149
name:
@@ -168,15 +168,15 @@ roles/common/tasks/main.yml
168168
The {{ timezone }} variable is defined in the roles/common/vars/main.yml file:
169169

170170
roles/common/vars/main.yml
171-
```
171+
```yaml
172172
---
173173
timezone: Asia/Tokyo
174174
```
175175

176176
Now that the common role is ready, let's set up the PHP role in a similar way:
177177

178178
roles/php/tasks/main.yml
179-
```
179+
```yaml
180180
- name: Install PHP and extensions
181181
apt:
182182
name:
@@ -194,7 +194,7 @@ roles/php/tasks/main.yml
194194
This will install PHP and php-fpm (PHP FastCGI Process Manager) and notify the handler to restart php-fpm. The handler is defined like this:
195195

196196
roles/php/handlers/main.yml
197-
```
197+
```yaml
198198
- name: restart php-fpm
199199
service:
200200
name: "php{{ php_version }}-fpm"
@@ -205,7 +205,7 @@ roles/php/handlers/main.yml
205205
Set the PHP version in the following variable file:
206206

207207
roles/php/vars/main.yml
208-
```
208+
```yaml
209209
---
210210
php_version: 8.3
211211
```
@@ -214,7 +214,9 @@ If you need to add secret variables, you can use an Ansible vault file. When usi
214214

215215
Finally, run this command to provision the server:
216216

217-
`ansible-playbook playbooks/provision.yml`
217+
```bash
218+
ansible-playbook playbooks/provision.yml
219+
```
218220

219221
This is the basic way of using Ansible. For more advanced usage, please check additional resources about Ansible. Creating a README.md file for each role is a best practice to document all necessary details.
220222

src/content/notes/data-structure-circular-queue-in-javascript.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Circular Queue usage:
3636
- print() - print the elements in the queue
3737

3838

39-
```
39+
```js
4040
class CircularQueue {
4141
constructor(capacity) {
4242
this.items = new Array(capacity)
@@ -109,7 +109,7 @@ class CircularQueue {
109109

110110
This is the implementation for the circular queue data structure in JavaScript. Let's check if it workks correctly.
111111

112-
```
112+
```js
113113
const circularQueue = new CircularQueue(5)
114114
console.log(circularQueue.isEmpty()) // true
115115

src/content/notes/data-structure-linkedlist-in-javascript.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Linked List Usage
2727
- Video Player
2828

2929

30-
```
30+
```js
3131
class Node {
3232
constructor(value) {
3333
this.value = value
@@ -58,7 +58,7 @@ class LinkedList {
5858
}
5959
```
6060

61-
```
61+
```js
6262
const list = new LinkedList()
6363
console.log(list.isEmpty()) // true
6464
console.log(list.getSize()) // 0

src/layouts/BlogPost.astro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,8 @@ const tagList: string[] =
119119
</article>
120120
</main>
121121
<Footer />
122+
<script>
123+
import "../scripts/codemirror-loader.js";
124+
</script>
122125
</body>
123126
</html>

src/scripts/codemirror-loader.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
import { EditorView, basicSetup } from "codemirror";
3+
import { EditorState } from "@codemirror/state";
4+
import { vscodeDark } from '@uiw/codemirror-theme-vscode';
5+
6+
async function main() {
7+
const codeblocks = document.querySelectorAll('pre');
8+
9+
for (const preElement of codeblocks) {
10+
const codeElement = preElement.querySelector('code');
11+
if (!codeElement) continue;
12+
13+
const code = codeElement.textContent?.replace(/\n$/, '') || '';
14+
const langMatch = codeElement.className.match(/language-(\S+)/);
15+
let lang = langMatch ? langMatch[1] : 'plaintext';
16+
17+
// Normalize language names
18+
const langMap = {
19+
'js': 'javascript',
20+
'ts': 'typescript',
21+
'py': 'python',
22+
'yml': 'yaml',
23+
'md': 'markdown'
24+
};
25+
lang = langMap[lang] || lang;
26+
27+
const extensions = [basicSetup];
28+
let languageSupport;
29+
30+
try {
31+
switch (lang) {
32+
case 'javascript':
33+
case 'typescript':
34+
case 'jsx':
35+
case 'tsx':
36+
languageSupport = (await import('@codemirror/lang-javascript')).javascript();
37+
break;
38+
case 'python':
39+
languageSupport = (await import('@codemirror/lang-python')).python();
40+
break;
41+
case 'html':
42+
languageSupport = (await import('@codemirror/lang-html')).html();
43+
break;
44+
case 'css':
45+
languageSupport = (await import('@codemirror/lang-css')).css();
46+
break;
47+
case 'json':
48+
languageSupport = (await import('@codemirror/lang-json')).json();
49+
break;
50+
case 'markdown':
51+
languageSupport = (await import('@codemirror/lang-markdown')).markdown();
52+
break;
53+
case 'yaml':
54+
languageSupport = (await import('@codemirror/lang-yaml')).yaml();
55+
break;
56+
}
57+
} catch(e) {
58+
console.error(`Failed to load language support for ${lang}`, e);
59+
}
60+
61+
if (languageSupport) {
62+
extensions.push(languageSupport);
63+
}
64+
65+
const state = EditorState.create({
66+
doc: code,
67+
extensions: [
68+
...extensions,
69+
EditorView.editable.of(false),
70+
vscodeDark
71+
]
72+
});
73+
74+
const parent = preElement.parentNode;
75+
if (parent) {
76+
const wrapper = document.createElement('div');
77+
parent.insertBefore(wrapper, preElement);
78+
preElement.style.display = 'none';
79+
80+
new EditorView({
81+
state,
82+
parent: wrapper,
83+
});
84+
}
85+
}
86+
}
87+
88+
main();

0 commit comments

Comments
 (0)