summaryrefslogtreecommitdiff
path: root/website.go
diff options
context:
space:
mode:
Diffstat (limited to 'website.go')
-rw-r--r--website.go61
1 files changed, 56 insertions, 5 deletions
diff --git a/website.go b/website.go
index 47b4051..b54030c 100644
--- a/website.go
+++ b/website.go
@@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "html/template"
"io/fs"
"log"
"net/http"
@@ -18,9 +19,15 @@ import (
"time"
"github.com/a-h/templ"
+ chromahtml "github.com/alecthomas/chroma/v2/formatters/html"
"github.com/yuin/goldmark"
+ highlighting "github.com/yuin/goldmark-highlighting/v2"
+ "github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/extension"
+ "github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/renderer/html"
+ "github.com/yuin/goldmark/text"
+ "github.com/yuin/goldmark/util"
"gopkg.in/yaml.v3"
)
@@ -167,8 +174,25 @@ type Blog struct {
}
var md = goldmark.New(
- goldmark.WithExtensions(extension.GFM, extension.Footnote),
+ goldmark.WithExtensions(
+ extension.GFM,
+ extension.Footnote,
+ highlighting.NewHighlighting(
+ highlighting.WithFormatOptions(chromahtml.WithClasses(true)),
+ highlighting.WithWrapperRenderer(func(w util.BufWriter, ctx highlighting.CodeBlockContext, entering bool) {
+ if entering {
+ lang, _ := ctx.Language()
+ fmt.Fprintf(w, `<div class="codeblock" data-lang="%s">`, template.HTMLEscapeString(string(lang)))
+ } else {
+ w.WriteString(`</div>`)
+ }
+ }),
+ ),
+ ),
goldmark.WithRendererOptions(html.WithUnsafe()),
+ goldmark.WithParserOptions(
+ parser.WithASTTransformers(util.Prioritized(externalLinks{}, 100)),
+ ),
)
type frontmatter struct {
@@ -295,6 +319,33 @@ func latestBlog(blogs []Blog) *Blog {
return &blogs[0]
}
+type externalLinks struct{}
+
+func openInNewTab(n ast.Node) {
+ n.SetAttributeString("target", []byte("_blank"))
+ n.SetAttributeString("rel", []byte("noopener noreferrer"))
+}
+
+func (externalLinks) Transform(doc *ast.Document, reader text.Reader, pc parser.Context) {
+ src := reader.Source()
+ ast.Walk(doc, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
+ if !entering {
+ return ast.WalkContinue, nil
+ }
+ switch link := n.(type) {
+ case *ast.Link:
+ if bytes.HasPrefix(link.Destination, []byte("http")) {
+ openInNewTab(link)
+ }
+ case *ast.AutoLink:
+ if link.AutoLinkType == ast.AutoLinkURL && bytes.HasPrefix(link.URL(src), []byte("http")) {
+ openInNewTab(link)
+ }
+ }
+ return ast.WalkContinue, nil
+ })
+}
+
var projects = []Project{
{
Slug: "krypton",
@@ -545,13 +596,13 @@ func main() {
}
jetbrains := FontPack{
- Monospace: "JetBrains Mono",
- Normal: `system-ui, sans-serif`,
+ Monospace: `JetBrains Mono, monospace`,
+ Normal: `Inter, system-ui, sans-serif`,
}
minecraft := FontPack{
- Monospace: `"Monocraft", "JetBrains Mono", monospace`,
- Normal: `"Monocraft", system-ui, sans-serif`,
+ Monospace: `Monocraft, JetBrains Mono, monospace`,
+ Normal: `Monocraft, Inter, system-ui, sans-serif`,
}
SetTheme("carbonight-cat", carbonightCat)