Example #1
0
func (d *DefaultRenderer) copyStatic() error {
	theme := d.getTheme()
	out := d.getOutputDir()
	switch theme {
	case defaultTheme:
		info, _ := os.Stat(d.root)
		for _, f := range gh.AssetNames() {
			if filepath.Ext(f) == ".html" {
				continue
			}
			base := filepath.Join(out, filepath.Dir(f))
			os.MkdirAll(base, info.Mode())
			b, err := gh.Asset(f)
			if err != nil {
				return err
			}
			err = ioutil.WriteFile(filepath.Join(out, f), b, DefaultPerm)
			if err != nil {
				log.Println(err, base)
				return err
			}
		}
		return nil
	default:
		// we copy the static directory in the current theme directory
		staticDir := filepath.Join(d.root, ThemeDir, theme, StaticDir)
		if com.IsExist(staticDir) {
			err := com.CopyDir(staticDir, filepath.Join(d.root, OutputDir, StaticDir))
			if err != nil {
				return err
			}
		}

	}

	// if we have the static set on the config file we use it.
	if staticDirective, ok := d.config[StaticDir]; ok {
		switch staticDirective.(type) {
		case []interface{}:
			sd := staticDirective.([]interface{})
			for _, f := range sd {
				dir := f.(string)
				err := com.CopyDir(filepath.Join(d.root, dir), filepath.Join(out, dir))
				if err != nil {
					return err
				}
			}
		}
	}
	return nil
}
Example #2
0
func init() {
	defaultTemplates = template.New("bongo")
	for _, n := range gh.AssetNames() {
		if filepath.Ext(n) != ".html" {
			continue
		}
		tx := defaultTemplates.New(filepath.Join("gh", n))
		d, err := gh.Asset(n)
		if err != nil {
			panic(err)
		}
		_, err = tx.Parse(string(d))
		if err != nil {
			panic(err)
		}
	}
	log.SetFlags(log.Lshortfile)
}