Merge branch '2025-redesign-blog-system' into 2025-redesign
This commit is contained in:
93
flake.lock
generated
93
flake.lock
generated
@@ -1,24 +1,6 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1694529238,
|
||||
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils_2": {
|
||||
"locked": {
|
||||
"lastModified": 1667395993,
|
||||
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
|
||||
@@ -54,28 +36,6 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"gomod2nix": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": [
|
||||
"templ",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1722589758,
|
||||
"narHash": "sha256-sbbA8b6Q2vB/t/r1znHawoXLysCyD4L/6n6/RykiSnA=",
|
||||
"owner": "nix-community",
|
||||
"repo": "gomod2nix",
|
||||
"rev": "4e08ca09253ef996bd4c03afa383b23e35fe28a1",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "gomod2nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1734424634,
|
||||
@@ -92,18 +52,34 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"nixpkgs-unstable": {
|
||||
"locked": {
|
||||
"lastModified": 1724322575,
|
||||
"narHash": "sha256-kRYwAdYsaICNb2WYcWtBFG6caSuT0v/vTAyR8ap0IR0=",
|
||||
"lastModified": 1735471104,
|
||||
"narHash": "sha256-0q9NGQySwDQc7RhAV2ukfnu7Gxa5/ybJ2ANT8DQrQrs=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "2a02822b466ffb9f1c02d07c5dd6b96d08b56c6b",
|
||||
"rev": "88195a94f390381c6afcdaa933c2f6ff93959cb4",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "release-24.05",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1735669367,
|
||||
"narHash": "sha256-tfYRbFhMOnYaM4ippqqid3BaLOXoFNdImrfBfCp4zn0=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "edf04b75c13c2ac0e54df5ec5c543e300f76f1c9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-24.11",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
@@ -114,46 +90,31 @@
|
||||
"templ": "templ"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"templ": {
|
||||
"inputs": {
|
||||
"gitignore": "gitignore",
|
||||
"gomod2nix": "gomod2nix",
|
||||
"nixpkgs": "nixpkgs_2",
|
||||
"nixpkgs-unstable": "nixpkgs-unstable",
|
||||
"xc": "xc"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1725786353,
|
||||
"narHash": "sha256-lU8aVTw73HX0lNGPyD8Xnvtnr2VFTXv/S6xCVn6Lg74=",
|
||||
"lastModified": 1735817715,
|
||||
"narHash": "sha256-kTP/DLnou3KETZRtvHdeiMmRW6xldgZBAn9O9p9s/MA=",
|
||||
"owner": "a-h",
|
||||
"repo": "templ",
|
||||
"rev": "e2511cd57e5ecd28ce6e3d944c87f1e31e20b596",
|
||||
"rev": "e54517eb7d8a7d9ef67d43177709a0ca26235e43",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "a-h",
|
||||
"ref": "v0.2.778",
|
||||
"ref": "v0.3.819",
|
||||
"repo": "templ",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"xc": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils_2",
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": [
|
||||
"templ",
|
||||
"nixpkgs"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
description = "My development environment";
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
templ.url = "github:a-h/templ?ref=v0.2.778";
|
||||
templ.url = "github:a-h/templ?ref=v0.3.819";
|
||||
};
|
||||
outputs = {
|
||||
self,
|
||||
@@ -50,6 +50,7 @@
|
||||
gotools
|
||||
delve
|
||||
(templ system)
|
||||
gopls
|
||||
|
||||
# Sqlite tools
|
||||
sqlite
|
||||
|
||||
8
go.mod
8
go.mod
@@ -6,4 +6,10 @@ require forge.capytal.company/loreddev/x v0.0.0
|
||||
|
||||
replace forge.capytal.company/loreddev/x => ./x
|
||||
|
||||
require github.com/a-h/templ v0.2.793
|
||||
require (
|
||||
github.com/a-h/templ v0.3.819
|
||||
github.com/yuin/goldmark v1.7.8
|
||||
github.com/yuin/goldmark-meta v1.1.0
|
||||
)
|
||||
|
||||
require gopkg.in/yaml.v2 v2.3.0 // indirect
|
||||
|
||||
10
go.sum
10
go.sum
@@ -1,4 +1,14 @@
|
||||
github.com/a-h/templ v0.2.793 h1:Io+/ocnfGWYO4VHdR0zBbf39PQlnzVCVVD+wEEs6/qY=
|
||||
github.com/a-h/templ v0.2.793/go.mod h1:lq48JXoUvuQrU0VThrK31yFwdRjTCnIE5bcPCM9IP1w=
|
||||
github.com/a-h/templ v0.3.819 h1:KDJ5jTFN15FyJnmSmo2gNirIqt7hfvBD2VXVDTySckM=
|
||||
github.com/a-h/templ v0.3.819/go.mod h1:iDJKJktpttVKdWoTkRNNLcllRI+BlpopJc+8au3gOUo=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
|
||||
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
||||
github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc=
|
||||
github.com/yuin/goldmark-meta v1.1.0/go.mod h1:U4spWENafuA7Zyg+Lj5RqK/MF+ovMYtBvXi1lBb2VP0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -11,24 +13,58 @@ import (
|
||||
"forge.capytal.company/capytal/www/templates/layouts"
|
||||
|
||||
"forge.capytal.company/loreddev/x/groute/router/rerrors"
|
||||
"forge.capytal.company/loreddev/x/groute/router"
|
||||
"github.com/yuin/goldmark"
|
||||
"github.com/yuin/goldmark/extension"
|
||||
"github.com/yuin/goldmark/parser"
|
||||
"github.com/yuin/goldmark-meta"
|
||||
)
|
||||
|
||||
type EntryTemplate func(html []byte) templ.Component
|
||||
|
||||
type Blog struct {
|
||||
repo string
|
||||
owner string
|
||||
endpoint string
|
||||
|
||||
md goldmark.Markdown
|
||||
entryTemplate EntryTemplate
|
||||
}
|
||||
|
||||
func NewBlog(owner, repo, endpoint string) *Blog {
|
||||
type BlogOptions struct {
|
||||
EntryTemplate EntryTemplate
|
||||
}
|
||||
|
||||
func NewBlog(owner, repo, endpoint string, opts ...BlogOptions) *Blog {
|
||||
/*
|
||||
opt := BlogOptions{}
|
||||
if len(opts) > 0 {
|
||||
opt = opts[0]
|
||||
}
|
||||
*/
|
||||
|
||||
u, err := url.Parse(endpoint)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Blog Forgejo endpoint is not a valid URL: %v", err))
|
||||
}
|
||||
return &Blog{repo: repo, owner: owner, endpoint: u.String()}
|
||||
|
||||
md := goldmark.New(
|
||||
goldmark.WithExtensions(extension.GFM, meta.Meta),
|
||||
goldmark.WithParserOptions(parser.WithAutoHeadingID()),
|
||||
)
|
||||
|
||||
return &Blog{
|
||||
repo: repo,
|
||||
owner: owner,
|
||||
endpoint: u.String(),
|
||||
md: md,
|
||||
// entryTemplate: opt.EntryTemplate,
|
||||
entryTemplate: template,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Blog) Routes() http.Handler {
|
||||
r := http.NewServeMux()
|
||||
func (p *Blog) Routes() router.Router {
|
||||
r := router.NewRouter()
|
||||
|
||||
r.HandleFunc("/{entry...}", func(w http.ResponseWriter, r *http.Request) {
|
||||
pv := r.PathValue("entry")
|
||||
@@ -80,7 +116,24 @@ func (p *Blog) blogEntry(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(body)
|
||||
buf := bytes.NewBuffer([]byte(""))
|
||||
err := p.md.Convert(body, buf)
|
||||
if err != nil {
|
||||
rerrors.InternalError(errors.New("failed to render markdown"), err).ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
html, err := io.ReadAll(buf)
|
||||
if err != nil {
|
||||
rerrors.InternalError(errors.New("failed to read markdown html")).ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
err = p.entryTemplate(html).Render(r.Context(), w)
|
||||
if err != nil {
|
||||
rerrors.InternalError(errors.New("failed to write response"), err).ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Blog) get(endpoint string) (http.Header, []byte, *rerrors.RouteError) {
|
||||
@@ -120,3 +173,13 @@ type forgejoFile struct {
|
||||
LastCommitSha string `json:"last_commit_sha"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
templ template(html []byte) {
|
||||
@layouts.Page() {
|
||||
<div class="w-100% py-10rem flex justify-center">
|
||||
<main class="w-60vw">
|
||||
@templ.Raw(string(html))
|
||||
</main>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,5 +15,8 @@ func Routes(log *slog.Logger) router.Router {
|
||||
r.Handle("/", &IndexPage{})
|
||||
r.Handle("/about", &AboutPage{})
|
||||
|
||||
b := NewBlog("dot013", "blog", "https://forge.capytal.company/api/v1")
|
||||
r.Handle("/blog/", b.Routes())
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
9
makefile
9
makefile
@@ -1,4 +1,5 @@
|
||||
PORT?=8080
|
||||
TEMPL_VERSION=v0.3.819
|
||||
|
||||
lint: build/templ
|
||||
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 run
|
||||
@@ -10,13 +11,13 @@ lint/fix: build/templ
|
||||
|
||||
fmt: build/templ
|
||||
go fmt ./.
|
||||
go run github.com/a-h/templ/cmd/templ@v0.2.707 fmt .
|
||||
go run github.com/a-h/templ/cmd/templ@$(TEMPL_VERSION) fmt .
|
||||
go run mvdan.cc/gofumpt@v0.7.0 -l -w .
|
||||
go run github.com/segmentio/golines@v0.12.2 -w .
|
||||
go run golang.org/x/tools/cmd/goimports@v0.26.0 -w -l .
|
||||
|
||||
dev/templ:
|
||||
go run github.com/a-h/templ/cmd/templ@v0.2.707 generate --watch \
|
||||
go run github.com/a-h/templ/cmd/templ@$(TEMPL_VERSION) generate --watch \
|
||||
--proxy=http://localhost:$(PORT) \
|
||||
--proxybind="0.0.0.0" \
|
||||
--open-browser=false
|
||||
@@ -33,7 +34,7 @@ dev/server:
|
||||
|
||||
dev/sync_assets:
|
||||
go run github.com/air-verse/air@v1.52.2 \
|
||||
--build.cmd "go run github.com/a-h/templ/cmd/templ@v0.2.707 generate --notify-proxy" \
|
||||
--build.cmd "go run github.com/a-h/templ/cmd/templ@$(TEMPL_VERSION) generate --notify-proxy" \
|
||||
--build.bin "true" \
|
||||
--build.delay "100" \
|
||||
--build.exclude_dir "" \
|
||||
@@ -48,7 +49,7 @@ dev:
|
||||
make -j4 dev/templ dev/server dev/sync_assets dev/assets/css
|
||||
|
||||
build/templ:
|
||||
go run github.com/a-h/templ/cmd/templ@v0.2.707 generate
|
||||
go run github.com/a-h/templ/cmd/templ@$(TEMPL_VERSION) generate
|
||||
|
||||
build/app:
|
||||
go build -o ./.dist/app .
|
||||
|
||||
2
x
2
x
Submodule x updated: c0854dea2c...d00fd5dbbe
Reference in New Issue
Block a user