diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d298be1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +public/ \ No newline at end of file diff --git a/_config.toml b/_config.toml index 76cd570..43e82c8 100644 --- a/_config.toml +++ b/_config.toml @@ -10,4 +10,8 @@ category_dir = "categories" # Pagination per_page = 10 -pagination_dir = "page" \ No newline at end of file +pagination_dir = "page" + +# Theme +theme_dir = "themes" +theme = "unnamed" \ No newline at end of file diff --git a/config/provider.go b/config/provider.go index b090c60..3899220 100644 --- a/config/provider.go +++ b/config/provider.go @@ -16,6 +16,9 @@ type Config struct { PerPage int `toml:"per_page"` PaginationDir string `toml:"pagination_dir"` + + ThemeDir string `toml:"theme_dir"` + Theme string `toml:"theme"` } func NewProvider(f string) *Config { diff --git a/themes/unnamed/layout/layout.html b/themes/unnamed/layout/layout.html new file mode 100755 index 0000000..71e60a0 --- /dev/null +++ b/themes/unnamed/layout/layout.html @@ -0,0 +1,16 @@ +{{ define "layout" }} + + + + + + {{ if eq .CurrentPage "index" }} + {{ .Cfg.Title }} + {{ end }} + + + +Hello World. + + +{{ end }} \ No newline at end of file diff --git a/xlib/x.go b/xlib/x.go index c981662..21f81fd 100644 --- a/xlib/x.go +++ b/xlib/x.go @@ -1,6 +1,8 @@ package xlib import ( + "bytes" + "html/template" "math" "path/filepath" "x/config" @@ -42,5 +44,20 @@ func (s *Site) Build() { } clearDir(s.Cfg.PublicDir) - makeFile([]byte("hello"), filepath.Join(s.Cfg.PublicDir, indexPage)) + + bt := s.renderPage() + makeFile(bt, filepath.Join(s.Cfg.PublicDir, indexPage)) +} + +func (s *Site) renderPage() []byte { + var doc bytes.Buffer + + var t = filepath.Join(s.Cfg.ThemeDir, s.Cfg.Theme, "/layout/*.html") + tmpl, err := template.ParseGlob(t) + if err != nil { + panic(err) + } + tmpl.ExecuteTemplate(&doc, "layout", s) + + return []byte(doc.String()) }