Configured the site a little

This commit is contained in:
Leon Mika 2025-03-30 10:39:02 +11:00
parent 2411e64a53
commit b465899f85
10 changed files with 121 additions and 20 deletions

View file

@ -1,9 +1,15 @@
package models
import "io/fs"
type ThemeMeta struct {
ID string `json:"id"`
Name string `json:"name"`
URL string `json:"repo"`
ID string
Name string
// Source repo
URL string
OverlayFS fs.FS
Overlays map[string]string
// Indicates that this theme prefers posts have titles.
PreferTitle bool
@ -12,5 +18,5 @@ type ThemeMeta struct {
AddTitleToPages bool
// Page bundle for "blog" posts
BlogPostBundle string `json:"post_dir"`
BlogPostBundle string
}

View file

@ -1,11 +1,16 @@
package hugo
type permalinksConfig struct {
Page map[string]string `yaml:"page"`
}
type hugoConfig struct {
BaseURL string `yaml:"baseURL,omitempty"`
LanguageCode string `yaml:"languageCode"`
Title string `yaml:"title"`
Theme string `yaml:"theme"`
CanonifyURLs bool `yaml:"canonifyURLs,omitempty"`
BaseURL string `yaml:"baseURL,omitempty"`
LanguageCode string `yaml:"languageCode"`
Title string `yaml:"title"`
Theme string `yaml:"theme"`
CanonifyURLs bool `yaml:"canonifyURLs,omitempty"`
Permalinks permalinksConfig `yaml:"permalinks,omitempty"`
Markup hugoConfigMarkup `yaml:"markup"`
}

View file

@ -97,17 +97,25 @@ func (p *Provider) publishSiteAt(ctx context.Context, dir string, site models.Si
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
if err := cmd.Run(); err != nil {
if err := cmd.Start(); err != nil {
return "", err
}
if err := cmd.Wait(); err != nil {
return "", err
}
return outDir, nil
}
func (p *Provider) ReconfigureSite(ctx context.Context, isPreviewConfig bool, configBase string, site models.Site) error {
func (p *Provider) ReconfigureSite(ctx context.Context, isPreviewConfig bool, configBase string, site models.Site, meta models.ThemeMeta) error {
hugoCfg := hugoConfig{
Title: site.Title,
LanguageCode: "en",
Theme: site.Theme,
Permalinks: permalinksConfig{
Page: map[string]string{
meta.BlogPostBundle: meta.BlogPostBundle + "/:year/:month/:day/:title",
},
},
Markup: hugoConfigMarkup{
Goldmark: hugoGoldmarkConfig{
Renderer: hugoGoldmarkRendererConfig{

View file

@ -1,14 +1,23 @@
package themes
import "lmika.dev/lmika/hugo-cms/models"
import (
"lmika.dev/lmika/hugo-cms/models"
"lmika.dev/lmika/hugo-cms/providers/themes/overlays"
)
var themes = []models.ThemeMeta{
{
ID: "bear",
Name: "Bear",
URL: "https://github.com/janraasch/hugo-bearblog",
ID: "bear",
Name: "Bear",
URL: "https://github.com/janraasch/hugo-bearblog",
OverlayFS: overlays.HugoBearblogFS,
Overlays: map[string]string{
"hugo-bearblog/archetype-posts.md": "archetypes/posts.md",
"hugo-bearblog/index.html": "layouts/index.html",
"hugo-bearblog/partials-nav.html": "layouts/partials/nav.html",
},
PreferTitle: true,
BlogPostBundle: "blog",
BlogPostBundle: "posts",
},
{
ID: "terminal",

View file

@ -0,0 +1,6 @@
package overlays
import "embed"
//go:embed hugo-bearblog/*
var HugoBearblogFS embed.FS

View file

@ -0,0 +1,13 @@
+++
title = "{{ replace .Name "-" " " | title }}"
date = "{{ .Date }}"
#
# description is optional
#
# description = "An optional description for SEO. If not provided, an automatically created summary will be used."
tags = [{{ range $plural, $terms := .Site.Taxonomies }}{{ range $term, $val := $terms }}"{{ printf "%s" $term }}",{{ end }}{{ end }}]
+++
This is a page about »{{ replace .Name "-" " " | title }}«.

View file

@ -0,0 +1,24 @@
{{ define "main" }}
{{ .Content }}
<h3>Recent Posts</h3>
<ul class="blog-posts">
{{ range site.RegularPages }}
<li>
<span>
<i>
<time datetime='{{ .Date.Format "2006-01-02" }}'>
{{ .Date.Format (default "02 Jan, 2006" .Site.Params.dateFormat) }}
</time>
</i>
</span>
<a href="{{ .Permalink }}">{{ .Title }}</a>
</li>
{{ else }}
<li>
No posts yet
</li>
{{ end }}
</ul>
{{ end }}

View file

@ -0,0 +1,7 @@
<a href="{{ "" | relURL }}">Home</a>
{{ range .Site.Menus.main }}
<a href="{{ .URL }}">{{ .Name }}</a>
{{ end }}
{{ with .Site.GetPage "/posts" }}
<a href="{{ "posts" | relURL }}">Posts</a>
{{ end }}

View file

@ -3,6 +3,7 @@ package sitebuilder
import (
"context"
"errors"
"io/fs"
"lmika.dev/lmika/hugo-cms/models"
"lmika.dev/lmika/hugo-cms/providers/bus"
"lmika.dev/lmika/hugo-cms/providers/db"
@ -168,15 +169,37 @@ func (s *Service) createSite(ctx context.Context, site models.Site) error {
// Setup the theme
log.Printf(" .. theme")
if err := s.git.Clone(ctx, themeMeta.URL, s.hugo.SiteStagingDir(site, hugo.ThemeSiteDir)); err != nil {
stagingDir := s.hugo.SiteStagingDir(site, hugo.ThemeSiteDir)
if err := s.git.Clone(ctx, themeMeta.URL, stagingDir); err != nil {
return err
}
if err := s.hugo.ReconfigureSite(ctx, false, "hugo", site); err != nil {
if overlayFS := themeMeta.OverlayFS; overlayFS != nil && len(themeMeta.Overlays) > 0 {
for src, target := range themeMeta.Overlays {
srcFile, err := fs.ReadFile(overlayFS, src)
if err != nil {
return err
}
targetPath := filepath.Join(s.hugo.SiteStagingDir(site, hugo.BaseSiteDir), target)
targetDir := filepath.Dir(targetPath)
if err := os.MkdirAll(targetDir, 0755); err != nil {
return err
}
if err := os.WriteFile(targetPath, srcFile, 0644); err != nil {
return err
}
log.Printf(" .. overlay %v", targetPath)
}
}
if err := s.hugo.ReconfigureSite(ctx, false, "hugo", site, themeMeta); err != nil {
return err
}
if err := s.hugo.ReconfigureSite(ctx, true, "hugoPreview", site); err != nil {
if err := s.hugo.ReconfigureSite(ctx, true, "hugoPreview", site, themeMeta); err != nil {
return err
}

View file

@ -14,7 +14,7 @@
<h1>Hugo CMS</h1>
<nav>
<span>{{.site.Title}}</span>
<a href="/preview/{{.site.Name}}" target="_blank">Preview</a>
<a href="/preview/{{.site.Name}}/" target="_blank">Preview</a>
{{ if .prodTarget }}
<a href="{{.prodTarget.URL}}" target="_blank">Visit</a>
{{ end }}