~kungtotte/dtt

6df7e90e8a9560e56d7148eb83285a9788df94ce — Thomas Landin 2 months ago d203635
Added a findBaseDir proc to search for a dtt dir

We don't use the config.cfg file anymore so I needed a better way to
find a dtt directory, now it will scan for a content directory upwards
and error out if it can't find it.

Should make it check for content + template to be really sure it won't
conk out.
2 files changed, 16 insertions(+), 8 deletions(-)

M src/dtt.nim
M src/utils.nim
M src/dtt.nim => src/dtt.nim +3 -8
@@ 9,10 9,6 @@ import utils

const
  bin = "dtt"
  css_dir = "css"
  content_dir = "content"
  template_dir = "templates"
  output_dir = "output"
  outFilePerms = {fpUserExec, fpUserWrite, fpUserRead, fpGroupExec,
                  fpGRoupRead, fpOthersExec, fpOthersRead}



@@ 99,11 95,10 @@ proc cleanCmd(all: bool = false, force: bool = false) =
    quit(ord(DttError.DirectoryNotFound))

proc buildCmd(posts_per_page: int = 5) =
  # TODO: Rationalized the config.cfg away! Scan for directory structure instead
  let (_, working_dir) = try:
    findConfigFile(os.getCurrentDir() / "config.cfg")
  let working_dir = try:
    findBaseDir(os.getCurrentDir())
  except IOError:
    stderr.writeLine(fmt"{bin}: Could not find a config.cfg file. Is this a dtt directory?")
    stderr.writeLine(fmt"{bin}: Could not find a content folder. Is this a dtt directory?")
    quit(ord(DttError.NotADttDirectory))
  let
    content_dir = working_dir / content_dir

M src/utils.nim => src/utils.nim +13 -0
@@ 6,6 6,10 @@ import markdown
import mustache

const
  css_dir* = "css"
  content_dir* = "content"
  template_dir* = "templates"
  output_dir* = "output"
  blog_dirs = ["blog", "blogs", "post", "posts", "articles", "journal", "journals"]

type


@@ 94,6 98,15 @@ proc buildBlogPost*(full_path: string, tmpl_dir: string): BlogPost =
  result.url = target
  result.content = rendered

proc findBaseDir*(starting_dir: string): string =
  if existsDir(starting_dir / content_dir):
    return starting_dir
  let (path, _) = splitPath(starting_dir)
  for p in parentDirs(path):
    if existsDir(p / content_dir):
      return p
  raise new IOError

proc findConfigFile*(full_path: string): tuple[cfg: Config, wd: string] =
  let (path, name) = splitPath(full_path)
  for p in parentDirs(path):