Skip to content

Commit f2dc158

Browse files
authored
Merge pull request #23709 from dvdksn/gordon
site: use gordon for ask ai
2 parents 3cc68ba + 33f0ec9 commit f2dc158

12 files changed

Lines changed: 839 additions & 57 deletions

File tree

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: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,106 @@ 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+
// Configure marked to escape HTML in text tokens only (not code blocks)
39+
marked.use({
40+
walkTokens(token) {
41+
// Escape HTML in text and HTML tokens, preserve code blocks
42+
if (token.type === 'text' || token.type === 'html') {
43+
const text = token.text || token.raw
44+
const escaped = text
45+
.replace(/&/g, '&')
46+
.replace(/</g, '&lt;')
47+
.replace(/>/g, '&gt;')
48+
if (token.text) token.text = escaped
49+
if (token.raw) token.raw = escaped
50+
}
51+
}
52+
})
53+
54+
// Add $markdown magic for rendering markdown with syntax highlighting
55+
Alpine.magic('markdown', () => {
56+
return (content) => {
57+
if (!content) return ''
58+
const html = marked(content)
59+
60+
// Parse and highlight code blocks
61+
const div = document.createElement('div')
62+
div.innerHTML = html
63+
64+
// Handle code blocks (pre > code)
65+
div.querySelectorAll('pre').forEach((pre) => {
66+
// Add not-prose to prevent Tailwind Typography styling
67+
pre.classList.add('not-prose')
68+
const code = pre.querySelector('code')
69+
if (code) {
70+
// Preserve the original text with newlines
71+
const codeText = code.textContent
72+
73+
// Clear and set as plain text first to preserve structure
74+
code.textContent = codeText
75+
76+
// Now apply highlight.js which will work with the text nodes
77+
hljs.highlightElement(code)
78+
}
79+
})
80+
81+
// Handle inline code elements (not in pre blocks)
82+
div.querySelectorAll('code:not(pre code)').forEach((code) => {
83+
code.classList.add('not-prose')
84+
})
85+
86+
return div.innerHTML
87+
}
88+
})
89+
90+
// Stores
1191
Alpine.store("showSidebar", false)
92+
Alpine.store('gordon', {
93+
isOpen: false,
94+
query: '',
95+
toggle() {
96+
this.isOpen = !this.isOpen
97+
},
98+
open(query) {
99+
this.isOpen = true
100+
if (query) this.query = query
101+
},
102+
close() {
103+
this.isOpen = false
104+
}
105+
})
12106

13107
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

layouts/_default/baseof.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
class="dark:bg-navbar-bg-dark bg-navbar-bg flex flex-col items-center text-base text-black dark:text-white"
99
>
1010
{{ partial "header.html" . }}
11+
{{ partial "gordon-chat.html" . }}
1112
<main class="relative flex w-full max-w-[1920px]">
1213
<!-- Sidebar -->
1314
<div

layouts/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</svg>
1616
</div>
1717
{{ partial "header.html" . }}
18+
{{ partial "gordon-chat.html" . }}
1819
<main class="flex w-full flex-col items-stretch gap-20 self-center pt-20">
1920
<div class="grid w-full grid-cols-1 items-center gap-20 px-4 lg:grid-cols-2 xl:w-[1200px] self-center">
2021
<div class="bg-pattern-blue relative rounded-sm drop-shadow z-10"

0 commit comments

Comments
 (0)