diff options
| author | Shulhan <ms@kilabit.info> | 2020-03-24 23:09:34 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2020-03-24 23:09:34 +0700 |
| commit | 82a5951ca37483e4a4c98d42522fc2704b2581b7 (patch) | |
| tree | 4cf236ff48fac45abb603c8c608d616c405e71e6 | |
| parent | ab71b479e539e258fbd541fc4a9328a923114967 (diff) | |
| download | ciigo-82a5951ca37483e4a4c98d42522fc2704b2581b7.tar.xz | |
all: rename markupFile to fileMarkup
This is to make it consistent with fileHTML.
| -rw-r--r-- | filehtml.go | 2 | ||||
| -rw-r--r-- | filemarkup.go (renamed from fileadoc.go) | 14 | ||||
| -rw-r--r-- | generate.go | 22 | ||||
| -rw-r--r-- | htmlgenerator.go | 6 | ||||
| -rw-r--r-- | server.go | 34 |
5 files changed, 39 insertions, 39 deletions
diff --git a/filehtml.go b/filehtml.go index fe2a949..151d3ad 100644 --- a/filehtml.go +++ b/filehtml.go @@ -42,7 +42,7 @@ func (fhtml *fileHTML) reset() { // unpackMarkup convert the markup metadata to its HTML representation and // rawBody to template.HTML. // -func (fhtml *fileHTML) unpackMarkup(fa *markupFile) { +func (fhtml *fileHTML) unpackMarkup(fa *fileMarkup) { fhtml.Metadata = make(map[string]string) for k, v := range fa.metadata { diff --git a/fileadoc.go b/filemarkup.go index e6e550d..e416f55 100644 --- a/fileadoc.go +++ b/filemarkup.go @@ -12,7 +12,7 @@ import ( "strings" ) -type markupFile struct { +type fileMarkup struct { kind byte // kind define the type of markup file. path string // path contains full path to markup file. info os.FileInfo // info contains FileInfo of markup file. @@ -20,26 +20,26 @@ type markupFile struct { metadata map[string]interface{} // metadata contains markup metadata. } -func newMarkupFile(filePath string, fi os.FileInfo) (fmarkup *markupFile, err error) { +func newFileMarkup(filePath string, fi os.FileInfo) (fmarkup *fileMarkup, err error) { if len(filePath) == 0 { - return nil, fmt.Errorf("ciigo: newMarkupFile: empty path") + return nil, fmt.Errorf("ciigo: newFileMarkup: empty path") } if fi == nil { fi, err = os.Stat(filePath) if err != nil { - return nil, fmt.Errorf("newMarkupFile: " + err.Error()) + return nil, fmt.Errorf("newFileMarkup: " + err.Error()) } } ext := strings.ToLower(path.Ext(filePath)) - fmarkup = &markupFile{ + fmarkup = &fileMarkup{ kind: markupKind(ext), path: filePath, info: fi, } if fmarkup.kind == markupKindUnknown { - return nil, fmt.Errorf("newMarkupFile: unknown markup file " + filePath) + return nil, fmt.Errorf("newFileMarkup: unknown markup file " + filePath) } fmarkup.basePath = strings.TrimSuffix(filePath, ext) @@ -52,7 +52,7 @@ func newMarkupFile(filePath string, fi os.FileInfo) (fmarkup *markupFile, err er // modification time is equal or greater than their markup file; otherwise // it will return false. // -func (fa *markupFile) isHTMLLatest(htmlPath string) bool { +func (fa *fileMarkup) isHTMLLatest(htmlPath string) bool { htmlInfo, err := os.Stat(htmlPath) if err != nil { if os.IsNotExist(err) { diff --git a/generate.go b/generate.go index 1049a29..9f5d9e3 100644 --- a/generate.go +++ b/generate.go @@ -32,9 +32,9 @@ func Convert(dir, htmlTemplate string) { htmlg := newHTMLGenerator(htmlTemplate, string(b)) - markupFiles := listMarkupFiles(dir) + fileMarkups := listFileMarkups(dir) - htmlg.convertMarkupFiles(markupFiles, true) + htmlg.convertFileMarkups(fileMarkups, true) } // @@ -51,9 +51,9 @@ func Generate(root, out, htmlTemplate string) { } htmlg := newHTMLGenerator(htmlTemplate, string(b)) - markupFiles := listMarkupFiles(root) + fileMarkups := listFileMarkups(root) - htmlg.convertMarkupFiles(markupFiles, false) + htmlg.convertFileMarkups(fileMarkups, false) mfs, err := memfs.New(nil, defExcludes, true) if err != nil { @@ -77,13 +77,13 @@ func Generate(root, out, htmlTemplate string) { } // -// listMarkupFiles find any markup files inside the content directory, +// listFileMarkups find any markup files inside the content directory, // recursively. // -func listMarkupFiles(dir string) (markupFiles []*markupFile) { +func listFileMarkups(dir string) (fileMarkups []*fileMarkup) { d, err := os.Open(dir) if err != nil { - log.Fatal("ciigo: listMarkupFiles: os.Open: ", err) + log.Fatal("ciigo: listFileMarkups: os.Open: ", err) } fis, err := d.Readdir(0) @@ -99,7 +99,7 @@ func listMarkupFiles(dir string) (markupFiles []*markupFile) { } if fi.IsDir() && name[0] != '.' { newdir := filepath.Join(dir, fi.Name()) - markupFiles = append(markupFiles, listMarkupFiles(newdir)...) + fileMarkups = append(fileMarkups, listFileMarkups(newdir)...) continue } @@ -111,14 +111,14 @@ func listMarkupFiles(dir string) (markupFiles []*markupFile) { continue } - markupf := &markupFile{ + markupf := &fileMarkup{ kind: markupKind(ext), path: filepath.Join(dir, name), info: fi, basePath: filepath.Join(dir, strings.TrimSuffix(name, ext)), } - markupFiles = append(markupFiles, markupf) + fileMarkups = append(fileMarkups, markupf) } - return markupFiles + return fileMarkups } diff --git a/htmlgenerator.go b/htmlgenerator.go index 6939def..2cf5a76 100644 --- a/htmlgenerator.go +++ b/htmlgenerator.go @@ -62,10 +62,10 @@ func (htmlg *htmlGenerator) loadTemplate() (err error) { return } -func (htmlg *htmlGenerator) convertMarkupFiles(markupFiles []*markupFile, force bool) { +func (htmlg *htmlGenerator) convertFileMarkups(fileMarkups []*fileMarkup, force bool) { fhtml := &fileHTML{} - for _, fmarkup := range markupFiles { + for _, fmarkup := range fileMarkups { fhtml.reset() fhtml.path = fmarkup.basePath + ".html" @@ -78,7 +78,7 @@ func (htmlg *htmlGenerator) convertMarkupFiles(markupFiles []*markupFile, force } } -func (htmlg *htmlGenerator) convert(fmarkup *markupFile, fhtml *fileHTML, force bool) { +func (htmlg *htmlGenerator) convert(fmarkup *fileMarkup, fhtml *fileHTML, force bool) { if fmarkup.isHTMLLatest(fhtml.path) && !force { return } @@ -28,7 +28,7 @@ type Server struct { http *libhttp.Server opts *libhttp.ServerOptions htmlg *htmlGenerator - markupFiles []*markupFile + fileMarkups []*fileMarkup dw *libio.DirWatcher } @@ -84,8 +84,8 @@ func NewServer(root, address, htmlTemplate string) (srv *Server) { } srv.htmlg = newHTMLGenerator(htmlTemplate, string(bhtml)) - srv.markupFiles = listMarkupFiles(root) - srv.htmlg.convertMarkupFiles(srv.markupFiles, false) + srv.fileMarkups = listFileMarkups(root) + srv.htmlg.convertFileMarkups(srv.fileMarkups, false) } else { tmplNode, err := srv.http.Memfs.Get(htmlTemplate) if err != nil { @@ -135,7 +135,7 @@ func (srv *Server) autoGenerate() { `.*\.html$`, `^\..*`, }, - Callback: srv.onChangeMarkupFile, + Callback: srv.onChangeFileMarkup, } err := srv.dw.Start() @@ -150,12 +150,12 @@ func (srv *Server) autoGenerate() { } // -// onChangeMarkupFile watch the markup files inside the "content" directory, +// onChangeFileMarkup watch the markup files inside the "content" directory, // and re-generate them into HTML file when changed. // -func (srv *Server) onChangeMarkupFile(ns *libio.NodeState) { +func (srv *Server) onChangeFileMarkup(ns *libio.NodeState) { if ns.State == libio.FileStateDeleted { - fmt.Printf("ciigo: onChangeMarkupFile: %q deleted\n", ns.Node.SysPath) + fmt.Printf("ciigo: onChangeFileMarkup: %q deleted\n", ns.Node.SysPath) return } @@ -164,38 +164,38 @@ func (srv *Server) onChangeMarkupFile(ns *libio.NodeState) { return } - fmt.Println("ciigo: onChangeMarkupFile: " + ns.Node.SysPath) + fmt.Println("ciigo: onChangeFileMarkup: " + ns.Node.SysPath) var ( - fmarkup *markupFile + fmarkup *fileMarkup err error ) switch ns.State { case libio.FileStateCreated: - fmarkup, err = newMarkupFile(ns.Node.SysPath, nil) + fmarkup, err = newFileMarkup(ns.Node.SysPath, nil) if err != nil { log.Println(err) return } - srv.markupFiles = append(srv.markupFiles, fmarkup) + srv.fileMarkups = append(srv.fileMarkups, fmarkup) case libio.FileStateModified: - for x := 0; x < len(srv.markupFiles); x++ { - if srv.markupFiles[x].path == ns.Node.SysPath { - fmarkup = srv.markupFiles[x] + for x := 0; x < len(srv.fileMarkups); x++ { + if srv.fileMarkups[x].path == ns.Node.SysPath { + fmarkup = srv.fileMarkups[x] break } } if fmarkup == nil { - fmarkup, err = newMarkupFile(ns.Node.SysPath, nil) + fmarkup, err = newFileMarkup(ns.Node.SysPath, nil) if err != nil { log.Println(err) return } - srv.markupFiles = append(srv.markupFiles, fmarkup) + srv.fileMarkups = append(srv.fileMarkups, fmarkup) } } @@ -223,7 +223,7 @@ func (srv *Server) onChangeHTMLTemplate(ns *libio.NodeState) { fmt.Println("web: regenerate all markup files ... ") - srv.htmlg.convertMarkupFiles(srv.markupFiles, true) + srv.htmlg.convertFileMarkups(srv.fileMarkups, true) } func (srv *Server) onSearch(res http.ResponseWriter, req *http.Request, reqBody []byte) ( |
