Go licenses as markdown template
This commit is contained in:
parent
d37958fc37
commit
614f15e1f1
12 changed files with 1064 additions and 1587 deletions
|
|
@ -5,11 +5,11 @@ Gestion des membres & sympathisants pour le POP Vaud
|
||||||
## Récupérer les licences des modules Go
|
## Récupérer les licences des modules Go
|
||||||
Installer l'utilitaire (si pas déjà fait)
|
Installer l'utilitaire (si pas déjà fait)
|
||||||
```bash
|
```bash
|
||||||
./licences/install_tool.sh
|
./licenses/install_tool.sh
|
||||||
```
|
```
|
||||||
Générer le fichier de licences (à faire avant build si nouveau module)
|
Générer le fichier de licences (à faire avant build si nouveau module)
|
||||||
```bash
|
```bash
|
||||||
./licences/fetch_licences.sh
|
./licenses/fetch_licenses.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
## Générer une build
|
## Générer une build
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.readonly.ch/bouzoure/pop-camarades/helpers"
|
"git.readonly.ch/bouzoure/pop-camarades/helpers"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/yuin/goldmark"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetColorMode(c *fiber.Ctx) error {
|
func SetColorMode(c *fiber.Ctx) error {
|
||||||
|
|
@ -30,8 +32,25 @@ func SetColorMode(c *fiber.Ctx) error {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
func Licences(c *fiber.Ctx) error {
|
func Licenses(c *fiber.Ctx) error {
|
||||||
return c.Render("licences", fiber.Map{
|
staticFS, err := helpers.GetEmbeddedFS("static")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
source, err := staticFS.ReadFile("static/licenses.md")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var buf bytes.Buffer
|
||||||
|
err = goldmark.Convert(source, &buf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Render("licenses", fiber.Map{
|
||||||
"PageTitle": "Licences",
|
"PageTitle": "Licences",
|
||||||
|
"Markdown": buf.String(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
go.mod
1
go.mod
|
|
@ -65,6 +65,7 @@ require (
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
github.com/valyala/fasthttp v1.61.0 // indirect
|
github.com/valyala/fasthttp v1.61.0 // indirect
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||||
|
github.com/yuin/goldmark v1.7.11 // indirect
|
||||||
go.opencensus.io v0.24.0 // indirect
|
go.opencensus.io v0.24.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect
|
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect
|
||||||
golang.org/x/net v0.39.0 // indirect
|
golang.org/x/net v0.39.0 // indirect
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -223,6 +223,8 @@ github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZ
|
||||||
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
||||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
|
github.com/yuin/goldmark v1.7.11 h1:ZCxLyDMtz0nT2HFfsYG8WZ47Trip2+JyLysKcMYE5bo=
|
||||||
|
github.com/yuin/goldmark v1.7.11/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
|
||||||
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
|
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
|
||||||
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
|
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
|
||||||
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
|
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
|
||||||
|
|
|
||||||
25
helpers/embed.go
Normal file
25
helpers/embed.go
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
package helpers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var embeddedFS = make(map[string]*embed.FS)
|
||||||
|
|
||||||
|
func AddEmbeddedFS(key string, fs *embed.FS) {
|
||||||
|
embeddedFS[key] = fs
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetEmbeddedFS(key string) (*embed.FS, error) {
|
||||||
|
var fs *embed.FS
|
||||||
|
|
||||||
|
for k, v := range embeddedFS {
|
||||||
|
if strings.EqualFold(k, key) {
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fs, fmt.Errorf("embedded filesystem not found")
|
||||||
|
}
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
{% extends "layouts/main.html" %}
|
|
||||||
|
|
||||||
{% block main %}
|
|
||||||
<div class="container">
|
|
||||||
{{ range . }}
|
|
||||||
<div class="my-5">
|
|
||||||
<span class="h3 my-3">
|
|
||||||
{{ .Name }}
|
|
||||||
</span>
|
|
||||||
<ul class="list-group my-3">
|
|
||||||
<li class="list-group-item">
|
|
||||||
<b>Version:</b> {{ .Version }}
|
|
||||||
</li>
|
|
||||||
<li class="list-group-item">
|
|
||||||
<b>License:</b>
|
|
||||||
{{ if ne .LicenseURL "Unknown" }}
|
|
||||||
<a href="{{ .LicenseURL }}">
|
|
||||||
{{ .LicenseName }}
|
|
||||||
</a>
|
|
||||||
{{ else }}
|
|
||||||
{{ .LicenseName }}
|
|
||||||
{{ end }}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<pre>{{ .LicenseText }}</pre>
|
|
||||||
</div>
|
|
||||||
{{ end }}
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
|
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
|
||||||
TPL_LOCATION="$SCRIPT_DIR/template.html"
|
TPL_LOCATION="$SCRIPT_DIR/template.md"
|
||||||
STATIC_LOCATION="$SCRIPT_DIR/../views/licences.html"
|
STATIC_LOCATION="$SCRIPT_DIR/../static/licenses.md"
|
||||||
PROJECT_URL="git.readonly.ch/bouzoure/pop-camarades"
|
PROJECT_URL="git.readonly.ch/bouzoure/pop-camarades"
|
||||||
|
|
||||||
go-licenses report "$PROJECT_URL" --template "$TPL_LOCATION" > "$STATIC_LOCATION"
|
go-licenses report "$PROJECT_URL" --template "$TPL_LOCATION" > "$STATIC_LOCATION"
|
||||||
15
licenses/template.md
Normal file
15
licenses/template.md
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
{{ range . }}
|
||||||
|
## {{ .Name }}
|
||||||
|
|
||||||
|
* Name: {{ .Name }}
|
||||||
|
* Version: {{ .Version }}
|
||||||
|
{{ if ne .LicenseURL "Unknown" }}
|
||||||
|
* License: [{{ .LicenseName }}]({{ .LicenseURL }})
|
||||||
|
{{ else }}
|
||||||
|
* License: {{ .LicenseName }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
```
|
||||||
|
{{ .LicenseText }}
|
||||||
|
```
|
||||||
|
{{ end }}
|
||||||
8
main.go
8
main.go
|
|
@ -28,6 +28,10 @@ var embedViews embed.FS
|
||||||
func main() {
|
func main() {
|
||||||
log := helpers.GetLogger()
|
log := helpers.GetLogger()
|
||||||
|
|
||||||
|
// Add embedded filesystems to shared state
|
||||||
|
helpers.AddEmbeddedFS("static", &embedStatic)
|
||||||
|
helpers.AddEmbeddedFS("views", &embedViews)
|
||||||
|
|
||||||
// Fetch app config
|
// Fetch app config
|
||||||
config, err := helpers.GetConfig()
|
config, err := helpers.GetConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -109,8 +113,8 @@ func main() {
|
||||||
app.Post("/set-color-mode", controllers.SetColorMode)
|
app.Post("/set-color-mode", controllers.SetColorMode)
|
||||||
|
|
||||||
// Licences page
|
// Licences page
|
||||||
app.Use("/licences", middlewares.TemplatesMiddleware)
|
app.Use("/licenses", middlewares.TemplatesMiddleware)
|
||||||
app.Get("/licences", controllers.Licences)
|
app.Get("/licenses", controllers.Licenses)
|
||||||
|
|
||||||
// Security middlewares
|
// Security middlewares
|
||||||
app.Use(middlewares.SavedSessionMiddleware)
|
app.Use(middlewares.SavedSessionMiddleware)
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
20
views/licenses.html
Normal file
20
views/licenses.html
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
{% extends "layouts/main.html" %}
|
||||||
|
|
||||||
|
{% block main %}
|
||||||
|
<div id="licenses" class="container-fluid p-3">
|
||||||
|
{{ Markdown|safe }}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block stylesheet %}
|
||||||
|
<style>
|
||||||
|
#licenses h2 {
|
||||||
|
font-weight: bold;
|
||||||
|
margin: 15px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#licenses p {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endblock %}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue