Browse Source

correct url in test mode

master
alistair 3 years ago
parent
commit
7c0095a7f9
  1. 2853
      darkhttpd.c
  2. 37
      main.cpp
  3. 8
      templater.hpp

2853
darkhttpd.c

File diff suppressed because it is too large Load Diff

37
main.cpp

@ -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;
}

8
templater.hpp

@ -233,9 +233,6 @@ class ifdef_plugin : public substitution_plugin { @@ -233,9 +233,6 @@ class ifdef_plugin : public substitution_plugin {
std::string subst_text = "";
val.body = args.at(2); // invocation.substr(val.second + 1);
spdlog::info("IFDEF: '{}'", name);
spdlog::info("IFDEF replacewith: '{}'", val.body);
if (properties.count(name)) {
val.name_exists = true;
}
@ -685,7 +682,6 @@ std::multimap<time_t, blog_item> get_sorted_post_list(const std::string &cs_dire @@ -685,7 +682,6 @@ std::multimap<time_t, blog_item> get_sorted_post_list(const std::string &cs_dire
}
paths.push_back(path);
spdlog::info("path {}", path.string());
first = next + 1;
next = relpath.find(",", first);
@ -693,7 +689,6 @@ std::multimap<time_t, blog_item> get_sorted_post_list(const std::string &cs_dire @@ -693,7 +689,6 @@ std::multimap<time_t, blog_item> get_sorted_post_list(const std::string &cs_dire
std::multimap<time_t, blog_item> feed_items;
spdlog::info("numpaths {}", paths.size());
for (std::string dir: paths) {
@ -862,9 +857,6 @@ class templater { @@ -862,9 +857,6 @@ class templater {
s2_substitution_commands.insert({s->hook_name(), s});
}
for (auto s : substitution_commands) {
spdlog::info("{}: thing", s.first);
}
}

Loading…
Cancel
Save