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"
10)
11
12type conf struct {
13 style string
14 header string
15 menu []link
16 footer string
17 generateGitWorktree bool
18}
19
20var defaultConf = map[string]any{
21 "style": "simple.min.css",
22 "header": "<h1>TITLE</h1>",
23 "menu": []link{
24 {Display: "🏠 Home", Link: "/"},
25 {Display: "📖 Readme", Link: "/README.html"},
26 {Display: "🐞 Issues", Link: "/boards/issues.html"},
27 {Display: "⚖ Licence", Link: "/LICENCE.html"},
28 },
29 "footer": "<p>Clone with <code>git clone ssh://INSTANCE_URL/PROJECT_NAME</code></p><small>Hosted with ❤️ by Gitroot</small>",
30 "generateGitWorktree": true,
31}
32
33var defaultRun = []gitroot.PluginRun{{
34 Path: "**/*",
35 Branch: []string{"main"},
36 When: gitroot.PluginRunWhenAll,
37 Write: gitroot.PluginWrite{
38 Git: []gitroot.PluginWriteRight{{
39 Path: "index.md",
40 Can: []gitroot.PluginWriteRightCan{gitroot.PluginWriteRightCanAdd},
41 }},
42 Web: []gitroot.PluginWriteRight{{
43 Path: "**/*",
44 Can: gitroot.PluginWriteRightCanAll,
45 }},
46 },
47 Configuration: defaultConf,
48}}
49
50type link struct {
51 Link string `json:"link"`
52 Display string `json:"display"`
53}
54
55func (p *Plugin) NewConf(serializedConf string) *conf {
56 jsonConf := gjson.Parse(serializedConf)
57 menus := []link{}
58 for _, l := range jsonConf.Get("menu").Array() {
59 menus = append(menus, link{
60 Link: l.Get("link").String(),
61 Display: l.Get("display").String(),
62 })
63 }
64 return &conf{
65 style: jsonConf.Get("style").String(),
66 header: jsonConf.Get("header").String(),
67 menu: menus,
68 footer: jsonConf.Get("footer").String(),
69 generateGitWorktree: jsonConf.Get("generateGitWorktree").Bool(),
70 }
71}