a0282402f19cab78cde4fbc7bec95c3c88828396 — Thomas Landin 7 months ago f7dd054
Add recursive searching for config.cfg

Now it will let you build your site anywhere inside your site's folder
structure and give you a nicer error message if you run the build
command in the wrong folder (no config.cfg found).

It would also let you share a config.cfg between two sites by placing it
in a parent directory to the two sites:


Not sure why you'd want to do that, but the tool will let you anyway :)
1 files changed, 14 insertions(+), 1 deletions(-)

M src/dtt.nim
M src/dtt.nim => src/dtt.nim +14 -1
@@ 197,6 197,13 @@ proc findBlogPosts(directory: string, tmpldir: string): seq[Table[string, string
  sort(result, dateSort, Descending)

proc findConfigFile(full_path: string): Config =
  let (path, name) = splitPath(full_path)
  for p in parentDirs(path):
      if existsFile(p / name):
        return loadConfig(p / name)
  raise new IOError

proc buildCmd() =
    wd = os.getCurrentDir()

@@ 209,7 216,13 @@ proc buildCmd() =
  if not existsDir(outdir):

  let config = loadConfig(wd / "config.cfg")
  let config = try:
    findConfigFile(wd / "config.cfg")
  except IOError:
    stderr.writeLine(fmt"{bin}: Could not find a config.cfg file. Is this a dtt directory?")

  # let config = try: findConfig(wd / "config.cfg") except IOError: false
  loadMetaData(config, mcontext)
  let blogs = findBlogPosts(condir, tmpldir)
  mcontext["links"] = findLinks(condir, excludes=blogs)