diff options
| author | Xe Iaso <me@xeiaso.net> | 2023-10-22 12:44:42 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2023-10-22 12:44:42 -0400 |
| commit | ded584e1e7455e64440c744957dd6fa006c2ac42 (patch) | |
| tree | 5a100b527cf94f551b1ee517c65dbcb5e55afd3b | |
| parent | 3cff11317d33da8b649c64aec3cb04df30616a26 (diff) | |
| download | xesite-ded584e1e7455e64440c744957dd6fa006c2ac42.tar.xz xesite-ded584e1e7455e64440c744957dd6fa006c2ac42.zip | |
internal/lume: annotate website commit in footer
Signed-off-by: Xe Iaso <me@xeiaso.net>
| -rw-r--r-- | cmd/xesite/main.go | 31 | ||||
| -rw-r--r-- | internal/lume/lume.go | 34 | ||||
| -rw-r--r-- | lume/src/_data/.gitignore | 1 | ||||
| -rw-r--r-- | lume/src/_includes/base.njk | 2 |
4 files changed, 45 insertions, 23 deletions
diff --git a/cmd/xesite/main.go b/cmd/xesite/main.go index daf831e..1a6284d 100644 --- a/cmd/xesite/main.go +++ b/cmd/xesite/main.go @@ -113,24 +113,23 @@ func main() { http.Redirect(w, r, "/static/site.webmanifest", http.StatusMovedPermanently) }) - if *devel { - mux.HandleFunc("/.within/hook/github", func(w http.ResponseWriter, r *http.Request) { - if err := fs.Update(r.Context()); err != nil { - if err == git.NoErrAlreadyUpToDate { - w.WriteHeader(http.StatusOK) - fmt.Fprintln(w, "already up to date") - return - } - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) + + gh := &GitHubWebhook{fs: fs} + s := hmacsig.Handler256(gh, *githubSecret) + mux.Handle("/.within/hook/github", s) + + mux.HandleFunc("/.within/hook/localonlybegood", func(w http.ResponseWriter, r *http.Request) { + if err := fs.Update(r.Context()); err != nil { + if err == git.NoErrAlreadyUpToDate { + w.WriteHeader(http.StatusOK) + fmt.Fprintln(w, "already up to date") return } - }) - } else { - gh := &GitHubWebhook{fs: fs} - s := hmacsig.Handler256(gh, *githubSecret) - mux.Handle("/.within/hook/github", s) - } + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + }) mux.Handle("/.within/hook/patreon", &PatreonWebhook{fs: fs}) diff --git a/internal/lume/lume.go b/internal/lume/lume.go index 8188488..40eafd9 100644 --- a/internal/lume/lume.go +++ b/internal/lume/lume.go @@ -123,6 +123,8 @@ func New(ctx context.Context, o *Options) (*FS, error) { dur := time.Since(t0) slog.Debug("repo cloned", "in", dur.String()) + siteCommit := "development" + fs := &FS{ repo: repo, repoDir: repoDir, @@ -134,6 +136,14 @@ func New(ctx context.Context, o *Options) (*FS, error) { if err != nil { return nil, err } + } else { + ref, err := repo.Head() + if err != nil { + return nil, err + } + + slog.Debug("cloned commit", "hash", ref.Hash().String()) + siteCommit = ref.Hash().String() } if o.MiToken != "" { @@ -148,7 +158,7 @@ func New(ctx context.Context, o *Options) (*FS, error) { fs.conf = conf - if err := fs.build(ctx); err != nil { + if err := fs.build(ctx, siteCommit); err != nil { return nil, err } @@ -174,6 +184,8 @@ func (f *FS) Update(ctx context.Context) error { return err } + siteCommit := "development" + if !f.opt.Development { err = wt.PullContext(ctx, &git.PullOptions{ ReferenceName: plumbing.NewBranchReferenceName(f.opt.Branch), @@ -199,6 +211,14 @@ func (f *FS) Update(ctx context.Context) error { updateErrors.Add(1) return err } + + ref, err := f.repo.Head() + if err != nil { + return err + } + + slog.Debug("checked out commit", "hash", ref.Hash().String()) + siteCommit = ref.Hash().String() } conf, err := config.Load(filepath.Join(f.repoDir, "config.dhall")) @@ -208,7 +228,7 @@ func (f *FS) Update(ctx context.Context) error { f.conf = conf - if err := f.build(ctx); err != nil { + if err := f.build(ctx, siteCommit); err != nil { return err } @@ -223,13 +243,13 @@ func (f *FS) Update(ctx context.Context) error { return nil } -func (f *FS) build(ctx context.Context) error { +func (f *FS) build(ctx context.Context, siteCommit string) error { builds.Add(1) destDir := filepath.Join(f.repoDir, f.opt.StaticSiteDir, "_site") begin := time.Now() - if err := f.writeConfig(); err != nil { + if err := f.writeConfig(siteCommit); err != nil { return err } @@ -298,9 +318,9 @@ func (f *FS) writePatrons(dataDir string) error { return nil } -func (f *FS) writeConfig() error { +func (f *FS) writeConfig(siteCommit string) error { dataDir := filepath.Join(f.repoDir, f.opt.StaticSiteDir, "src", "_data") - + os.WriteFile(filepath.Join(dataDir, "patrons.json"), []byte(`{"included": {"Items": []}}`), 0o644) if f.opt.PatreonClient != nil { @@ -317,6 +337,7 @@ func (f *FS) writeConfig() error { "argv.json": os.Args, "authors.json": f.conf.Authors, "characters.json": f.conf.Characters, + "commit.json": map[string]any{"hash": siteCommit}, "contactLinks.json": f.conf.ContactLinks, "jobHistory.json": f.conf.JobHistory, "notableProjects.json": f.conf.NotableProjects, @@ -325,6 +346,7 @@ func (f *FS) writeConfig() error { "seriesDescriptions.json": f.conf.SeriesDescMap, "signalboost.json": f.conf.Signalboost, } { + slog.Debug("opening data file", "fname", filepath.Join(dataDir, fname)) fh, err := os.Create(filepath.Join(dataDir, fname)) if err != nil { return err diff --git a/lume/src/_data/.gitignore b/lume/src/_data/.gitignore index 773657a..2d0f2ed 100644 --- a/lume/src/_data/.gitignore +++ b/lume/src/_data/.gitignore @@ -1,6 +1,7 @@ argv.json authors.json characters.json +commit.json contactLinks.json jobHistory.json notableProjects.json diff --git a/lume/src/_includes/base.njk b/lume/src/_includes/base.njk index 78211b5..91cda14 100644 --- a/lume/src/_includes/base.njk +++ b/lume/src/_includes/base.njk @@ -165,7 +165,7 @@ la budza pu cusku lu href="https://patreon.com/cadey">Patreon</a> like <a href="/patrons">these awesome people</a>!</p> </div> <div class="flex items-center justify-center border-fg-3 dark:border-fgDark-3 lg:justify-between"> - <p>Served by xesite v4 ({{argv[0]}}), source code available <a href="https://github.com/Xe/site">here</a>.</p> + <p>Served by xesite v4 ({{argv[0]}}) with site version {% if commit.hash != "development" %}<a href="https://github.com/Xe/site/commit/{{commit.hash}}">{{commit.hash.substr(0, 8)}}</a>{% else %}{{commit.hash}}{% endif %}, source code available <a href="https://github.com/Xe/site">here</a>.</p> </div> </footer> </body>
\ No newline at end of file |
