Пример #1
0
// GenerateHandler is called by the website when we want to execute the generator
func GenerateSite(dir_site string, confPath string) error {
	//fmt.Fprintln(os.Stdout, "dir:", dir_site)

	conf := config.FromConfiguration(confPath)
	viewBuilder := view.NewBuilder(filepath.Join(dir_site, "_layouts"), conf.TemplatePaths)

	// prepare the destination site dir
	dst_dir := filepath.Join(dir_site, SITE_DST)
	if err := prepareSiteDest(dst_dir); err != nil {
		return err
	}

	bundle := &SiteBundle{SiteIndexTitle: conf.SiteIndexTitle,
		SiteDst: dst_dir, PostsDstDir: filepath.Join(dst_dir, POSTS_DIR_DST)}
	// iterate over the posts directory and compile each post
	if err := compilePosts(filepath.Join(dir_site, POSTS_DIR_SRC),
		filepath.Join(dst_dir, POSTS_DIR_DST), viewBuilder, bundle); err != nil {
		return err
	}

	// compile the index page
	if err := generateIndexHTML(bundle, viewBuilder); err != nil {
		return err
	}

	// copy all the static paths
	for _, path := range conf.StaticPaths {
		//fmt.Println("path", path)
		if err := lpio.Copy(path, filepath.Join(dst_dir, filepath.Base(path)), SITE_DST_PERM); err != nil {
			return err
		}
	}
	return nil
}
Пример #2
0
func compileDirPost(src_post_dir string, info os.FileInfo, dst_posts_dir string, viewBuilder *view.Builder) (*post.BPost, error) {
	//postName := getPostNameFromRaw(info)
	srcPostDir := filepath.Join(src_post_dir, info.Name())

	// create the post object
	p, err := post.FromMarkdown(filepath.Join(srcPostDir, info.Name()+".md"))
	if err != nil {
		return nil, err
	}
	// copy the rest of the folder
	dstPostDir := filepath.Join(dst_posts_dir, p.UrlPermalink)
	if err := lpio.Copy(srcPostDir, dstPostDir, SITE_DST_PERM); err != nil {
		return nil, err
	}

	return p, generatePostHTML(p, filepath.Join(dstPostDir, "index.html"), viewBuilder)
}