diff --git a/Taskfile.yml b/Taskfile.yml index a83c843..f11fd27 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -41,8 +41,9 @@ tasks: desc: Format .v files cmds: - v fmt -w *.v - - v fmt -w commands/*.v - - v fmt -w template/*.v + - v fmt -w commands + - v fmt -w internal/template + - v fmt -w internal/config/ clean: desc: Clean test files diff --git a/commands/build.v b/commands/build.v index 4e19c91..bc59697 100644 --- a/commands/build.v +++ b/commands/build.v @@ -7,12 +7,12 @@ import time import toml import regex import markdown -import template +import internal.template const default_config = 'config.toml' // Allowed parameters -const config_params = ['title', 'description', 'baseUrl'] +const config_params = ['title', 'description', 'baseUrl', 'build'] const default_template = 'layouts/index.html' diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..93fb8e7 --- /dev/null +++ b/example/README.md @@ -0,0 +1,3 @@ +# Example project + +This is vss example project. diff --git a/example/config.toml b/example/config.toml index 0048965..7cb55ce 100644 --- a/example/config.toml +++ b/example/config.toml @@ -1,6 +1,6 @@ title = "Open Sea" description = "Takumi Tsuruta's home page" -# baseUrl = 'https://zztkm.github.io/vss/' +# base_url = 'https://zztkm.github.io/vss/' [build] -ignoreFiles = ["ignore.md", "README.md"] \ No newline at end of file +ignore_files = ["ignore.md", "README.md"] \ No newline at end of file diff --git a/internal/config/config.v b/internal/config/config.v new file mode 100644 index 0000000..005e0ff --- /dev/null +++ b/internal/config/config.v @@ -0,0 +1,32 @@ +module config + +import toml + +// Build settings for build +struct Build { +pub mut: + ignore_files []string +} + +struct Config { +pub mut: + build Build + title string + description string + base_url string +} + +// load +pub fn load(toml_text string) ?Config { + doc := toml.parse_text(toml_text)? + + mut config := doc.reflect() + config.build = doc.value('build').reflect() + + return config +} + +// as_map for template.parse +pub fn (c Config) as_map() ?map[string]string { + +} \ No newline at end of file diff --git a/internal/config/config_test.v b/internal/config/config_test.v new file mode 100644 index 0000000..968ce49 --- /dev/null +++ b/internal/config/config_test.v @@ -0,0 +1,22 @@ +module config + +const toml_text = '# for test +title = "test site" +description = "test page" +base_url = "https://vss.github.io/vss/" + +[build] +ignore_files = ["ignore.md", "README.md"] +' + +fn test_load() { + config := load(config.toml_text) or { + eprintln(err) + return + } + + assert config.title == 'test site' + assert config.description == 'test page' + assert config.base_url == 'https://vss.github.io/vss/' + assert config.build.ignore_files == ['ignore.md', 'README.md'] +}