Skip to content

Commit 2b37a6d

Browse files
committed
site: use gordon for ask ai
Signed-off-by: David Karlsson <[email protected]>
1 parent 9900c01 commit 2b37a6d

File tree

12 files changed

+723
-60
lines changed

12 files changed

+723
-60
lines changed

assets/css/style.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@
4141
@import "syntax-dark.css";
4242
@import "syntax-light.css";
4343
@import "components.css";
44+
@import "highlight-github-dark.css";
4445

4546
@variant dark (&:where(.dark, .dark *));

assets/js/src/alpine.js

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,90 @@ import Alpine from 'alpinejs'
22
import collapse from '@alpinejs/collapse'
33
import persist from '@alpinejs/persist'
44
import focus from '@alpinejs/focus'
5-
5+
import { marked } from 'marked'
6+
import hljs from 'highlight.js/lib/core'
7+
// Import languages relevant to Docker docs
8+
import bash from 'highlight.js/lib/languages/bash'
9+
import dockerfile from 'highlight.js/lib/languages/dockerfile'
10+
import yaml from 'highlight.js/lib/languages/yaml'
11+
import json from 'highlight.js/lib/languages/json'
12+
import javascript from 'highlight.js/lib/languages/javascript'
13+
import python from 'highlight.js/lib/languages/python'
14+
import go from 'highlight.js/lib/languages/go'
15+
616
window.Alpine = Alpine
717

818
Alpine.plugin(collapse)
919
Alpine.plugin(persist)
1020
Alpine.plugin(focus)
21+
22+
// Register highlight.js languages
23+
hljs.registerLanguage('bash', bash)
24+
hljs.registerLanguage('sh', bash)
25+
hljs.registerLanguage('shell', bash)
26+
hljs.registerLanguage('console', bash)
27+
hljs.registerLanguage('dockerfile', dockerfile)
28+
hljs.registerLanguage('yaml', yaml)
29+
hljs.registerLanguage('yml', yaml)
30+
hljs.registerLanguage('json', json)
31+
hljs.registerLanguage('javascript', javascript)
32+
hljs.registerLanguage('js', javascript)
33+
hljs.registerLanguage('python', python)
34+
hljs.registerLanguage('py', python)
35+
hljs.registerLanguage('go', go)
36+
hljs.registerLanguage('golang', go)
37+
38+
// Add $markdown magic for rendering markdown with syntax highlighting
39+
Alpine.magic('markdown', () => {
40+
return (content) => {
41+
if (!content) return ''
42+
const html = marked(content)
43+
44+
// Parse and highlight code blocks
45+
const div = document.createElement('div')
46+
div.innerHTML = html
47+
48+
// Handle code blocks (pre > code)
49+
div.querySelectorAll('pre').forEach((pre) => {
50+
// Add not-prose to prevent Tailwind Typography styling
51+
pre.classList.add('not-prose')
52+
const code = pre.querySelector('code')
53+
if (code) {
54+
// Preserve the original text with newlines
55+
const codeText = code.textContent
56+
57+
// Clear and set as plain text first to preserve structure
58+
code.textContent = codeText
59+
60+
// Now apply highlight.js which will work with the text nodes
61+
hljs.highlightElement(code)
62+
}
63+
})
64+
65+
// Handle inline code elements (not in pre blocks)
66+
div.querySelectorAll('code:not(pre code)').forEach((code) => {
67+
code.classList.add('not-prose')
68+
})
69+
70+
return div.innerHTML
71+
}
72+
})
73+
74+
// Stores
1175
Alpine.store("showSidebar", false)
76+
Alpine.store('gordon', {
77+
isOpen: Alpine.$persist(false).as('gordon-isOpen'),
78+
query: '',
79+
toggle() {
80+
this.isOpen = !this.isOpen
81+
},
82+
open(query) {
83+
this.isOpen = true
84+
if (query) this.query = query
85+
},
86+
close() {
87+
this.isOpen = false
88+
}
89+
})
1290

1391
Alpine.start()

hugo.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ module:
271271
# Mount the icon files to assets so we can access them with resources.Get
272272
- source: node_modules/@material-symbols/svg-400/rounded
273273
target: assets/icons
274+
# Mount highlight.js theme for Gordon chat syntax highlighting
275+
- source: node_modules/highlight.js/styles/github-dark.css
276+
target: assets/css/highlight-github-dark.css
274277

275278
imports:
276279

0 commit comments

Comments
 (0)