all repos — nirvash @ 59c7fbcc741b86cdca442dccbe9dba3869771930

modular CMS using the quartzgun library

archetype/eureka.go (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package archetype

import (
	"errors"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
)

type EurekaAdapter struct {
	Root string
}

func (self *EurekaAdapter) Init(cfg *Config) {
	fileInfo, err := os.Stat(cfg.Root)
	if os.IsNotExist(err) {
		panic("SSG content root does not exist! Ensure your configs are correct or create it!")
	} else if !fileInfo.IsDir() {
		panic("SSG content root is not a directory!")
	}

	self.Root = cfg.Root
}

func (self *EurekaAdapter) Name() string {
	return "eureka"
}

func (self *EurekaAdapter) EditableSlugs() bool {
  return false
}

func (self *EurekaAdapter) GetConfig(key string) (interface{}, error) {
	return nil, nil
}

func (self *EurekaAdapter) SetConfig(key string, value interface{}) error {
	return nil
}

func (self *EurekaAdapter) ListPages() map[string]string {
	files, err := ioutil.ReadDir(
		filepath.Join(self.Root, "inc"))

	if err != nil {
		panic(err.Error())
	}

	pages := map[string]string{}
	for _, file := range files {
		filename := file.Name()
		if strings.HasSuffix(filename, ".htm") {
			pages[filename] = strings.Replace(
				strings.TrimSuffix(filename, ".htm"), "_", " ", -1)
		}
	}
	return pages
}

func (self *EurekaAdapter) GetPage(filename string) (Page, error) {
	fullPath := filepath.Join(self.Root, "inc", filename)
	f, err := os.ReadFile(fullPath)

	if err != nil {
		return Page{}, err
	}

	if !strings.HasSuffix(filename, ".htm") {
		return Page{}, errors.New("Page file extension is not '.htm'")
	}

	title := strings.Replace(
		strings.TrimSuffix(filename, ".htm"), "_", " ", -1)
	fileInfo, _ := os.Stat(fullPath)
	content := string(f[:])

	return Page{
		Title:   title,
		Slug: filename,
		Content: content,
		Edited:  fileInfo.ModTime(),
	}, nil
}

func (self *EurekaAdapter) FormatPage(raw string) string {
	return raw
}

func (self *EurekaAdapter) FormattingHelp() string {
	return "help!"
}

func (self *EurekaAdapter) CreatePage(slug, title, content string) error {
	return nil
}

func (self *EurekaAdapter) SavePage(oldSlug, newSlug, title, content string) error {
	return nil
}

func (self *EurekaAdapter) DeletePage(slug string) error {
	return nil
}

func (self *EurekaAdapter) Build() (bool, string) {
	return true, "Build successful"
}