|
|
|
@ -35,6 +35,7 @@ const std::string DEFAULT_SOURCE_DIR = ".";
@@ -35,6 +35,7 @@ const std::string DEFAULT_SOURCE_DIR = ".";
|
|
|
|
|
const std::string TEMPLATE_FILEEXT = "template"; |
|
|
|
|
const std::string DEFAULT_WATCH_FILETYPES[] = {"md", "markdown", TEMPLATE_FILEEXT}; |
|
|
|
|
const std::string DEFAULT_IGNORE_FILES[] = {SITE_CONFIG_FNAME}; |
|
|
|
|
const std::string TEST_URL = "http://localhost:8000"; |
|
|
|
|
|
|
|
|
|
using json = nlohmann::json; |
|
|
|
|
namespace fs = std::filesystem; |
|
|
|
@ -42,6 +43,8 @@ namespace fs = std::filesystem;
@@ -42,6 +43,8 @@ namespace fs = std::filesystem;
|
|
|
|
|
struct runtime_config { |
|
|
|
|
bool no_interactive = false; |
|
|
|
|
bool save_config = false; |
|
|
|
|
bool test = false; |
|
|
|
|
std::set<std::string> readonly_properties {}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
runtime_config settings; |
|
|
|
@ -141,6 +144,7 @@ class builder {
@@ -141,6 +144,7 @@ class builder {
|
|
|
|
|
properties["current_directory"] = directory; |
|
|
|
|
|
|
|
|
|
// update the properties map if there is a new cconfig file
|
|
|
|
|
// and not in testing mode
|
|
|
|
|
fs::path confname = fs::path(directory) / SITE_CONFIG_FNAME; |
|
|
|
|
|
|
|
|
|
if (fs::exists(confname)) { |
|
|
|
@ -150,7 +154,8 @@ class builder {
@@ -150,7 +154,8 @@ class builder {
|
|
|
|
|
|
|
|
|
|
// dump json into properties map
|
|
|
|
|
for (json::iterator it = parse_json.begin(); it != parse_json.end(); ++it) { |
|
|
|
|
properties[it.key()] = it.value(); |
|
|
|
|
if (!settings.readonly_properties.count(it.key())) |
|
|
|
|
properties[it.key()] = it.value(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -611,6 +616,7 @@ std::map<std::string, std::string> parse_options (int argc, char **argv) {
@@ -611,6 +616,7 @@ std::map<std::string, std::string> parse_options (int argc, char **argv) {
|
|
|
|
|
("d,documentation", "Show in-depth documentation") |
|
|
|
|
("s,save-config", "Save the configuration used to build the site to src/stgen.json") |
|
|
|
|
("y,noninteractive", "Non-interactive mode (confirm everything)") |
|
|
|
|
("t,test", "Start internal server and build in test mode") |
|
|
|
|
("n,name", "Site name, defaults to $source", cxxopts::value<std::string>())
|
|
|
|
|
("u,url", "Site url, defaults to file://$destination", cxxopts::value<std::string>()) |
|
|
|
|
("a,author", "Site author", cxxopts::value<std::string>()) |
|
|
|
@ -636,6 +642,10 @@ std::map<std::string, std::string> parse_options (int argc, char **argv) {
@@ -636,6 +642,10 @@ std::map<std::string, std::string> parse_options (int argc, char **argv) {
|
|
|
|
|
if (result.count("save-config")) { |
|
|
|
|
settings.save_config = true; |
|
|
|
|
} |
|
|
|
|
if (result.count("test")) { |
|
|
|
|
settings.readonly_properties.insert("url"); |
|
|
|
|
settings.test = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (result.count("help")) |
|
|
|
|
{ |
|
|
|
@ -684,11 +694,17 @@ std::map<std::string, std::string> parse_options (int argc, char **argv) {
@@ -684,11 +694,17 @@ std::map<std::string, std::string> parse_options (int argc, char **argv) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (settings.test) { |
|
|
|
|
parsed_opts["url"] = TEST_URL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (result.count("noninteractive")) |
|
|
|
|
{ |
|
|
|
|
settings.no_interactive = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return parsed_opts; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -732,14 +748,23 @@ int main(int argc, char **argv) {
@@ -732,14 +748,23 @@ int main(int argc, char **argv) {
|
|
|
|
|
// folder.
|
|
|
|
|
|
|
|
|
|
auto cmd_options = parse_options(argc, argv); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stgen::builder b (cmd_options); |
|
|
|
|
b.build(); |
|
|
|
|
|
|
|
|
|
server s {}; |
|
|
|
|
s.serve_now("./llll", "8080", "127.0.0.1"); |
|
|
|
|
|
|
|
|
|
unsigned int microsecond = 1000000; |
|
|
|
|
usleep(100000 * microsecond);//sleeps for 3 second
|
|
|
|
|
if (settings.test) { |
|
|
|
|
server s {}; |
|
|
|
|
s.serve_now(cmd_options.at("publish_root"), "8000", "127.0.0.1"); |
|
|
|
|
spdlog::info("Rebuilding every 5 seconds."); |
|
|
|
|
while (true) { |
|
|
|
|
b.build(); |
|
|
|
|
unsigned int microsecond = 1000000; |
|
|
|
|
usleep(5 * microsecond);//sleeps for 3 second
|
|
|
|
|
spdlog::info("Rebuilt."); |
|
|
|
|
} |
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|