Shiz innit

This commit is contained in:
Maximilian Friedersdorff 2025-06-01 21:27:08 +01:00
parent 3ad3666002
commit 2c0a3c7d80
8 changed files with 25 additions and 14 deletions

View file

@ -4,12 +4,14 @@ import (
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"os"
"gitea.gwairfelin.com/max/gonotes/internal/conf" "forgejo.gwairfelin.com/max/gonotes/internal/conf"
"gitea.gwairfelin.com/max/gonotes/internal/notes/views" "forgejo.gwairfelin.com/max/gonotes/internal/notes/views"
) )
func main() { func main() {
os.Mkdir("./foobardir", os.ModeDir|os.ModePerm)
conf.LoadConfig("./conf.toml") conf.LoadConfig("./conf.toml")
router := http.NewServeMux() router := http.NewServeMux()

4
go.mod
View file

@ -1,10 +1,10 @@
module gitea.gwairfelin.com/max/gonotes module forgejo.gwairfelin.com/max/gonotes
go 1.23.5 go 1.23.5
require github.com/yuin/goldmark v1.7.8 require github.com/yuin/goldmark v1.7.8
require ( require (
gitea.gwairfelin.com/max/gispatcho v0.1.1 forgejo.gwairfelin.com/max/gispatcho v0.1.2
github.com/pelletier/go-toml/v2 v2.2.3 github.com/pelletier/go-toml/v2 v2.2.3
) )

4
go.sum
View file

@ -1,5 +1,5 @@
gitea.gwairfelin.com/max/gispatcho v0.1.1 h1:8Zv6UH046mSSLdf0PqpNRK6DACuWJfgBSUiWhMW0sMY= forgejo.gwairfelin.com/max/gispatcho v0.1.2 h1:z6H3Fe3L/c+TxVzIc2xQd96zmSh7b1Mkmeh+6OKZLGk=
gitea.gwairfelin.com/max/gispatcho v0.1.1/go.mod h1:TRhxU+uNv+nIcFIxy2jl30DPbcM5Yib0S/cpLXws5iM= forgejo.gwairfelin.com/max/gispatcho v0.1.2/go.mod h1:yt8U7rLn1yUCApGiJ3YKLN5VSpsttJs68BQBT7caTcM=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=

View file

@ -6,6 +6,7 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"path"
"path/filepath" "path/filepath"
"github.com/pelletier/go-toml/v2" "github.com/pelletier/go-toml/v2"
@ -19,6 +20,12 @@ type Asset struct {
func (asset *Asset) FetchIfNotExists(staticPath string) { func (asset *Asset) FetchIfNotExists(staticPath string) {
destPath := filepath.Join(staticPath, asset.Path) destPath := filepath.Join(staticPath, asset.Path)
err := os.MkdirAll(path.Dir(destPath), os.ModeDir|0777)
if err != nil {
log.Printf("Couldn't create parent dirs of %s\n", destPath)
panic(err)
}
out, err := os.OpenFile( out, err := os.OpenFile(
destPath, destPath,
os.O_WRONLY|os.O_CREATE|os.O_EXCL, os.O_WRONLY|os.O_CREATE|os.O_EXCL,
@ -75,6 +82,8 @@ func LoadConfig(path string) {
log.Fatal(err) log.Fatal(err)
} }
os.Mkdir(Conf.Static.Dir, os.FileMode(750))
for _, asset := range Conf.Static.Assets { for _, asset := range Conf.Static.Assets {
asset.FetchIfNotExists(Conf.Static.Dir) asset.FetchIfNotExists(Conf.Static.Dir)
} }

View file

@ -10,7 +10,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"gitea.gwairfelin.com/max/gonotes/internal/conf" "forgejo.gwairfelin.com/max/gonotes/internal/conf"
"github.com/yuin/goldmark" "github.com/yuin/goldmark"
"github.com/yuin/goldmark/extension" "github.com/yuin/goldmark/extension"
) )

View file

@ -7,10 +7,10 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
urls "gitea.gwairfelin.com/max/gispatcho" urls "forgejo.gwairfelin.com/max/gispatcho"
"gitea.gwairfelin.com/max/gonotes/internal/conf" "forgejo.gwairfelin.com/max/gonotes/internal/conf"
"gitea.gwairfelin.com/max/gonotes/internal/notes" "forgejo.gwairfelin.com/max/gonotes/internal/notes"
"gitea.gwairfelin.com/max/gonotes/internal/templ" "forgejo.gwairfelin.com/max/gonotes/internal/templ"
) )
var myurls urls.URLs var myurls urls.URLs
@ -55,7 +55,7 @@ func edit(w http.ResponseWriter, r *http.Request) {
} }
urlSave := myurls.Reverse("save", urls.Repl{"note": title}) urlSave := myurls.Reverse("save", urls.Repl{"note": title})
context := templ.Ctx{"note": note, "urlSave": urlSave} context := templ.Ctx{"note": note, "urlSave": urlSave, "text": string(note.Body)}
err = templ.RenderTemplate(w, "edit.tmpl.html", context) err = templ.RenderTemplate(w, "edit.tmpl.html", context)
if err != nil { if err != nil {
log.Print(err.Error()) log.Print(err.Error())

View file

@ -6,7 +6,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"gitea.gwairfelin.com/max/gonotes/internal/conf" "forgejo.gwairfelin.com/max/gonotes/internal/conf"
) )
type Ctx map[string]any type Ctx map[string]any

View file

@ -6,7 +6,7 @@
<label for="noteBodyInput" class="form-label">Note</label> <label for="noteBodyInput" class="form-label">Note</label>
<div class="border rounded rounded-1"> <div class="border rounded rounded-1">
<div id="toolbar"></div> <div id="toolbar"></div>
<textarea class="form-control" id="noteBodyInput" name="body" aria-described-by="bodyHelp">{{.noteBody}}</textarea> <textarea class="form-control" id="noteBodyInput" name="body" aria-described-by="bodyHelp">{{.text}}</textarea>
</div> </div>
<div id="bodyHelp" class="form-text">Enter your note content in markdown</div> <div id="bodyHelp" class="form-text">Enter your note content in markdown</div>
</div> </div>