xonecas.io
8356
Wx

www-xonecas-io / files

www-xonecas-io / internal / project / topics.go

4.9 KB
1package project
2
3import (
4	"path/filepath"
5	"regexp"
6	"strings"
7
8	"xonecas.io/site/internal/repo"
9)
10
11// topic is a specific tag. code matches the dependency files and the paths, ignoring case;
12// prose matches the README and the agent instructions as written. Either one finds it.
13type topic struct {
14	name        string
15	code, prose *regexp.Regexp
16}
17
18// t compiles a topic. An empty pattern never matches.
19func t(name, code, prose string) topic {
20	re := func(flags, s string) *regexp.Regexp {
21		if s == "" {
22			return nil
23		}
24		return regexp.MustCompile(flags + s)
25	}
26	return topic{name, re(`(?i)`, code), re(``, prose)}
27}
28
29// topics is the vocabulary, in the order a project lists them: what it is, then what it is built with.
30var topics = []topic{
31	t("cli", `"(commander|yargs|meow|cac)"|spf13/cobra|urfave/cli`, `\b(a|the) CLI\b|\bCLI (tool|app)\b|\bcommand[- ]line (tool|app|interface|utility)\b`),
32	t("tui", `bubbletea|"(ink|blessed)"|cel-tui|tview|ratatui`, `\bTUI\b|\bterminal UI\b`),
33	t("neovim", `\bnvim\b|(^|\n)(lua|plugin|ftplugin|after)/[^\n]*\.(lua|vim)\n`, `\bNeovim\b|\bnvim\b`),
34	t("vim", `\.vim\n|(^|[\n/])\.?vimrc\n|(^|\n)vim-`, `\bVim\b`),
35	t("dotfiles", `dotfiles`, `\bdotfiles\b`),
36	t("i3", `(^|[\n/-])i3(wm|status|_config)?\b`, `\bi3(wm)?\b`),
37	t("macos", `macotron`, `\bmenu bar\b`),
38	t("chrome-extension", `"(content_scripts|manifest_version|browser_action)"`, `\b(Chrome|browser|Firefox) (extension|add-on)\b|\bunpacke?d extension\b|\bextensions? tab\b`),
39	t("ai-agent", `@modelcontextprotocol|mcp-go|@earendil-works|opencode`, `\bcoding agents?\b|\bagent (loop|harness)\b|\bMCP\b`),
40	t("skills", `(^|[\n/])SKILL\.md\n`, ``),
41	t("llm", `"openai"|go-openai|@anthropic-ai|@ai-sdk|"ai"|ollama`, `\bLLMs?\b|\bOpenRouter\b|\bOllama\b`),
42	t("pytorch", `\btorch\b`, `\bPyTorch\b`),
43	t("game", `"(phaser|pixi\.js|kaboom|excalibur)"`, `\b[Gg]ames?\b`),
44	t("canvas", `canvas`, `\b[Cc]anvas\b`),
45	t("webrtc", `livekit|webrtc|simple-peer|"peerjs"`, `\bWebRTC\b`),
46	t("websocket", `gorilla/websocket|"(ws|socket\.io|socket\.io-client)"|nhooyr\.io/websocket`, `\bWebSockets?\b`),
47	t("react", `"(react|react-dom|react-scripts|preact)"`, `\bReact\b`),
48	t("next.js", `"next"`, `\bNext\.js\b`),
49	t("vue", `"vue"`, `\bVue(\.js)?\b`),
50	t("angular", `"(angular|@angular/core)"`, `\bAngular(JS)?\b`),
51	t("backbone", `"backbone"|(^|/)backbone[^/\n]*\.js\n`, `\bBackbone(\.js)?\b`),
52	t("jquery", `"jquery"|(^|/)jquery[^/\n]*\.js\n`, `\bjQuery\b`),
53	t("three.js", `"three"|threejs|(^|/)three(\.min)?\.js\n`, `\b[Tt]hree\.js\b`),
54	t("tailwind", `tailwindcss`, `\bTailwind\b`),
55	t("bootstrap", `"bootstrap"`, `\bBootstrap\b`),
56	t("styled-components", `"styled-components"`, ``),
57	t("shadcn", `"shadcn"|radix-ui`, `\bshadcn\b`),
58	t("vite", `"vite"`, `\bVite\b`),
59	t("node", `(^|\n)node_modules/|(^|\n)(server|app|http|node)\.js\n`, `\bNode(\.js|JS)?\b|\bnode\.js\b`),
60	t("bun", `@types/bun|(^|\n)bun\.lockb?\n|bunfig\.toml`, ``),
61	t("express", `"express"`, `\bExpress\.js\b`),
62	t("koa", `"koa"`, `\bKoa\b`),
63	t("gin", `gin-gonic/gin`, ``),
64	t("encore", `encore\.dev`, `\bEncore\b`),
65	t("flask", `\bflask\b`, `\bFlask\b`),
66	t("jekyll", `\bjekyll\b|github-pages`, `\bJekyll\b`),
67	t("electron", `"electron"`, `\bElectron\b`),
68	t("sqlite", `sqlite`, `\bSQLite\b`),
69	t("postgres", `"(pg|postgres)"|jackc/pgx|lib/pq`, `\bPostgres(QL)?\b`),
70	t("mongodb", `"mongo(db|ose)"`, `\bMongoDB\b`),
71	t("redis", `"(redis|ioredis)"|go-redis`, `\bRedis\b`),
72	t("prisma", `"prisma"|@prisma/client`, ``),
73	t("drizzle", `drizzle-orm`, ``),
74	t("graphql", `"graphql"|apollo`, `\bGraphQL\b`),
75	t("tree-sitter", `tree-sitter`, `\b[Tt]ree-sitter\b`),
76	t("docker", `(^|\n|/)(dockerfile|(docker-)?compose\.ya?ml)\n`, `\bDocker\b`),
77}
78
79var (
80	manifest = regexp.MustCompile(`(?i)(^|/)(package\.json|go\.mod|cargo\.toml|requirements\.txt|pyproject\.toml|gemfile|build\.zig\.zon|composer\.json|bower\.json|manifest\.json)$`)
81	agents   = regexp.MustCompile(`(?i)(^|/)(agents|claude)\.md$`)
82)
83
84// findTopics reads the dependency files, the README and the agent instructions among the kept paths in dir,
85// and returns the topics they, the repo's name and all its paths mention.
86func findTopics(dir string, all, kept []string, readme string) []string {
87	code := []string{strings.TrimSuffix(filepath.Base(dir), ".git"), strings.Join(all, "\n") + "\n"}
88	prose := []string{}
89	for _, p := range kept {
90		into := &code
91		if p == readme || agents.MatchString(p) {
92			into = &prose
93		} else if !manifest.MatchString(p) {
94			continue
95		}
96		if text, err := repo.Git(dir, "show", "HEAD:"+p); err == nil {
97			*into = append(*into, text)
98		}
99	}
100	return matchTopics(strings.Join(code, "\n"), strings.Join(prose, "\n"))
101}
102
103// matchTopics is the topics that code or prose mention.
104func matchTopics(code, prose string) []string {
105	var found []string
106	for _, tp := range topics {
107		if (tp.code != nil && tp.code.MatchString(code)) || (tp.prose != nil && tp.prose.MatchString(prose)) {
108			found = append(found, tp.name)
109		}
110	}
111	return found
112}