fixed bugs and reduced line count
Signed-off-by: Sarmonsiill <sarmonsiill@tilde.guru>
This commit is contained in:
parent
473102460a
commit
8fed1d6777
36
gtc_gen.v
36
gtc_gen.v
|
@ -11,17 +11,16 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
struct Cfg {
|
struct Cfg {
|
||||||
base_directory string = '${os.getenv('HOME')}/.gtc_gen'
|
base_directory string = '${os.getenv('HOME')}/.gtc_gen'
|
||||||
editor string = os.getenv('EDITOR')
|
|
||||||
application_name string = 'gtc_gen'
|
application_name string = 'gtc_gen'
|
||||||
about_file string = '${os.getenv('HOME')}/.gtc_gen.about'
|
about_file string = '${os.getenv('HOME')}/.gtc_gen.about'
|
||||||
auth string = genv('GTC_GEN_AUTH', 'unknown')
|
auth string = genv('GTC_GEN_AUTH', 'unknown')
|
||||||
mail string = genv('GTC_GEN_MAIL', 'unknown@example.org')
|
mail string = genv('GTC_GEN_MAIL', 'unknown@example.org')
|
||||||
site_name string = genv('GTC_GEN_SITE', 'gtc_gen -site')
|
site_name string = genv('GTC_GEN_SITE', 'gtc_gen -site')
|
||||||
target string = genv('GTC_GEN_TARGET', './site')
|
target string = genv('GTC_GEN_TARGET', './site')
|
||||||
url string = genv('GTC_GEN_URL', 'https://example.org')
|
url string = genv('GTC_GEN_URL', 'https://example.org')
|
||||||
entries_dir string = os.join_path(genv('GTC_GEN_TARGET', './site'),'entries')
|
entries_dir string = os.join_path(genv('GTC_GEN_TARGET', './site'),'entries')
|
||||||
copyleft string = 'License: <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC-BY-SA-4.0</a>'
|
copyleft string = genv('GTC_GEN_LICENSE', 'License: <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC-BY-SA-4.0</a>')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -29,21 +28,17 @@ fn main() {
|
||||||
if !os.is_dir(c.base_directory) {os.mkdir(c.base_directory) or {panic(err)}}
|
if !os.is_dir(c.base_directory) {os.mkdir(c.base_directory) or {panic(err)}}
|
||||||
if os.args.len != 2 { help() }
|
if os.args.len != 2 { help() }
|
||||||
match os.args[1] {
|
match os.args[1] {
|
||||||
'a' { os.execvp(c.editor,
|
'a' { os.execvp(genv('EDITOR', 'vi'), [os.join_path(c.base_directory, '${now().unix}.post')]) or { panic(err) } }
|
||||||
[os.join_path(c.base_directory, '${now().unix}.post')])
|
|
||||||
or { panic(err) } }
|
|
||||||
'm' { c.make() }
|
'm' { c.make() }
|
||||||
else { help() }
|
else { help() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn genv(k string, d string) string {
|
fn genv(k string, d string) string { if os.getenv(k) != '' { return os.getenv(k) } else {return d} }
|
||||||
if os.getenv(k) != '' { return os.getenv(k) } else {return d}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_links(input string) string {
|
fn parse_links(input string) string {
|
||||||
mut re := regex.regex_opt(query) or { panic(err) }
|
mut re := regex.regex_opt(query) or { panic(err) }
|
||||||
mut output := ''
|
mut output := input
|
||||||
for l in re.find_all_str(input) {output=input.replace(l, "<a href='${l}' target='_blank'>${l}</a>")}
|
for l in re.find_all_str(input) {output=input.replace(l, "<a href='${l}' target='_blank'>${l}</a>")}
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
@ -54,7 +49,10 @@ fn (c Cfg) make_entries_list() string {
|
||||||
for p in posts {
|
for p in posts {
|
||||||
content := os.read_file(p) or { panic(err) }
|
content := os.read_file(p) or { panic(err) }
|
||||||
lines := content.split_into_lines()
|
lines := content.split_into_lines()
|
||||||
if lines.len < 1 { continue }
|
if lines.len < 1 {
|
||||||
|
println("$p has no lines")
|
||||||
|
continue
|
||||||
|
}
|
||||||
name := p.split('/').last().trim('.post')
|
name := p.split('/').last().trim('.post')
|
||||||
ts := time.unix(name.int())
|
ts := time.unix(name.int())
|
||||||
title := lines[0].capitalize()
|
title := lines[0].capitalize()
|
||||||
|
@ -90,7 +88,7 @@ fn help() {
|
||||||
println("gtc_gen - made by sarmonsiill <sarmonsiill@tilde.guru>\n
|
println("gtc_gen - made by sarmonsiill <sarmonsiill@tilde.guru>\n
|
||||||
\tgtc_gen a\tadd a new post\n\tgtc_gen m\ttranspile posts
|
\tgtc_gen a\tadd a new post\n\tgtc_gen m\ttranspile posts
|
||||||
\n--\nEnvironment variables\n\n\tGTC_GEN_AUTH\tname of author
|
\n--\nEnvironment variables\n\n\tGTC_GEN_AUTH\tname of author
|
||||||
\tGTC_GEN_MAIL\temail of author\n\tGTC_GEN_SITE\tsite title
|
\tGTC_GEN_MAIL\temail of author\n\tGTC_GEN_SITE\tsite title\n\tGTC_GEN_LICENSE\tlicense of the content
|
||||||
\tGTC_GEN_TARGET\tsite output\n\tGTC_GEN_URL\tdomain of the site. incl https://
|
\tGTC_GEN_TARGET\tsite output\n\tGTC_GEN_URL\tdomain of the site. incl https://
|
||||||
\nFirst line of the post will become the header. Filename will become timestamp.
|
\nFirst line of the post will become the header. Filename will become timestamp.
|
||||||
posts are stored in \$HOME/.gtc_gen\n~/.gtc_gen.about is uses as an about -section on the index.")
|
posts are stored in \$HOME/.gtc_gen\n~/.gtc_gen.about is uses as an about -section on the index.")
|
||||||
|
|
Loading…
Reference in New Issue