slweb

Једноставни генератор статичких веб страна
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување b30d2adab8047a27fa7baa30f887510bf3f28f78
родитељ a16c8d750af0e2f104fc85f73d2848b274b126b5
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Sun, 31 Jan 2021 15:54:11 +0100

Added article header and variables: add-article-header, author, header-text

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
Mindex.html | 2+-
Mslweb.1.in | 20++++++++++++++++++--
Mslweb.c | 120++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
измењених датотека: 3, додавања: 95(+), брисања: 47(-)

diff --git a/index.html b/index.html @@ -136,7 +136,7 @@ this program. If not, see &lt;<a href="https://www.gnu.org/licenses">https://www <div id="git-log"> Previous commit: -index.slw d29a55b 2021-01-30 21:41:33 +0100 (Страхиња Радић) (HEAD -> master, origin/master, origin/HEAD) +index.slw a16c8d7 2021-01-30 22:52:17 +0100 (Страхиња Радић) (HEAD -> master, origin/master, origin/HEAD) </div><!--git-log--> diff --git a/slweb.1.in b/slweb.1.in @@ -613,6 +613,11 @@ directive. (See .SS Special YAML variables . .IP \[bu] 4 +.BR add-article-header . +If set to \[lq]1\[rq], title, date and header text at the beginning of the +output body will be enclosed in a \fC<header>\fP tag. +. +.IP \[bu] .BR add-figcaption . If set to \[lq]0\[rq], \fC<figure>\fP and \fC<figcaption>\fP tags around images will not be added (otherwise they will by default, see @@ -631,6 +636,12 @@ will by default, see .BR Images ). . .IP \[bu] +.BR author . +If set, the contents of this variable will be added to the start of the output +body (inside a \fC<header>\fP tag if it is set), surrounded by +\fC<address></address>\fP. +. +.IP \[bu] .BR csv-delimiter . Changes the delimiter used for .I .csv @@ -667,6 +678,11 @@ will be used as a favicon instead of the default, \fC/favicon.ico\fP. . .IP \[bu] +.BR header-text . +The contents of this variable will be added to the start of the output body +(inside a \fC<header>\fP tag if it is set), surrounded by \fC<p></p>\fP. +. +.IP \[bu] .BR permalink-url . If present, this .SM URL @@ -715,8 +731,8 @@ file. . .IP \[bu] .BR title . -If present, contents of this variable will be prepended to the body as a heading -with the level determined by the +If present, contents of this variable will be prepended to the body (inside a +\fC<header>\fP tag if it is set) as a heading with the level determined by the .I title-heading-level variable, defaulting to 2. (\fCtitle: Some title\fP becomes \fC<h2>Some title</h2>\fP). diff --git a/slweb.c b/slweb.c @@ -1614,6 +1614,60 @@ end_head_start_body(FILE* output) } int +begin_article(FILE* output, const BOOL add_article_header, + const uint8_t* author, const uint8_t* title, + const uint8_t* header_text, const char* title_heading_level, + uint8_t* date, const BOOL ext_in_permalink, const char* permalink_url) +{ + if (title || date) + print_output(output, "<header>\n"); + + if (title) + print_output(output, "<h%s>%s</h%s>\n", + title_heading_level ? title_heading_level : "2", + (char*)title, + title_heading_level ? title_heading_level : "2"); + + if (header_text) + print_output(output, "<p>%s</p>\n", (char*)header_text); + + if (author) + print_output(output, "<address>%s</address>\n", author); + + if (date && input_filename) + { + char* link = strip_ext(input_filename); + uint8_t* samedir_permalink = get_value(vars, vars_count, + (uint8_t*)"samedir-permalink", NULL); + char* real_link = NULL; + uint8_t* permalink_macro = get_value(macros, macros_count, + (uint8_t*)"permalink", NULL); + CALLOC(real_link, char, BUFSIZE) + + if (ext_in_permalink) + strncat(link, timestamp_output_ext, BUFSIZE-strlen(link)-1); + + if (permalink_url) + process_timestamp(output, permalink_url, permalink_macro, date); + else if (samedir_permalink && !u8_strcmp(samedir_permalink, (uint8_t*)"1")) + { + get_realpath(&real_link, input_dirname, link); + process_timestamp(output, real_link, permalink_macro, date); + } + else + process_timestamp(output, link, permalink_macro, date); + + free(real_link); + free(link); + } + + if (title || date) + print_output(output, "</header>\n"); + + return 0; +} + +int end_footnotes(FILE* output, BOOL add_footnote_div) { size_t footnote = 0; @@ -1666,9 +1720,12 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only, { uint8_t* title = NULL; uint8_t* title_heading_level = NULL; + uint8_t* header_text = NULL; + uint8_t* author = NULL; uint8_t* date = NULL; uint8_t* permalink_url = NULL; uint8_t* ext_in_permalink = NULL; + uint8_t* var_add_article_header = NULL; uint8_t* var_add_image_links = NULL; uint8_t* var_add_figcaption = NULL; uint8_t* var_add_footnote_div = NULL; @@ -1709,18 +1766,21 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only, if (!macros) exit(error(EINVAL, (uint8_t*)"Invalid argument (macros)")); - title = get_value(vars, vars_count, (uint8_t*)"title", NULL); - title_heading_level = get_value(vars, vars_count, + title = get_value(vars, vars_count, (uint8_t*)"title", NULL); + title_heading_level = get_value(vars, vars_count, (uint8_t*)"title-heading-level", NULL); - date = get_value(vars, vars_count, (uint8_t*)"date", NULL); - permalink_url = get_value(vars, vars_count, (uint8_t*)"permalink-url", NULL); - ext_in_permalink = get_value(vars, vars_count, (uint8_t*)"ext-in-permalink", NULL); - var_add_image_links = get_value(vars, vars_count, (uint8_t*)"add-image-links", NULL); - add_image_links = !(var_add_image_links && *var_add_image_links == '0'); - var_add_figcaption = get_value(vars, vars_count, (uint8_t*)"add-figcaption", NULL); - add_figcaption = !(var_add_figcaption && *var_add_figcaption == '0'); - var_add_footnote_div = get_value(vars, vars_count, (uint8_t*)"add-footnote-div", NULL); - add_footnote_div = var_add_footnote_div && *var_add_footnote_div == '1'; + header_text = get_value(vars, vars_count, (uint8_t*)"header-text", NULL); + author = get_value(vars, vars_count, (uint8_t*)"author", NULL); + date = get_value(vars, vars_count, (uint8_t*)"date", NULL); + permalink_url = get_value(vars, vars_count, (uint8_t*)"permalink-url", NULL); + ext_in_permalink = get_value(vars, vars_count, (uint8_t*)"ext-in-permalink", NULL); + var_add_article_header = get_value(vars, vars_count, (uint8_t*)"add-article-header", NULL); + var_add_image_links = get_value(vars, vars_count, (uint8_t*)"add-image-links", NULL); + add_image_links = !(var_add_image_links && *var_add_image_links == '0'); + var_add_figcaption = get_value(vars, vars_count, (uint8_t*)"add-figcaption", NULL); + add_figcaption = !(var_add_figcaption && *var_add_figcaption == '0'); + var_add_footnote_div = get_value(vars, vars_count, (uint8_t*)"add-footnote-div", NULL); + add_footnote_div = var_add_footnote_div && *var_add_footnote_div == '1'; CALLOC(line, uint8_t, BUFSIZE) token_size = BUFSIZE; @@ -1741,39 +1801,11 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only, end_head_start_body(output); } - if (title) - print_output(output, "<h%s>%s</h%s>\n", - title_heading_level ? (char*)title_heading_level : "2", - (char*)title, - title_heading_level ? (char*)title_heading_level : "2"); - - if (date && input_filename) - { - char* link = strip_ext(input_filename); - uint8_t* samedir_permalink = get_value(vars, vars_count, - (uint8_t*)"samedir-permalink", NULL); - char* real_link = NULL; - uint8_t* permalink_macro = get_value(macros, macros_count, - (uint8_t*)"permalink", NULL); - CALLOC(real_link, char, BUFSIZE) - - if (ext_in_permalink && *ext_in_permalink != (ucs4_t)'0') - strncat(link, timestamp_output_ext, BUFSIZE-strlen(link)-1); - - if (permalink_url) - process_timestamp(output, (char*)permalink_url, permalink_macro, - date); - else if (samedir_permalink && !u8_strcmp(samedir_permalink, (uint8_t*)"1")) - { - get_realpath(&real_link, input_dirname, link); - process_timestamp(output, real_link, permalink_macro, date); - } - else - process_timestamp(output, link, permalink_macro, date); - - free(real_link); - free(link); - } + begin_article(output, + var_add_article_header && *var_add_article_header == '1', + author, title, header_text, (char*)title_heading_level, date, + ext_in_permalink && *ext_in_permalink != '0', + (char*)permalink_url); RESET_TOKEN(token, ptoken, token_size)