models_pages and controllers_pages

posts
serr 2025-04-10 21:50:10 +03:00
parent cbce343e51
commit 5a34d18ed6
10 changed files with 22 additions and 22 deletions

View File

@ -4,9 +4,9 @@ import (
"fmt"
"log"
"main/mvc/controllers"
controllers_pages "main/mvc/controllers/pages"
"main/mvc/controllers/controllers_pages"
"main/mvc/models"
models_pages "main/mvc/models/pages"
"main/mvc/models/models_pages"
"main/tools"
"net/http"
)

View File

@ -1,10 +1,10 @@
package controllers
package controllers_pages
import (
"log"
"main/mvc/models"
models_pages "main/mvc/models/pages"
"main/mvc/models/models_pages"
"main/tools"
"net/http"
)

View File

@ -1,8 +1,8 @@
package controllers
package controllers_pages
import (
"main/mvc/models"
models_pages "main/mvc/models/pages"
"main/mvc/models/models_pages"
"net/http"
)

View File

@ -1,8 +1,8 @@
package controllers
package controllers_pages
import (
"main/mvc/models"
models_pages "main/mvc/models/pages"
"main/mvc/models/models_pages"
"net/http"
)

View File

@ -1,8 +1,8 @@
package controllers
package controllers_pages
import (
"main/mvc/models"
models_pages "main/mvc/models/pages"
"main/mvc/models/models_pages"
"net/http"
)

View File

@ -6,7 +6,7 @@ import (
"os"
)
type Config struct {
type config struct {
PostsDir string
AssetsDir string
TemplatesDir string
@ -20,16 +20,16 @@ type Config struct {
}
var (
Cfg = Config{}
Cfg = config{}
)
func init() {
if err := Cfg.Load("config.json"); err != nil {
if err := Cfg.load("config.json"); err != nil {
log.Fatalf("%v", err)
}
}
func (c *Config) Load(configPath string) error {
func (c *config) load(configPath string) error {
configFile, err := os.ReadFile(configPath)
if err != nil {
return err

View File

@ -1,4 +1,4 @@
package models
package models_pages
import (
"bytes"

View File

@ -1,4 +1,4 @@
package models
package models_pages
import (
"bytes"

View File

@ -1,4 +1,4 @@
package models
package models_pages
import (
"bytes"
@ -36,7 +36,7 @@ func RenderPostPage(templates *template.Template, version int64, data template.H
return pageData.Bytes(), nil
}
func NewPost(link string, data []byte) *Post {
func newPost(link string, data []byte) *Post {
previewBuf := make([]byte, 0, 503)
if len(data) > 500 {

View File

@ -1,4 +1,4 @@
package models
package models_pages
import (
"bytes"
@ -26,7 +26,7 @@ var (
)
func init() {
if err := LoadPosts(models.Cfg.PostsDir); err != nil {
if err := loadPosts(models.Cfg.PostsDir); err != nil {
log.Fatalf("%v", err)
}
}
@ -35,7 +35,7 @@ func GetPosts() Posts {
return posts
}
func LoadPosts(dir string) error {
func loadPosts(dir string) error {
err := filepath.Walk(dir, func(path string, f os.FileInfo, err error) error {
if err != nil {
return err
@ -54,7 +54,7 @@ func LoadPosts(dir string) error {
html := tools.MdToHTML(md)
link := fmt.Sprintf("/%s/", strings.TrimSuffix(filepath.Base(path), ".md"))
posts[PostLink(link)] = NewPost(link, html)
posts[PostLink(link)] = newPost(link, html)
}
return nil
})