|
|
@ -45,8 +45,8 @@ fn new_build_cmd() cli.Command {
|
|
|
|
execute: fn (cmd cli.Command) ! {
|
|
|
|
execute: fn (cmd cli.Command) ! {
|
|
|
|
mut logger := log.Log{}
|
|
|
|
mut logger := log.Log{}
|
|
|
|
logger.set_level(log.Level.info)
|
|
|
|
logger.set_level(log.Level.info)
|
|
|
|
config := load_config(commands.default_config)!
|
|
|
|
conf := load_config(commands.default_config)!
|
|
|
|
build(config, mut logger) or {
|
|
|
|
build(conf, mut logger) or {
|
|
|
|
logger.error(err.msg())
|
|
|
|
logger.error(err.msg())
|
|
|
|
println('Build failed')
|
|
|
|
println('Build failed')
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -99,13 +99,37 @@ fn get_content(path string) !string {
|
|
|
|
return markdown.to_html(md)
|
|
|
|
return markdown.to_html(md)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn check_layout(path string) bool {
|
|
|
|
|
|
|
|
// check if layout is specified in front matter
|
|
|
|
|
|
|
|
// if not, use default layout
|
|
|
|
|
|
|
|
// if specified, check if layout file exists
|
|
|
|
|
|
|
|
// if not, return error
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn (mut b Builder) md2html(md_path string) ! {
|
|
|
|
fn (mut b Builder) md2html(md_path string) ! {
|
|
|
|
// get html body content from md
|
|
|
|
// get html body content from md
|
|
|
|
|
|
|
|
b.logger.info('start md to html: ${md_path}')
|
|
|
|
content := get_content(md_path)!
|
|
|
|
content := get_content(md_path)!
|
|
|
|
// want to change from contents to content
|
|
|
|
// want to change from contents to content
|
|
|
|
b.config_map['contents'] = content
|
|
|
|
b.config_map['contents'] = content
|
|
|
|
html := template.parse(b.template_content, b.config_map)
|
|
|
|
|
|
|
|
|
|
|
|
// parse template
|
|
|
|
html_path := get_html_path(md_path)
|
|
|
|
html_path := get_html_path(md_path)
|
|
|
|
|
|
|
|
dir := os.dir(md_path)
|
|
|
|
|
|
|
|
mut template_content := ''
|
|
|
|
|
|
|
|
if os.exists('layouts/${html_path}') {
|
|
|
|
|
|
|
|
b.logger.info('use custom template: layouts/${html_path}')
|
|
|
|
|
|
|
|
template_content = os.read_file('layouts/${html_path}')!
|
|
|
|
|
|
|
|
} else if os.exists('layouts/${dir}/index.html') {
|
|
|
|
|
|
|
|
b.logger.info('use custom template: layouts/${dir}/index.html')
|
|
|
|
|
|
|
|
template_content = os.read_file('layouts/${dir}/index.html')!
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
b.logger.info('use default template')
|
|
|
|
|
|
|
|
template_content = b.template_content
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
html := template.parse(template_content, b.config_map)
|
|
|
|
dist_path := os.join_path(b.dist, html_path)
|
|
|
|
dist_path := os.join_path(b.dist, html_path)
|
|
|
|
if !os.exists(os.dir(dist_path)) {
|
|
|
|
if !os.exists(os.dir(dist_path)) {
|
|
|
|
os.mkdir_all(os.dir(dist_path))!
|
|
|
|
os.mkdir_all(os.dir(dist_path))!
|
|
|
@ -148,14 +172,14 @@ fn (mut b Builder) is_ignore(path string) bool {
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn build(config config.Config, mut logger log.Log) ! {
|
|
|
|
fn build(conf config.Config, mut logger log.Log) ! {
|
|
|
|
println('Start building')
|
|
|
|
println('Start building')
|
|
|
|
mut sw := time.new_stopwatch()
|
|
|
|
mut sw := time.new_stopwatch()
|
|
|
|
mut b := new_builder(logger)
|
|
|
|
mut b := new_builder(logger)
|
|
|
|
template_content := os.read_file(commands.default_template)!
|
|
|
|
template_content := os.read_file(commands.default_template)!
|
|
|
|
b.template_content = template_content
|
|
|
|
b.template_content = template_content
|
|
|
|
b.config = config
|
|
|
|
b.config = conf
|
|
|
|
b.config_map = config.as_map()
|
|
|
|
b.config_map = conf.as_map()
|
|
|
|
|
|
|
|
|
|
|
|
b.create_dist_dir()!
|
|
|
|
b.create_dist_dir()!
|
|
|
|
// copy static dir files
|
|
|
|
// copy static dir files
|
|
|
@ -166,7 +190,7 @@ fn build(config config.Config, mut logger log.Log) ! {
|
|
|
|
logger.info('start md to html')
|
|
|
|
logger.info('start md to html')
|
|
|
|
for path in mds {
|
|
|
|
for path in mds {
|
|
|
|
if b.is_ignore(path) {
|
|
|
|
if b.is_ignore(path) {
|
|
|
|
logger.info('$path is included in ignore_files, skip build')
|
|
|
|
logger.info('${path} is included in ignore_files, skip build')
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
b.md2html(path)!
|
|
|
|
b.md2html(path)!
|
|
|
|