diff --git a/models/theme.go b/models/theme.go index 69e9d81..3112c7d 100644 --- a/models/theme.go +++ b/models/theme.go @@ -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 } diff --git a/providers/hugo/config.go b/providers/hugo/config.go index e28a736..8b04263 100644 --- a/providers/hugo/config.go +++ b/providers/hugo/config.go @@ -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"` } diff --git a/providers/hugo/provider.go b/providers/hugo/provider.go index 2860c3a..511b067 100644 --- a/providers/hugo/provider.go +++ b/providers/hugo/provider.go @@ -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{ diff --git a/providers/themes/meta.go b/providers/themes/meta.go index c2bf058..5946b1f 100644 --- a/providers/themes/meta.go +++ b/providers/themes/meta.go @@ -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", diff --git a/providers/themes/overlays/fs.go b/providers/themes/overlays/fs.go new file mode 100644 index 0000000..0d3ee3c --- /dev/null +++ b/providers/themes/overlays/fs.go @@ -0,0 +1,6 @@ +package overlays + +import "embed" + +//go:embed hugo-bearblog/* +var HugoBearblogFS embed.FS diff --git a/providers/themes/overlays/hugo-bearblog/archetype-posts.md b/providers/themes/overlays/hugo-bearblog/archetype-posts.md new file mode 100644 index 0000000..8a89180 --- /dev/null +++ b/providers/themes/overlays/hugo-bearblog/archetype-posts.md @@ -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 }}«. \ No newline at end of file diff --git a/providers/themes/overlays/hugo-bearblog/index.html b/providers/themes/overlays/hugo-bearblog/index.html new file mode 100644 index 0000000..573123f --- /dev/null +++ b/providers/themes/overlays/hugo-bearblog/index.html @@ -0,0 +1,24 @@ +{{ define "main" }} +{{ .Content }} + +