-
Notifications
You must be signed in to change notification settings - Fork 0
/
blogit.nim
56 lines (43 loc) · 1.62 KB
/
blogit.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const doc = """
Blogit - A custom, awesome and fun static site generator.
Usage:
blogit generate <filename>
Options:
-h --help Show this message.
--version Show version.
"""
const welcome_message = """
╔═════════════════════════════════════════════════════════════════════════╗
╠═ 🐱 Blogit v0.1.0 - a custom, awesome and fun static site generator 🐱 ═╣
╚═════════════════════════════════════════════════════════════════════════╝
"""
import docopt
import strformat
import os
import results
import logging
import metadata
let logger = newConsoleLogger(fmtStr="[$datetime] - $appname - $levelname: ")
addHandler(logger)
let args = docopt(doc, version="Blogit 0.1.0")
echo welcome_message
when isMainModule:
if args["generate"]:
let file = args["<filename>"]
if not fileExists($file):
error fmt"File '{file}' not found; exiting"
quit -1
if splitFile($file).ext != ".md":
error "File given is not a Markdown file; exiting"
quit -1
var entireFile: string
try:
entireFile = readFile($file)
except IOError as e:
error fmt"There was an error trying to open the file. Error: {e.msg}; exiting"
quit -1
let metadataResult = parseMetadata(entireFile)
if metadataResult.isErr:
error metadataResult.error.message
quit -1
echo metadataResult.get