The code and data behind xeiaso.net
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/lume: annotate website commit in footer

Signed-off-by: Xe Iaso <me@xeiaso.net>

Xe Iaso ded584e1 3cff1131

+45 -23
+15 -16
cmd/xesite/main.go
··· 113 113 http.Redirect(w, r, "/static/site.webmanifest", http.StatusMovedPermanently) 114 114 }) 115 115 116 - if *devel { 117 - mux.HandleFunc("/.within/hook/github", func(w http.ResponseWriter, r *http.Request) { 118 - if err := fs.Update(r.Context()); err != nil { 119 - if err == git.NoErrAlreadyUpToDate { 120 - w.WriteHeader(http.StatusOK) 121 - fmt.Fprintln(w, "already up to date") 122 - return 123 - } 124 - log.Println(err) 125 - http.Error(w, err.Error(), http.StatusInternalServerError) 116 + 117 + gh := &GitHubWebhook{fs: fs} 118 + s := hmacsig.Handler256(gh, *githubSecret) 119 + mux.Handle("/.within/hook/github", s) 120 + 121 + mux.HandleFunc("/.within/hook/localonlybegood", func(w http.ResponseWriter, r *http.Request) { 122 + if err := fs.Update(r.Context()); err != nil { 123 + if err == git.NoErrAlreadyUpToDate { 124 + w.WriteHeader(http.StatusOK) 125 + fmt.Fprintln(w, "already up to date") 126 126 return 127 127 } 128 - }) 129 - } else { 130 - gh := &GitHubWebhook{fs: fs} 131 - s := hmacsig.Handler256(gh, *githubSecret) 132 - mux.Handle("/.within/hook/github", s) 133 - } 128 + log.Println(err) 129 + http.Error(w, err.Error(), http.StatusInternalServerError) 130 + return 131 + } 132 + }) 134 133 135 134 mux.Handle("/.within/hook/patreon", &PatreonWebhook{fs: fs}) 136 135
+28 -6
internal/lume/lume.go
··· 123 123 dur := time.Since(t0) 124 124 slog.Debug("repo cloned", "in", dur.String()) 125 125 126 + siteCommit := "development" 127 + 126 128 fs := &FS{ 127 129 repo: repo, 128 130 repoDir: repoDir, ··· 134 136 if err != nil { 135 137 return nil, err 136 138 } 139 + } else { 140 + ref, err := repo.Head() 141 + if err != nil { 142 + return nil, err 143 + } 144 + 145 + slog.Debug("cloned commit", "hash", ref.Hash().String()) 146 + siteCommit = ref.Hash().String() 137 147 } 138 148 139 149 if o.MiToken != "" { ··· 148 158 149 159 fs.conf = conf 150 160 151 - if err := fs.build(ctx); err != nil { 161 + if err := fs.build(ctx, siteCommit); err != nil { 152 162 return nil, err 153 163 } 154 164 ··· 174 184 return err 175 185 } 176 186 187 + siteCommit := "development" 188 + 177 189 if !f.opt.Development { 178 190 err = wt.PullContext(ctx, &git.PullOptions{ 179 191 ReferenceName: plumbing.NewBranchReferenceName(f.opt.Branch), ··· 199 211 updateErrors.Add(1) 200 212 return err 201 213 } 214 + 215 + ref, err := f.repo.Head() 216 + if err != nil { 217 + return err 218 + } 219 + 220 + slog.Debug("checked out commit", "hash", ref.Hash().String()) 221 + siteCommit = ref.Hash().String() 202 222 } 203 223 204 224 conf, err := config.Load(filepath.Join(f.repoDir, "config.dhall")) ··· 208 228 209 229 f.conf = conf 210 230 211 - if err := f.build(ctx); err != nil { 231 + if err := f.build(ctx, siteCommit); err != nil { 212 232 return err 213 233 } 214 234 ··· 223 243 return nil 224 244 } 225 245 226 - func (f *FS) build(ctx context.Context) error { 246 + func (f *FS) build(ctx context.Context, siteCommit string) error { 227 247 builds.Add(1) 228 248 destDir := filepath.Join(f.repoDir, f.opt.StaticSiteDir, "_site") 229 249 230 250 begin := time.Now() 231 251 232 - if err := f.writeConfig(); err != nil { 252 + if err := f.writeConfig(siteCommit); err != nil { 233 253 return err 234 254 } 235 255 ··· 298 318 return nil 299 319 } 300 320 301 - func (f *FS) writeConfig() error { 321 + func (f *FS) writeConfig(siteCommit string) error { 302 322 dataDir := filepath.Join(f.repoDir, f.opt.StaticSiteDir, "src", "_data") 303 - 323 + 304 324 os.WriteFile(filepath.Join(dataDir, "patrons.json"), []byte(`{"included": {"Items": []}}`), 0o644) 305 325 306 326 if f.opt.PatreonClient != nil { ··· 317 337 "argv.json": os.Args, 318 338 "authors.json": f.conf.Authors, 319 339 "characters.json": f.conf.Characters, 340 + "commit.json": map[string]any{"hash": siteCommit}, 320 341 "contactLinks.json": f.conf.ContactLinks, 321 342 "jobHistory.json": f.conf.JobHistory, 322 343 "notableProjects.json": f.conf.NotableProjects, ··· 325 346 "seriesDescriptions.json": f.conf.SeriesDescMap, 326 347 "signalboost.json": f.conf.Signalboost, 327 348 } { 349 + slog.Debug("opening data file", "fname", filepath.Join(dataDir, fname)) 328 350 fh, err := os.Create(filepath.Join(dataDir, fname)) 329 351 if err != nil { 330 352 return err
+1
lume/src/_data/.gitignore
··· 1 1 argv.json 2 2 authors.json 3 3 characters.json 4 + commit.json 4 5 contactLinks.json 5 6 jobHistory.json 6 7 notableProjects.json
+1 -1
lume/src/_includes/base.njk
··· 165 165 href="https://patreon.com/cadey">Patreon</a> like <a href="/patrons">these awesome people</a>!</p> 166 166 </div> 167 167 <div class="flex items-center justify-center border-fg-3 dark:border-fgDark-3 lg:justify-between"> 168 - <p>Served by xesite v4 ({{argv[0]}}), source code available <a href="https://github.com/Xe/site">here</a>.</p> 168 + <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> 169 169 </div> 170 170 </footer> 171 171 </body>