fixed bugs and reduced line count

Signed-off-by: Sarmonsiill <sarmonsiill@tilde.guru>
This commit is contained in:
Sarmonsiill 2023-01-07 11:38:23 +00:00
parent 473102460a
commit 8fed1d6777
1 changed files with 17 additions and 19 deletions

View File

@ -11,17 +11,16 @@ const (
)
struct Cfg {
base_directory string = '${os.getenv('HOME')}/.gtc_gen'
editor string = os.getenv('EDITOR')
base_directory string = '${os.getenv('HOME')}/.gtc_gen'
application_name string = 'gtc_gen'
about_file string = '${os.getenv('HOME')}/.gtc_gen.about'
auth string = genv('GTC_GEN_AUTH', 'unknown')
mail string = genv('GTC_GEN_MAIL', 'unknown@example.org')
site_name string = genv('GTC_GEN_SITE', 'gtc_gen -site')
target string = genv('GTC_GEN_TARGET', './site')
url string = genv('GTC_GEN_URL', 'https://example.org')
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>'
about_file string = '${os.getenv('HOME')}/.gtc_gen.about'
auth string = genv('GTC_GEN_AUTH', 'unknown')
mail string = genv('GTC_GEN_MAIL', 'unknown@example.org')
site_name string = genv('GTC_GEN_SITE', 'gtc_gen -site')
target string = genv('GTC_GEN_TARGET', './site')
url string = genv('GTC_GEN_URL', 'https://example.org')
entries_dir string = os.join_path(genv('GTC_GEN_TARGET', './site'),'entries')
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() {
@ -29,21 +28,17 @@ fn main() {
if !os.is_dir(c.base_directory) {os.mkdir(c.base_directory) or {panic(err)}}
if os.args.len != 2 { help() }
match os.args[1] {
'a' { os.execvp(c.editor,
[os.join_path(c.base_directory, '${now().unix}.post')])
or { panic(err) } }
'a' { os.execvp(genv('EDITOR', 'vi'), [os.join_path(c.base_directory, '${now().unix}.post')]) or { panic(err) } }
'm' { c.make() }
else { help() }
}
}
fn genv(k string, d string) string {
if os.getenv(k) != '' { return os.getenv(k) } else {return d}
}
fn genv(k string, d string) string { if os.getenv(k) != '' { return os.getenv(k) } else {return d} }
fn parse_links(input string) string {
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>")}
return output
}
@ -54,7 +49,10 @@ fn (c Cfg) make_entries_list() string {
for p in posts {
content := os.read_file(p) or { panic(err) }
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')
ts := time.unix(name.int())
title := lines[0].capitalize()
@ -90,7 +88,7 @@ fn help() {
println("gtc_gen - made by sarmonsiill <sarmonsiill@tilde.guru>\n
\tgtc_gen a\tadd a new post\n\tgtc_gen m\ttranspile posts
\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://
\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.")