diff options
| author | Xe Iaso <me@xeiaso.net> | 2023-10-14 11:38:13 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2023-10-14 11:38:16 -0400 |
| commit | df59f21fbc27ec37375613be35fd04eb3033189e (patch) | |
| tree | db400299783c2ef7d56976be0313939f16382804 /internal | |
| parent | 782faa8d445945c24016a0384480d337abddbab1 (diff) | |
| download | xesite-df59f21fbc27ec37375613be35fd04eb3033189e.tar.xz xesite-df59f21fbc27ec37375613be35fd04eb3033189e.zip | |
internal/lume: make pages for post series
I'm probably reading something wrong in the documentation for Lume, but
I wasn't able to find an obvious way to generate pages for each of the post
series programmatically.
This is a bit of a hacky workaround that makes the Lume driver write
individual JSX files for each series defined in the Dhall source. It
should work for my needs though.
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/lume/lume.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/internal/lume/lume.go b/internal/lume/lume.go index 7bee446..3f7c84e 100644 --- a/internal/lume/lume.go +++ b/internal/lume/lume.go @@ -5,6 +5,7 @@ import ( "encoding/json" "expvar" "fmt" + "html/template" "io/fs" "log" "log/slog" @@ -339,6 +340,10 @@ func (f *FS) writeConfig() error { } } + if err := f.writeSeriesPages(); err != nil { + return err + } + return nil } @@ -348,6 +353,62 @@ func (f *FS) Clacks() []string { return f.conf.ClackSet } +func (f *FS) writeSeriesPages() error { + seriesPageDir := filepath.Join(f.repoDir, f.opt.StaticSiteDir, "src", "blog", "series") + + for k, v := range f.conf.SeriesDescMap { + fname := filepath.Join(seriesPageDir, fmt.Sprintf("%s.jsx", k)) + + fout, err := os.Create(fname) + if err != nil { + return fmt.Errorf("can't open %s: %w", fname, err) + } + defer fout.Close() + + if err := seriesPageTemplate.Execute(fout, struct { + Series string + Desc string + }{ + Series: k, + Desc: v, + }); err != nil { + return fmt.Errorf("can't write %s: %w", fname, err) + } + } + + return nil +} + +const seriesPageTemplateStr = `export const title = "{{.Series}}"; +export const layout = "base.njk"; + +export default ({ search }) => { + const dateOptions = { year: "numeric", month: "2-digit", day: "2-digit" }; + + return ( + <div> + <h1 className="text-3xl mb-4">{title}</h1> + <p className="mb-4"> + {{.Desc}} + </p> + + <ul class="list-disc ml-4 mb-4"> + {search.pages("series={{.Series}}", "order date=desc").map((post) => { + const url = post.data.redirect_to ? post.data.redirect_to : post.data.url; + return ( + <li> + <span className="font-mono">{post.data.date.toLocaleDateString("en-US", dateOptions)}</span> -{" "} + <a href={url}>{post.data.title}</a> + </li> + ); + })} + </ul> + </div> + ); +};` + +var seriesPageTemplate = template.Must(template.New("seriesPage.jsx.tmpl").Parse(seriesPageTemplateStr)) + func (f *FS) buildResume(ctx context.Context) error { t0 := time.Now() wd := filepath.Join(f.repoDir, "dhall", "resume") |
