GitRoot
craft your forge, build your project, grow your community freely
1// SPDX-FileCopyrightText: 2025 Romain Maneschi <romain@gitroot.dev>
2//
3// SPDX-License-Identifier: EUPL-1.2
4
5package main
6
7import (
8 "github.com/tidwall/gjson"
9 gitroot "gitroot.dev/libs/golang/plugin/model"
10)
11
12type conf struct {
13 style string
14 header string
15 menu []link
16 footer string
17 generateGitWorktree bool
18 branchesDir string
19}
20
21var defaultConf = map[string]any{
22 "style": "simple.min.css",
23 "header": "<h1>TITLE</h1>",
24 "menu": []link{
25 {Display: "🏠 Home", Link: "/"},
26 {Display: "📖 Readme", Link: "/README.html"},
27 {Display: "🐞 Issues", Link: "/boards/issues.html"},
28 {Display: "⚖ Licence", Link: "/LICENCE.html"},
29 },
30 "footer": "<p>Clone with <code>git clone ssh://INSTANCE_URL/PROJECT_NAME</code></p><small>Hosted with ❤️ by Gitroot</small>",
31 "generateGitWorktree": true,
32 "branchesDir": "branches",
33}
34
35var defaultRun = []gitroot.PluginRun{{
36 Path: "**/*",
37 Branch: []string{"main"},
38 When: gitroot.PluginRunWhenAll,
39 Write: gitroot.PluginWrite{
40 Git: []gitroot.PluginWriteRight{{
41 Path: "index.md",
42 Can: []gitroot.PluginWriteRightCan{gitroot.PluginWriteRightCanAdd},
43 }},
44 Web: []gitroot.PluginWriteRight{{
45 Path: "**/*",
46 Can: gitroot.PluginWriteRightCanAll,
47 }},
48 },
49 Configuration: defaultConf,
50}, {
51 Path: "**/*",
52 Branch: []string{"*", "!main"},
53 When: gitroot.PluginRunWhenAll,
54 Write: gitroot.PluginWrite{
55 Git: []gitroot.PluginWriteRight{},
56 Web: []gitroot.PluginWriteRight{{
57 Path: "branches/**/*",
58 Can: gitroot.PluginWriteRightCanAll,
59 }},
60 },
61 Configuration: defaultConf,
62}}
63
64type link struct {
65 Link string `json:"link"`
66 Display string `json:"display"`
67}
68
69func (p *Plugin) NewConf(serializedConf string) *conf {
70 jsonConf := gjson.Parse(serializedConf)
71 menus := []link{}
72 for _, l := range jsonConf.Get("menu").Array() {
73 menus = append(menus, link{
74 Link: l.Get("link").String(),
75 Display: l.Get("display").String(),
76 })
77 }
78 return &conf{
79 style: jsonConf.Get("style").String(),
80 header: jsonConf.Get("header").String(),
81 menu: menus,
82 footer: jsonConf.Get("footer").String(),
83 generateGitWorktree: jsonConf.Get("generateGitWorktree").Bool(),
84 branchesDir: jsonConf.Get("branchesDir").String(),
85 }
86}