Exemplo n.º 1
0
func createWatcher(extensionsFunctions map[string]func() error) (*fsnotify.Watcher, error) {
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		return nil, err
	}
	go func() {
		for {
			select {
			case event := <-watcher.Events:
				if event.Op&fsnotify.Write == fsnotify.Write {
					for key, value := range extensionsFunctions {
						if !helpers.IsDirectory(event.Name) && filepath.Ext(event.Name) == key {
							// Call the function associated with this file extension
							err := value()
							if err != nil {
								log.Panic("Error while reloading theme or plugins:", err)
							}
						}
					}
				}
			case err := <-watcher.Errors:
				log.Println("Error while watching directory:", err)
			}
		}
	}()
	return watcher, nil
}
Exemplo n.º 2
0
func GetAllThemes() []string {
	themes := make([]string, 0)
	files, _ := filepath.Glob(filepath.Join(filenames.ThemesFilepath, "*"))
	for _, file := range files {
		if helpers.IsDirectory(file) {
			themes = append(themes, filepath.Base(file))
		}
	}
	return themes
}
Exemplo n.º 3
0
func pagesHandler(w http.ResponseWriter, r *http.Request, params map[string]string) {
	path := filepath.Join(filenames.PagesFilepath, params["filepath"])
	// If the path points to a directory, add a trailing slash to the path (needed if the page loads relative assets).
	if helpers.IsDirectory(path) && !strings.HasSuffix(r.RequestURI, "/") {
		http.Redirect(w, r, r.RequestURI+"/", 301)
		return
	}
	http.ServeFile(w, r, path)
	return
}