Change license. Add about-section. Fix bugs

This commit is contained in:
Sarmonsiill 2021-10-27 10:12:43 +00:00
parent e8005686c3
commit 82b8200632

View File

@ -8,6 +8,7 @@ const (
bdir = '${os.getenv('HOME')}/.gtc_gen' bdir = '${os.getenv('HOME')}/.gtc_gen'
ed = os.getenv('EDITOR') ed = os.getenv('EDITOR')
name = 'gtc_gen' name = 'gtc_gen'
afile = '${os.getenv('HOME')}/.gtc_gen.about'
/* regexp */ /* regexp */
query = r"(?P<format>https?)|(?P<format>ftps?)://(?P<token>[\w_]+.)+" query = r"(?P<format>https?)|(?P<format>ftps?)://(?P<token>[\w_]+.)+"
@ -45,7 +46,7 @@ fn make() {
trgt := genv('GTC_GEN_TARGET', './site') trgt := genv('GTC_GEN_TARGET', './site')
url := genv('GTC_GEN_URL', 'https://example.org') url := genv('GTC_GEN_URL', 'https://example.org')
ptrgt := os.join_path(trgt, 'entries') ptrgt := os.join_path(trgt, 'entries')
cp_rgt := 'copyleft $auth ($mail)' cp_rgt := 'License: <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC-BY-SA-4.0</a>'
if !os.is_dir(ptrgt) {os.mkdir_all(ptrgt) or { panic(err) }} if !os.is_dir(ptrgt) {os.mkdir_all(ptrgt) or { panic(err) }}
fls := os.glob('$bdir/*.post') or { panic(err) } fls := os.glob('$bdir/*.post') or { panic(err) }
mut indx_arr := []string{} mut indx_arr := []string{}
@ -69,8 +70,19 @@ $lt.ymmdd() $lt.hhmm() by $auth ($mail)</p>
ftr.replace('::FTR::', cp_rgt)) or { panic(err) } ftr.replace('::FTR::', cp_rgt)) or { panic(err) }
} }
indx_arr = indx_arr.reverse() indx_arr = indx_arr.reverse()
/* if we find ~/.gtc_gen.about we use that text content as an about
* -section on the index page. */
mut about := ''
if os.is_file(afile) {
acnt := os.read_file(afile) or { panic(err) }
about = '<h2>About</h2><p>${acnt}</p><hr />'
lnks := re.find_all_str(about)
for lnk in lnks {
about = about.replace(lnk, "<a href='${lnk}' target='_blank'>${lnk}</a>")
}
}
os.write_file(os.join_path(trgt, 'index.html'), hdr.replace('::TTL::', site) + os.write_file(os.join_path(trgt, 'index.html'), hdr.replace('::TTL::', site) +
"<h1><a href='$url'>$site</a></h1><ul>${indx_arr.join('')}</ul>" + "<h1><a href='$url'>$site</a></h1>${about}<ul>${indx_arr.join('')}</ul>" +
ftr.replace('::FTR::', cp_rgt)) or { panic(err) } ftr.replace('::FTR::', cp_rgt)) or { panic(err) }
} }
@ -86,6 +98,7 @@ fn help() {
\tGTC_GEN_URL\tThe domain of the site. Don't forget to include https:// or http:// \tGTC_GEN_URL\tThe domain of the site. Don't forget to include https:// or http://
\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.
Raw posts are stored in \$HOME/.gtc_gen Raw posts are stored in \$HOME/.gtc_gen
If ~/.gtc_gen.about exists it uses that text content as an about -section on the index.
That is it.") That is it.")
exit(1) exit(1)
} }