чување 0042610d51310db5bf564330efc26e89c33fc10a
родитељ 4bd161a8e84d6fbfa9b56218e5b87eade6e4def6
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Wed, 19 Jul 2023 19:10:38 +0200
Add feed-type; slweb.c(get_value): Introduce cursor parameter, allowing to
search further
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | slweb.1.in | | | 8 | ++++---- |
| M | slweb.c | | | 126 | +++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------- |
измењених датотека: 2, додавања: 85(+), брисања: 49(-)
diff --git a/slweb.1.in b/slweb.1.in
@@ -907,10 +907,10 @@ will be used as a favicon
instead of the default, \fC/favicon.ico\fR.
.
.IP \[bu]
-.BR feed ", " feed-desc .
-If both are present, contents of those variables will be added as \fIhref\fR and
-\fItitle\fR attributes (respectively) to the \fC<link rel="alternate"
-type="application/rss+xml">\fR tag in the page's \fC<head>\fR.
+.BR feed ", " feed-type ", " feed-desc .
+If all are present, contents of those variables will be added as \fIhref\fR,
+\fItype\fR and \fItitle\fR attributes (respectively) to the \fC<link
+rel="alternate">\fR tag in the page's \fC<head>\fR.
.
.IP \[bu]
.BR header-text .
diff --git a/slweb.c b/slweb.c
@@ -226,7 +226,8 @@ all_numeric(const u8* start, const u8* end)
}
u8*
-get_value(KeyValue* list, const size_t list_count, const u8* key)
+get_value(KeyValue* list, const size_t list_count, const u8* key,
+ KeyValue** cursor)
{
if (!list)
return NULL;
@@ -234,9 +235,20 @@ get_value(KeyValue* list, const size_t list_count, const u8* key)
while (plist < list + list_count)
{
if (!strcmp((char*)plist->key, (char*)key))
+ {
+ if (cursor)
+ {
+ if (plist < list + list_count-1)
+ *cursor = plist+1;
+ else
+ *cursor = NULL;
+ }
return plist->value;
+ }
plist++;
}
+ if (cursor)
+ *cursor = NULL;
return NULL;
}
@@ -319,7 +331,7 @@ print_output(FILE* output, const char* fmt, ...)
va_start(args, fmt);
var_incdir_only_summary
- = get_value(vars, vars_count, (u8*)"incdir-only-summary");
+ = get_value(vars, vars_count, (u8*)"incdir-only-summary", NULL);
incdir_only_summary
= var_incdir_only_summary && *var_incdir_only_summary == '1';
@@ -520,7 +532,7 @@ print_meta_var(FILE* output, u8** tsv_header, u8** tsv_register)
u8* var_name = NULL;
var_name = (u8*)strdup((char*)pvalue + 1);
*(var_name + value_len - 2) = 0;
- u8* value = get_value(vars, vars_count, var_name);
+ u8* value = get_value(vars, vars_count, var_name, NULL);
if (value)
print_output(output,
@@ -1138,7 +1150,8 @@ read_csv(FILE* output, const char* filename, csv_callback_t callback)
UBYTE current_header = 0;
u8* csv_register[MAX_CSV_REGISTERS];
UBYTE current_register = 0;
- u8* csv_delimiter = get_value(vars, vars_count, (u8*)"csv-delimiter");
+ u8* csv_delimiter
+ = get_value(vars, vars_count, (u8*)"csv-delimiter", NULL);
if (!(csv = fopen(filename, "rt")))
exit(error(ENOENT, (u8*)"csv: No such file: %s", filename));
@@ -1672,8 +1685,8 @@ process_incdir_subdir(FILE* output, const char* subdirname,
goto incdir_subdir_child_cleanup;
}
- title = get_value(vars, vars_count, (u8*)"title");
- date = get_value(vars, vars_count, (u8*)"date");
+ title = get_value(vars, vars_count, (u8*)"title", NULL);
+ date = get_value(vars, vars_count, (u8*)"date", NULL);
formatted_date
= format_date(date, list_timestamp_format);
if (!formatted_date)
@@ -1682,7 +1695,7 @@ process_incdir_subdir(FILE* output, const char* subdirname,
/* Have to temporarily reset this because of potential
* interaction with print_output */
var_incdir_only_summary = get_value(vars, vars_count,
- (u8*)"incdir-only-summary");
+ (u8*)"incdir-only-summary", NULL);
incdir_only_summary = var_incdir_only_summary
&& *var_incdir_only_summary == '1';
if (list_only && var_incdir_only_summary)
@@ -1826,7 +1839,7 @@ incdir_next_arg:
parg = arg;
if (*parg == '=')
- macro_body = get_value(macros, macros_count, arg + 1);
+ macro_body = get_value(macros, macros_count, arg + 1, NULL);
else if (!strcmp((const char*)arg, "listonly"))
list_only = 1;
else
@@ -2016,7 +2029,7 @@ process_macro(FILE* output, const u8* token, const int end_tag)
u8* eol;
size_t macro_body_len;
- macro_body = get_value(macros, macros_count, token + 1);
+ macro_body = get_value(macros, macros_count, token + 1, NULL);
if (!macro_body)
exit(error(1, (u8*)"Macro '%s' undefined", token + 1));
@@ -2273,7 +2286,7 @@ int
process_link(FILE* output, const u8* link_text, const u8* link_prefix,
const u8* link_macro_body, const u8* link_id)
{
- u8* url = get_value(links, links_count, link_id);
+ u8* url = get_value(links, links_count, link_id, NULL);
return process_inline_link(output, link_text, link_prefix,
link_macro_body, url);
}
@@ -2363,7 +2376,7 @@ process_image(FILE* output, const u8* image_text, const u8* image_file_prefix,
const u8* link_prefix, const u8* image_id, const int add_link,
const int add_figcaption)
{
- u8* url = get_value(links, links_count, image_id);
+ u8* url = get_value(links, links_count, image_id, NULL);
return process_inline_image(output, image_text, image_file_prefix,
link_prefix, url, add_link, add_figcaption);
}
@@ -2580,14 +2593,18 @@ process_formula(FILE* output, const u8* token, const int display_formula)
int
begin_html_and_head(FILE* output)
{
- u8* lang = get_value(vars, vars_count, (u8*)"lang");
- u8* site_name = get_value(vars, vars_count, (u8*)"site-name");
- u8* site_desc = get_value(vars, vars_count, (u8*)"site-desc");
- u8* canonical = get_value(vars, vars_count, (u8*)"canonical");
- u8* favicon_url = get_value(vars, vars_count, (u8*)"favicon-url");
- u8* meta = get_value(vars, vars_count, (u8*)"meta");
- u8* feed = get_value(vars, vars_count, (u8*)"feed");
- u8* feed_desc = get_value(vars, vars_count, (u8*)"feed-desc");
+ u8* lang = get_value(vars, vars_count, (u8*)"lang", NULL);
+ u8* site_name = get_value(vars, vars_count, (u8*)"site-name", NULL);
+ u8* site_desc = get_value(vars, vars_count, (u8*)"site-desc", NULL);
+ u8* canonical = get_value(vars, vars_count, (u8*)"canonical", NULL);
+ u8* favicon_url = get_value(vars, vars_count, (u8*)"favicon-url", NULL);
+ u8* meta = get_value(vars, vars_count, (u8*)"meta", NULL);
+ u8* feed = NULL;
+ u8* feed_type = NULL;
+ u8* feed_desc = NULL;
+ KeyValue* cursor = NULL;
+ KeyValue* cursor_type = NULL;
+ KeyValue* cursor_desc = NULL;
print_output(output,
"<!DOCTYPE html>\n"
@@ -2620,12 +2637,29 @@ begin_html_and_head(FILE* output)
print_output(output, "<link rel=\"canonical\" href=\"%s\">\n",
(char*)canonical);
- if (feed && *feed && feed_desc && *feed_desc)
- print_output(output,
- "<link rel=\"alternate\""
- " type=\"application/rss+xml\" href=\"%s\" "
- "title=\"%s\">\n",
- (char*)feed, (char*)feed_desc);
+ cursor = vars;
+ cursor_type = vars;
+ cursor_desc = vars;
+ do
+ {
+ feed = get_value(cursor, vars_count - (cursor - vars),
+ (u8*)"feed", &cursor);
+ feed_type = get_value(cursor_type,
+ vars_count - (cursor_type - vars), (u8*)"feed-type",
+ &cursor_type);
+ feed_desc = get_value(cursor_desc,
+ vars_count - (cursor_desc - vars), (u8*)"feed-desc",
+ &cursor_desc);
+
+ if (feed && *feed && feed_type && *feed_type && feed_desc
+ && *feed_desc)
+ print_output(output,
+ "<link rel=\"alternate\""
+ " type=\"%s\" href=\"%s\" "
+ "title=\"%s\">\n",
+ (char*)feed_type, (char*)feed,
+ (char*)feed_desc);
+ } while (feed && feed_type && feed_desc);
if (site_desc && *site_desc)
print_output(output,
@@ -2693,9 +2727,9 @@ begin_article(FILE* output, const char* source_filename, const u8* link_prefix,
if (date && source_filename)
{
- char* link = strip_ext((const char*)source_filename);
- u8* permalink_macro
- = get_value(macros, macros_count, (u8*)"permalink");
+ char* link = strip_ext((const char*)source_filename);
+ u8* permalink_macro = get_value(macros, macros_count,
+ (u8*)"permalink", NULL);
if (ext_in_permalink)
strcat(link, timestamp_output_ext);
@@ -2912,31 +2946,33 @@ slweb_parse(FILE* output, const char* source_filename, const u8* buffer,
if (!buffer)
exit(error(1, (u8*)"Empty buffer"));
- title = get_value(vars, vars_count, (u8*)"title");
+ title = get_value(vars, vars_count, (u8*)"title", NULL);
title_heading_level
- = get_value(vars, vars_count, (u8*)"title-heading-level");
- header_text = get_value(vars, vars_count, (u8*)"header-text");
- author = get_value(vars, vars_count, (u8*)"author");
- date = get_value(vars, vars_count, (u8*)"date");
- permalink_url = get_value(vars, vars_count, (u8*)"permalink-url");
+ = get_value(vars, vars_count, (u8*)"title-heading-level", NULL);
+ header_text = get_value(vars, vars_count, (u8*)"header-text", NULL);
+ author = get_value(vars, vars_count, (u8*)"author", NULL);
+ date = get_value(vars, vars_count, (u8*)"date", NULL);
+ permalink_url = get_value(vars, vars_count, (u8*)"permalink-url", NULL);
image_file_prefix
- = get_value(vars, vars_count, (u8*)"image-file-prefix");
- ext_in_permalink = get_value(vars, vars_count, (u8*)"ext-in-permalink");
+ = get_value(vars, vars_count, (u8*)"image-file-prefix", NULL);
+ ext_in_permalink
+ = get_value(vars, vars_count, (u8*)"ext-in-permalink", NULL);
var_add_article_header
- = get_value(vars, vars_count, (u8*)"add-article-header");
+ = get_value(vars, vars_count, (u8*)"add-article-header", NULL);
var_add_image_links
- = get_value(vars, vars_count, (u8*)"add-image-links");
+ = get_value(vars, vars_count, (u8*)"add-image-links", NULL);
add_image_links = !(var_add_image_links && *var_add_image_links == '0');
- var_add_figcaption = get_value(vars, vars_count, (u8*)"add-figcaption");
+ var_add_figcaption
+ = get_value(vars, vars_count, (u8*)"add-figcaption", NULL);
add_figcaption = !(var_add_figcaption && *var_add_figcaption == '0');
var_add_footnote_div
- = get_value(vars, vars_count, (u8*)"add-footnote-div");
+ = get_value(vars, vars_count, (u8*)"add-footnote-div", NULL);
add_footnote_div = var_add_footnote_div && *var_add_footnote_div == '1';
- link_prefix = get_value(vars, vars_count, (u8*)"link-prefix");
+ link_prefix = get_value(vars, vars_count, (u8*)"link-prefix", NULL);
footer_permalink_text = get_value(vars, vars_count,
- (u8*)"incdir-footer-permalink-text");
+ (u8*)"incdir-footer-permalink-text", NULL);
var_incdir_only_summary
- = get_value(vars, vars_count, (u8*)"incdir-only-summary");
+ = get_value(vars, vars_count, (u8*)"incdir-only-summary", NULL);
incdir_only_summary
= var_incdir_only_summary && *var_incdir_only_summary == '1';
@@ -4442,7 +4478,7 @@ do_line:
process_inline_link(output, link_text,
link_prefix,
get_value(macros, macros_count,
- link_macro),
+ link_macro, NULL),
token);
else
{
@@ -4528,7 +4564,7 @@ do_line:
if (!read_yaml_macros_and_links)
process_link(output, link_text, link_prefix,
get_value(macros, macros_count,
- link_macro),
+ link_macro, NULL),
token);
RESET_TOKEN(token, ptoken, token_size);
state &= ~(ST_LINK | ST_LINK_SECOND_ARG);