vitepress-theme-pm 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +78 -0
- package/dist/plugin.mjs +184 -0
- package/package.json +45 -0
- package/src/Layout.vue +15 -0
- package/src/cli.mjs +103 -0
- package/src/components/Board.vue +200 -0
- package/src/components/BoardCard.vue +73 -0
- package/src/components/BoardColumn.vue +90 -0
- package/src/components/MarkdownBody.vue +105 -0
- package/src/components/ProgressBar.vue +30 -0
- package/src/components/TagEditor.vue +65 -0
- package/src/components/TicketDetail.vue +257 -0
- package/src/composables/useDragDrop.ts +47 -0
- package/src/composables/useMarkdown.ts +24 -0
- package/src/composables/useTicketWriter.ts +32 -0
- package/src/index.ts +12 -0
- package/src/plugins/markdownWriter.ts +223 -0
- package/src/styles/board.css +40 -0
- package/src/types.ts +21 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Pierce
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# vitepress-project-management
|
|
2
|
+
|
|
3
|
+
A VitePress theme that adds a kanban board for project management. Tickets are individual `.md` files with YAML frontmatter — your board lives in your docs repo.
|
|
4
|
+
|
|
5
|
+
[Demo](https://mcbridemusings.github.io/vitepress-project-management/board.html)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install vitepress-theme-pm
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
### 1. Theme
|
|
16
|
+
|
|
17
|
+
`.vitepress/theme/index.ts`:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import Theme from "vitepress-theme-pm";
|
|
21
|
+
export default Theme;
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 2. Plugin
|
|
25
|
+
|
|
26
|
+
`.vitepress/config.ts`:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { defineConfig } from "vitepress";
|
|
30
|
+
import { markdownWriterPlugin } from "vitepress-theme-pm/plugin";
|
|
31
|
+
|
|
32
|
+
export default defineConfig({
|
|
33
|
+
vite: {
|
|
34
|
+
plugins: [markdownWriterPlugin()],
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 3. Board page
|
|
40
|
+
|
|
41
|
+
Create `board.md` at your site root:
|
|
42
|
+
|
|
43
|
+
```yaml
|
|
44
|
+
---
|
|
45
|
+
layout: page
|
|
46
|
+
board: true
|
|
47
|
+
ticketsDir: tickets
|
|
48
|
+
ticketPrefix: PM
|
|
49
|
+
defaultColumn: backlog
|
|
50
|
+
columns:
|
|
51
|
+
- { key: backlog, label: Backlog, color: "#718096" }
|
|
52
|
+
- { key: doing, label: In Progress, color: "#e6a817" }
|
|
53
|
+
- { key: review, label: Review, color: "#9f7aea" }
|
|
54
|
+
- { key: done, label: Done, color: "#6bcb6b" }
|
|
55
|
+
---
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 4. Create tickets
|
|
59
|
+
|
|
60
|
+
Via the board UI (click **+ New**) or CLI:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npx vitepress-theme-pm ticket "Fix login bug" --status doing --priority high --tags auth,ui
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Tickets are markdown files in `tickets/` with frontmatter for metadata and a body for description.
|
|
67
|
+
|
|
68
|
+
## How it works
|
|
69
|
+
|
|
70
|
+
- The board extends VitePress's default theme — all your docs pages keep their sidebar, TOC, and nav
|
|
71
|
+
- Tickets are plain `.md` files with `id`, `title`, `status`, `priority`, and `tags` in frontmatter
|
|
72
|
+
- Drag-and-drop between columns updates the ticket file
|
|
73
|
+
- A Vite dev server plugin handles reads/writes (dev only — no server code in production builds)
|
|
74
|
+
- The CLI creates ticket files from the terminal
|
|
75
|
+
|
|
76
|
+
## License
|
|
77
|
+
|
|
78
|
+
MIT
|
package/dist/plugin.mjs
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// src/plugins/markdownWriter.ts
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import matter from "gray-matter";
|
|
5
|
+
function scanTickets(ticketsDir, dirRelative) {
|
|
6
|
+
if (!fs.existsSync(ticketsDir)) return [];
|
|
7
|
+
const files = fs.readdirSync(ticketsDir).filter((f) => f.endsWith(".md"));
|
|
8
|
+
return files.map((file) => {
|
|
9
|
+
const raw = fs.readFileSync(path.join(ticketsDir, file), "utf-8");
|
|
10
|
+
const parsed = matter(raw);
|
|
11
|
+
return {
|
|
12
|
+
id: Number(parsed.data.id) || 0,
|
|
13
|
+
title: parsed.data.title || path.basename(file, ".md"),
|
|
14
|
+
status: parsed.data.status || "backlog",
|
|
15
|
+
priority: parsed.data.priority || "medium",
|
|
16
|
+
tags: parsed.data.tags || [],
|
|
17
|
+
body: parsed.content.trim(),
|
|
18
|
+
url: `/${dirRelative}/${path.basename(file, ".md")}.html`
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function getMaxTicketId(ticketsDir) {
|
|
23
|
+
if (!fs.existsSync(ticketsDir)) return 0;
|
|
24
|
+
const files = fs.readdirSync(ticketsDir).filter((f) => f.endsWith(".md"));
|
|
25
|
+
let max = 0;
|
|
26
|
+
for (const file of files) {
|
|
27
|
+
const raw = fs.readFileSync(path.join(ticketsDir, file), "utf-8");
|
|
28
|
+
const parsed = matter(raw);
|
|
29
|
+
const id = Number(parsed.data.id);
|
|
30
|
+
if (id > max) max = id;
|
|
31
|
+
}
|
|
32
|
+
return max;
|
|
33
|
+
}
|
|
34
|
+
function findMarkdownFiles(dir) {
|
|
35
|
+
const results = [];
|
|
36
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
37
|
+
const full = path.join(dir, entry.name);
|
|
38
|
+
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules") {
|
|
39
|
+
results.push(...findMarkdownFiles(full));
|
|
40
|
+
} else if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
41
|
+
results.push(full);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return results;
|
|
45
|
+
}
|
|
46
|
+
function markdownWriterPlugin() {
|
|
47
|
+
let srcDir = "";
|
|
48
|
+
let nextId = 0;
|
|
49
|
+
return {
|
|
50
|
+
name: "vitepress-pm-markdown-writer",
|
|
51
|
+
configResolved(config) {
|
|
52
|
+
srcDir = config.root;
|
|
53
|
+
},
|
|
54
|
+
configureServer(server) {
|
|
55
|
+
server.middlewares.use("/__vitepress_pm_tickets", (req, res) => {
|
|
56
|
+
const url = new URL(req.url || "/", "http://localhost");
|
|
57
|
+
const dir = url.searchParams.get("dir") || "tickets";
|
|
58
|
+
const ticketsDir = path.resolve(srcDir, dir);
|
|
59
|
+
const tickets = scanTickets(ticketsDir, dir);
|
|
60
|
+
let maxId = 0;
|
|
61
|
+
for (const t of tickets) {
|
|
62
|
+
if (t.id > maxId) maxId = t.id;
|
|
63
|
+
}
|
|
64
|
+
nextId = maxId + 1;
|
|
65
|
+
res.setHeader("Content-Type", "application/json");
|
|
66
|
+
res.end(JSON.stringify(tickets));
|
|
67
|
+
});
|
|
68
|
+
server.middlewares.use("/__vitepress_pm_create", (req, res) => {
|
|
69
|
+
if (req.method !== "POST") {
|
|
70
|
+
res.statusCode = 405;
|
|
71
|
+
res.end("Method not allowed");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
let body = "";
|
|
75
|
+
req.on("data", (chunk) => {
|
|
76
|
+
body += chunk;
|
|
77
|
+
});
|
|
78
|
+
req.on("end", () => {
|
|
79
|
+
try {
|
|
80
|
+
const { dir, status, title, priority, tags, body: ticketBody } = JSON.parse(body);
|
|
81
|
+
const ticketsDir = path.resolve(srcDir, dir || "tickets");
|
|
82
|
+
if (!fs.existsSync(ticketsDir)) {
|
|
83
|
+
fs.mkdirSync(ticketsDir, { recursive: true });
|
|
84
|
+
}
|
|
85
|
+
const currentMax = getMaxTicketId(ticketsDir);
|
|
86
|
+
if (nextId <= currentMax) nextId = currentMax + 1;
|
|
87
|
+
const id = nextId++;
|
|
88
|
+
const frontmatter = {
|
|
89
|
+
id,
|
|
90
|
+
title: title || "New ticket",
|
|
91
|
+
status: status || "backlog",
|
|
92
|
+
priority: priority || "medium",
|
|
93
|
+
tags: tags || []
|
|
94
|
+
};
|
|
95
|
+
const bodyContent = ticketBody ? `
|
|
96
|
+
${ticketBody}
|
|
97
|
+
` : "\n";
|
|
98
|
+
const content = matter.stringify(bodyContent, frontmatter);
|
|
99
|
+
const filePath = path.join(ticketsDir, `${id}.md`);
|
|
100
|
+
fs.writeFileSync(filePath, content);
|
|
101
|
+
const ticket = {
|
|
102
|
+
...frontmatter,
|
|
103
|
+
body: ticketBody || "",
|
|
104
|
+
url: `/${dir || "tickets"}/${id}.html`
|
|
105
|
+
};
|
|
106
|
+
res.setHeader("Content-Type", "application/json");
|
|
107
|
+
res.end(JSON.stringify(ticket));
|
|
108
|
+
} catch (e) {
|
|
109
|
+
res.statusCode = 500;
|
|
110
|
+
res.end(String(e));
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
server.middlewares.use("/__vitepress_pm_update", (req, res) => {
|
|
115
|
+
if (req.method !== "POST") {
|
|
116
|
+
res.statusCode = 405;
|
|
117
|
+
res.end("Method not allowed");
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
let body = "";
|
|
121
|
+
req.on("data", (chunk) => {
|
|
122
|
+
body += chunk;
|
|
123
|
+
});
|
|
124
|
+
req.on("end", () => {
|
|
125
|
+
try {
|
|
126
|
+
const { url, updates } = JSON.parse(body);
|
|
127
|
+
if (!url || typeof url !== "string") {
|
|
128
|
+
res.statusCode = 400;
|
|
129
|
+
res.end("Missing url");
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const mdPath = url.replace(/\.html$/, ".md").replace(/^\//, "");
|
|
133
|
+
const filePath = path.resolve(srcDir, mdPath);
|
|
134
|
+
if (!fs.existsSync(filePath)) {
|
|
135
|
+
res.statusCode = 404;
|
|
136
|
+
res.end(`File not found: ${mdPath}`);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const raw = fs.readFileSync(filePath, "utf-8");
|
|
140
|
+
const parsed = matter(raw);
|
|
141
|
+
for (const [key, value] of Object.entries(updates)) {
|
|
142
|
+
if (key === "body") {
|
|
143
|
+
parsed.content = "\n" + String(value) + "\n";
|
|
144
|
+
} else {
|
|
145
|
+
parsed.data[key] = value;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const output = matter.stringify(parsed.content, parsed.data);
|
|
149
|
+
fs.writeFileSync(filePath, output);
|
|
150
|
+
res.statusCode = 200;
|
|
151
|
+
res.end("ok");
|
|
152
|
+
} catch (e) {
|
|
153
|
+
res.statusCode = 500;
|
|
154
|
+
res.end(String(e));
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
generateBundle() {
|
|
160
|
+
const mdFiles = findMarkdownFiles(srcDir);
|
|
161
|
+
const seen = /* @__PURE__ */ new Set();
|
|
162
|
+
for (const file of mdFiles) {
|
|
163
|
+
const raw = fs.readFileSync(file, "utf-8");
|
|
164
|
+
const parsed = matter(raw);
|
|
165
|
+
if (!parsed.data.board) continue;
|
|
166
|
+
const dir = parsed.data.ticketsDir || "tickets";
|
|
167
|
+
if (seen.has(dir)) continue;
|
|
168
|
+
seen.add(dir);
|
|
169
|
+
const ticketsDir = path.resolve(srcDir, dir);
|
|
170
|
+
const tickets = scanTickets(ticketsDir, dir);
|
|
171
|
+
this.emitFile({
|
|
172
|
+
type: "asset",
|
|
173
|
+
fileName: `__vitepress_pm_tickets/${dir}.json`,
|
|
174
|
+
source: JSON.stringify(tickets)
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
export {
|
|
181
|
+
getMaxTicketId,
|
|
182
|
+
markdownWriterPlugin,
|
|
183
|
+
scanTickets
|
|
184
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vitepress-theme-pm",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A VitePress theme that adds a kanban board for project management with markdown tickets",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/McBrideMusings/vitepress-project-management",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/McBrideMusings/vitepress-project-management.git"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"vitepress",
|
|
14
|
+
"vitepress-theme",
|
|
15
|
+
"kanban",
|
|
16
|
+
"project-management",
|
|
17
|
+
"markdown",
|
|
18
|
+
"vue"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "esbuild src/plugins/markdownWriter.ts --format=esm --platform=node --bundle --external:gray-matter --external:vite --outfile=dist/plugin.mjs",
|
|
22
|
+
"prepublishOnly": "npm run build"
|
|
23
|
+
},
|
|
24
|
+
"exports": {
|
|
25
|
+
".": "./src/index.ts",
|
|
26
|
+
"./plugin": "./dist/plugin.mjs"
|
|
27
|
+
},
|
|
28
|
+
"bin": {
|
|
29
|
+
"vitepress-theme-pm": "./src/cli.mjs"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"src",
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"vitepress": ">=1.0.0",
|
|
37
|
+
"vue": ">=3.3.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"esbuild": ">=0.17.0"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"gray-matter": "^4.0.3"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/Layout.vue
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useData } from 'vitepress'
|
|
3
|
+
import DefaultTheme from 'vitepress/theme'
|
|
4
|
+
import Board from './components/Board.vue'
|
|
5
|
+
|
|
6
|
+
const { frontmatter } = useData()
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<template>
|
|
10
|
+
<DefaultTheme.Layout>
|
|
11
|
+
<template #page-top>
|
|
12
|
+
<Board v-if="frontmatter.board" />
|
|
13
|
+
</template>
|
|
14
|
+
</DefaultTheme.Layout>
|
|
15
|
+
</template>
|
package/src/cli.mjs
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import matter from 'gray-matter'
|
|
6
|
+
|
|
7
|
+
const args = process.argv.slice(2)
|
|
8
|
+
const command = args[0]
|
|
9
|
+
|
|
10
|
+
if (command === 'ticket') {
|
|
11
|
+
createTicket(args.slice(1))
|
|
12
|
+
} else {
|
|
13
|
+
console.log(`Usage:
|
|
14
|
+
vitepress-theme-pm ticket "Title" Create a new ticket
|
|
15
|
+
vitepress-theme-pm ticket "Title" --status doing --priority high --tags core,ui
|
|
16
|
+
|
|
17
|
+
Options:
|
|
18
|
+
--dir <path> Tickets directory (default: tickets)
|
|
19
|
+
--status <status> Initial status (default: backlog)
|
|
20
|
+
--priority <pri> Priority: critical, high, medium, low (default: medium)
|
|
21
|
+
--tags <tags> Comma-separated tags`)
|
|
22
|
+
process.exit(command ? 1 : 0)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getMaxTicketId(ticketsDir) {
|
|
26
|
+
if (!fs.existsSync(ticketsDir)) return 0
|
|
27
|
+
const files = fs.readdirSync(ticketsDir).filter(f => f.endsWith('.md'))
|
|
28
|
+
let max = 0
|
|
29
|
+
for (const file of files) {
|
|
30
|
+
const raw = fs.readFileSync(path.join(ticketsDir, file), 'utf-8')
|
|
31
|
+
const parsed = matter(raw)
|
|
32
|
+
const id = Number(parsed.data.id)
|
|
33
|
+
if (id > max) max = id
|
|
34
|
+
}
|
|
35
|
+
return max
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function parseArgs(args) {
|
|
39
|
+
let title = ''
|
|
40
|
+
let dir = 'tickets'
|
|
41
|
+
let status = 'backlog'
|
|
42
|
+
let priority = 'medium'
|
|
43
|
+
let tags = []
|
|
44
|
+
|
|
45
|
+
let i = 0
|
|
46
|
+
while (i < args.length) {
|
|
47
|
+
if (args[i] === '--dir') { dir = args[++i]; i++; continue }
|
|
48
|
+
if (args[i] === '--status') { status = args[++i]; i++; continue }
|
|
49
|
+
if (args[i] === '--priority') { priority = args[++i]; i++; continue }
|
|
50
|
+
if (args[i] === '--tags') { tags = args[++i].split(',').map(t => t.trim()).filter(Boolean); i++; continue }
|
|
51
|
+
if (!title) { title = args[i] }
|
|
52
|
+
i++
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return { title, dir, status, priority, tags }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function readTicketPrefix(siteDir) {
|
|
59
|
+
const boardPath = path.join(siteDir, 'board.md')
|
|
60
|
+
if (!fs.existsSync(boardPath)) return null
|
|
61
|
+
try {
|
|
62
|
+
const raw = fs.readFileSync(boardPath, 'utf-8')
|
|
63
|
+
const parsed = matter(raw)
|
|
64
|
+
return parsed.data.ticketPrefix || null
|
|
65
|
+
} catch {
|
|
66
|
+
return null
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function createTicket(args) {
|
|
71
|
+
const opts = parseArgs(args)
|
|
72
|
+
|
|
73
|
+
if (!opts.title) {
|
|
74
|
+
console.error('Error: title is required. Usage: vitepress-theme-pm ticket "My ticket title"')
|
|
75
|
+
process.exit(1)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const ticketsDir = path.resolve(process.cwd(), opts.dir)
|
|
79
|
+
if (!fs.existsSync(ticketsDir)) {
|
|
80
|
+
fs.mkdirSync(ticketsDir, { recursive: true })
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const id = getMaxTicketId(ticketsDir) + 1
|
|
84
|
+
const frontmatter = {
|
|
85
|
+
id,
|
|
86
|
+
title: opts.title,
|
|
87
|
+
status: opts.status,
|
|
88
|
+
priority: opts.priority,
|
|
89
|
+
}
|
|
90
|
+
if (opts.tags.length > 0) {
|
|
91
|
+
frontmatter.tags = opts.tags
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const content = matter.stringify('\n', frontmatter)
|
|
95
|
+
const filePath = path.join(ticketsDir, `${id}.md`)
|
|
96
|
+
fs.writeFileSync(filePath, content)
|
|
97
|
+
|
|
98
|
+
const prefix = readTicketPrefix(path.dirname(ticketsDir))
|
|
99
|
+
const displayId = prefix ? `${prefix}-${id}` : String(id)
|
|
100
|
+
|
|
101
|
+
console.log(`Created ${displayId}: ${opts.title}`)
|
|
102
|
+
console.log(` File: ${path.relative(process.cwd(), filePath)}`)
|
|
103
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, computed } from 'vue'
|
|
3
|
+
import { useData } from 'vitepress'
|
|
4
|
+
import type { Ticket, Column } from '../types'
|
|
5
|
+
import { useDragDrop } from '../composables/useDragDrop'
|
|
6
|
+
import { useTicketWriter } from '../composables/useTicketWriter'
|
|
7
|
+
import BoardColumn from './BoardColumn.vue'
|
|
8
|
+
import TicketDetail from './TicketDetail.vue'
|
|
9
|
+
import '../styles/board.css'
|
|
10
|
+
|
|
11
|
+
const { frontmatter } = useData()
|
|
12
|
+
|
|
13
|
+
const columns = computed<Column[]>(() => frontmatter.value.columns || [])
|
|
14
|
+
const ticketsDir = computed(() => frontmatter.value.ticketsDir || 'tickets')
|
|
15
|
+
const ticketPrefix = computed(() => frontmatter.value.ticketPrefix || '')
|
|
16
|
+
const defaultColumn = computed(() => frontmatter.value.defaultColumn || (columns.value.length > 0 ? columns.value[0].key : 'backlog'))
|
|
17
|
+
|
|
18
|
+
const tickets = ref<Ticket[]>([])
|
|
19
|
+
const selectedId = ref<number | null>(null)
|
|
20
|
+
const draftTicket = ref<Ticket | null>(null)
|
|
21
|
+
const filter = ref('')
|
|
22
|
+
|
|
23
|
+
const { writeTicket } = useTicketWriter()
|
|
24
|
+
|
|
25
|
+
// Load tickets from dev plugin or static JSON
|
|
26
|
+
if (typeof window !== 'undefined') {
|
|
27
|
+
const url = import.meta.env.DEV
|
|
28
|
+
? `/__vitepress_pm_tickets?dir=${encodeURIComponent(ticketsDir.value)}`
|
|
29
|
+
: `${import.meta.env.BASE_URL}__vitepress_pm_tickets/${encodeURIComponent(ticketsDir.value)}.json`
|
|
30
|
+
|
|
31
|
+
fetch(url)
|
|
32
|
+
.then(r => {
|
|
33
|
+
if (r.ok) return r.json()
|
|
34
|
+
throw new Error('not available')
|
|
35
|
+
})
|
|
36
|
+
.then((data: Ticket[]) => { tickets.value = data })
|
|
37
|
+
.catch(() => {})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function updateTicket(id: number, patch: Partial<Ticket>) {
|
|
41
|
+
tickets.value = tickets.value.map(t =>
|
|
42
|
+
t.id === id ? { ...t, ...patch } : t
|
|
43
|
+
)
|
|
44
|
+
const ticket = tickets.value.find(t => t.id === id)
|
|
45
|
+
if (ticket?.url) {
|
|
46
|
+
// Don't send url/id to the file writer
|
|
47
|
+
const { url: _url, id: _id, ...fields } = { ...patch } as any
|
|
48
|
+
if (Object.keys(fields).length > 0) {
|
|
49
|
+
writeTicket(ticket.url, fields)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function openNewTicket() {
|
|
55
|
+
draftTicket.value = {
|
|
56
|
+
id: 0,
|
|
57
|
+
title: 'New ticket',
|
|
58
|
+
status: defaultColumn.value,
|
|
59
|
+
priority: 'medium',
|
|
60
|
+
tags: [],
|
|
61
|
+
body: '',
|
|
62
|
+
url: '',
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function confirmCreate(draft: Ticket) {
|
|
67
|
+
if (import.meta.env.DEV) {
|
|
68
|
+
try {
|
|
69
|
+
const res = await fetch('/__vitepress_pm_create', {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
headers: { 'Content-Type': 'application/json' },
|
|
72
|
+
body: JSON.stringify({
|
|
73
|
+
dir: ticketsDir.value,
|
|
74
|
+
status: draft.status,
|
|
75
|
+
title: draft.title,
|
|
76
|
+
priority: draft.priority,
|
|
77
|
+
tags: draft.tags,
|
|
78
|
+
body: draft.body,
|
|
79
|
+
}),
|
|
80
|
+
})
|
|
81
|
+
if (!res.ok) throw new Error(await res.text())
|
|
82
|
+
const ticket: Ticket = await res.json()
|
|
83
|
+
tickets.value = [...tickets.value, ticket]
|
|
84
|
+
draftTicket.value = null
|
|
85
|
+
return
|
|
86
|
+
} catch (e) {
|
|
87
|
+
console.error('Failed to create ticket:', e)
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Production: create in-memory only
|
|
93
|
+
const maxId = tickets.value.reduce((m, t) => Math.max(m, t.id), 0)
|
|
94
|
+
const ticket: Ticket = {
|
|
95
|
+
id: maxId + 1,
|
|
96
|
+
title: draft.title,
|
|
97
|
+
status: draft.status,
|
|
98
|
+
priority: draft.priority,
|
|
99
|
+
tags: [...draft.tags],
|
|
100
|
+
body: draft.body,
|
|
101
|
+
url: '',
|
|
102
|
+
}
|
|
103
|
+
tickets.value = [...tickets.value, ticket]
|
|
104
|
+
draftTicket.value = null
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function deleteTicket(id: number) {
|
|
108
|
+
if (confirm('Delete this ticket?')) {
|
|
109
|
+
tickets.value = tickets.value.filter(t => t.id !== id)
|
|
110
|
+
if (selectedId.value === id) selectedId.value = null
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const filteredTickets = computed(() => {
|
|
115
|
+
if (!filter.value) return tickets.value
|
|
116
|
+
const q = filter.value.toLowerCase()
|
|
117
|
+
return tickets.value.filter(t =>
|
|
118
|
+
t.title.toLowerCase().includes(q) ||
|
|
119
|
+
t.tags.some(tag => tag.includes(q)) ||
|
|
120
|
+
formatId(t.id).toLowerCase().includes(q)
|
|
121
|
+
)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
const selectedTicket = computed(() =>
|
|
125
|
+
tickets.value.find(t => t.id === selectedId.value) || null
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
function columnTickets(key: string) {
|
|
129
|
+
return filteredTickets.value.filter(t => t.status === key)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function formatId(id: number): string {
|
|
133
|
+
return ticketPrefix.value ? `${ticketPrefix.value}-${id}` : String(id)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const { dragOverColumn, handleDragStart, handleDragEnd, handleDragOver, handleDragLeave, handleDrop } =
|
|
137
|
+
useDragDrop((ticketId, targetColumn) => {
|
|
138
|
+
updateTicket(Number(ticketId), { status: targetColumn })
|
|
139
|
+
})
|
|
140
|
+
</script>
|
|
141
|
+
|
|
142
|
+
<template>
|
|
143
|
+
<div style="display: flex; flex-direction: column; height: calc(100vh - var(--vp-nav-height) - 1px); overflow: hidden">
|
|
144
|
+
<!-- Filter bar -->
|
|
145
|
+
<div style="padding: 8px 16px; border-bottom: 1px solid #2d3748; flex-shrink: 0; display: flex; align-items: center; gap: 8px">
|
|
146
|
+
<input
|
|
147
|
+
v-model="filter"
|
|
148
|
+
placeholder="Filter tickets..."
|
|
149
|
+
style="font-size: 12px; padding: 5px 10px; background: #171923; border: 1px solid #2d3748; border-radius: 5px; color: #e2e8f0; outline: none; width: 200px"
|
|
150
|
+
>
|
|
151
|
+
<button
|
|
152
|
+
title="New ticket"
|
|
153
|
+
style="font-size: 13px; padding: 4px 12px; background: #2d3748; border: 1px solid #4a5568; border-radius: 5px; color: #e2e8f0; cursor: pointer; font-weight: 600; line-height: 1.2"
|
|
154
|
+
@click="openNewTicket"
|
|
155
|
+
>+ New</button>
|
|
156
|
+
</div>
|
|
157
|
+
|
|
158
|
+
<!-- Columns -->
|
|
159
|
+
<div class="board-columns" style="flex: 1; display: flex; overflow: auto; padding: 12px 8px">
|
|
160
|
+
<BoardColumn
|
|
161
|
+
v-for="col in columns"
|
|
162
|
+
:key="col.key"
|
|
163
|
+
:column="col"
|
|
164
|
+
:tickets="columnTickets(col.key)"
|
|
165
|
+
:selected-id="selectedId"
|
|
166
|
+
:ticket-prefix="ticketPrefix"
|
|
167
|
+
:is-over="dragOverColumn === col.key"
|
|
168
|
+
@select="(id: number) => selectedId = selectedId === id ? null : id"
|
|
169
|
+
@dragstart="(e: DragEvent, id: number) => handleDragStart(e, String(id))"
|
|
170
|
+
@dragend="handleDragEnd"
|
|
171
|
+
@dragover="(e: DragEvent) => handleDragOver(e, col.key)"
|
|
172
|
+
@dragleave="handleDragLeave"
|
|
173
|
+
@drop="(e: DragEvent) => handleDrop(e, col.key)"
|
|
174
|
+
/>
|
|
175
|
+
</div>
|
|
176
|
+
|
|
177
|
+
<!-- Create modal -->
|
|
178
|
+
<TicketDetail
|
|
179
|
+
v-if="draftTicket"
|
|
180
|
+
:ticket="draftTicket"
|
|
181
|
+
:columns="columns"
|
|
182
|
+
:ticket-prefix="ticketPrefix"
|
|
183
|
+
:create-mode="true"
|
|
184
|
+
@close="draftTicket = null"
|
|
185
|
+
@update="(_id: number, patch: Partial<Ticket>) => { draftTicket = { ...draftTicket!, ...patch } }"
|
|
186
|
+
@create="confirmCreate(draftTicket!)"
|
|
187
|
+
/>
|
|
188
|
+
|
|
189
|
+
<!-- Edit modal -->
|
|
190
|
+
<TicketDetail
|
|
191
|
+
v-else-if="selectedTicket"
|
|
192
|
+
:ticket="selectedTicket"
|
|
193
|
+
:columns="columns"
|
|
194
|
+
:ticket-prefix="ticketPrefix"
|
|
195
|
+
@close="selectedId = null"
|
|
196
|
+
@update="updateTicket"
|
|
197
|
+
@delete="deleteTicket"
|
|
198
|
+
/>
|
|
199
|
+
</div>
|
|
200
|
+
</template>
|