чување 9f0807ac8319c5ca8969b6cd1f938b760a265eb2
родитељ a9b14cf0a414305aabf581db24929acf5c3d6aa4
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Mon, 4 Jan 2021 12:58:05 +0100
Added permalink macro, permalink-url, ext-in-permalink; removed realpath processing from link and image url processing; updated manpage
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | index.html | | | 2 | +- |
| M | slweb.1.in | | | 69 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- |
| M | slweb.c | | | 100 | ++++++++++++++++++++++++++++--------------------------------------------------- |
измењених датотека: 3, додавања: 97(+), брисања: 74(-)
diff --git a/index.html b/index.html
@@ -127,7 +127,7 @@ this program. If not, see <<a href="https://www.gnu.org/licenses">https://www
<div id="git-log">
Previous commit:
-index.slw 5365c0c 2020-12-30 19:59:46 +0100 (Страхиња Радић) (HEAD -> master, origin/master, origin/HEAD)
+index.slw 37b6ecb 2021-01-04 13:37:53 +0100 (Страхиња Радић) (HEAD -> master, tag: v0.3.3-beta, origin/master, origin/HEAD)
</div><!--git-log-->
diff --git a/slweb.1.in b/slweb.1.in
@@ -37,12 +37,13 @@ Only add the contents of the \fC<body>\fR tag, skipping \fC<html>\fR and
.TQ
.B \-\-basedir <\fIdirectory\fR>
.br
-Set the base directory as a reference point to normalize paths in local links
-(the argument to
+Set the base directory as a reference point to normalize paths in includes and
+.I incdir
+directive (the argument to
.B --relative-to
option for the
.BR realpath (1)
-command).
+command). Defaults to the current directory.
.
.TP
.B \-h
@@ -180,8 +181,9 @@ be transformed into \fC<div id="myid"></div>\fR.
.BR Includes .
Directive \fC{include "somefile"}\fR will fork, parse
.I somefile.slw
-(related to the directory containing the file containing the directive) and
-output the resulting
+(related to
+.IR basedir )
+and output the resulting
.SM HTML
as if the option \fC--body-only\fR was specified. All macros and
.SM YAML
@@ -210,7 +212,9 @@ A \fC<ul class="incdir">\fR tag will be inserted into the document instead of
the directive.
.
.IP 2. 4
-For every subdirectory of the directory containing the input file, up to
+For every subdirectory of
+.IR basedir ,
+up to
.I num
(if present) or 5 (if omitted) total subdirectories, a \fC<li>\fR
tag will be inserted into the \fCul\fR tag.
@@ -257,11 +261,47 @@ home page.
.B Special
.SM \fBYAML
.B variables
-recognized by slweb are:
+recognized by
+.B slweb
+are:
.
.IP \[bu] 4
.BR date .
-If present,
+If present, this variable, assumed to be in
+.SM ISO
+8601
+.SM UTC
+datetime format, will be parsed to determine the timestamp in permalinks
+generated by the
+.I incdir
+directive. The actual values used depend on the source-level constant
+.IR timestamp_format .
+.
+.IP \[bu] 4
+.BR ext-in-permalink .
+If set to \[lq]0\[rq], permalinks generated by the
+.I incdir
+directive will not have the extension included in the
+.I href
+attribute. For example, instead of \fCblog/2020/august.html\fR, the resulting
+permalink will have \fCblog/2020/august\fR.
+.
+.IP \[bu] 4
+.BR permalink-url .
+If present, this
+.SM URL
+will completely replace the link used in the
+.I href
+attribute of permalinks generated by the
+.I incdir
+directive. This variable is more useful in individual
+.I .slw
+files inside the subdirectories of the
+.I basedir
+provided to the
+.I incdir
+directive.
+.
.IP \[bu] 4
.BR samedir-permalink .
If set to \[lq]1\[rq], path in the permalink generated by the presence of
@@ -306,6 +346,19 @@ to 2. (\fCtitle: Some title\fR becomes \fC<h2>Some title</h2>\fR).
See
.BR title .
.
+.PP
+.B Special macros
+recognized by
+.B slweb
+are:
+.
+.IP \[bu] 4
+.BR permalink .
+If present, the body of this macro will be inserted into permalinks generated by
+the
+.I incdir
+directive, similar to the macro-form of links.
+.
.SH "SEE ALSO"
.BR sed (1)
.
diff --git a/slweb.c b/slweb.c
@@ -322,7 +322,7 @@ process_include(uint8_t* token, FILE* output, ULONG* state,
strncpy(basedir, input_dirname, strlen(input_dirname));
sprintf(input_filename, "%s/%s.slw",
- input_dirname,
+ basedir,
include_filename);
FILE* input = NULL;
@@ -551,7 +551,8 @@ process_incdir(uint8_t* token, FILE* output, KeyValue** vars,
}
int
-process_timestamp(FILE* output, const char* link, uint8_t* date)
+process_timestamp(FILE* output, const char* link, uint8_t* permalink_macro,
+ uint8_t* date)
{
uint8_t* day = NULL;
uint8_t* month = NULL;
@@ -591,8 +592,9 @@ process_timestamp(FILE* output, const char* link, uint8_t* date)
ptimestamp_format++;
}
- fprintf(output, "<a href=\"%s\" class=\"timestamp\">%s</a>\n",
+ fprintf(output, "<a href=\"%s\" class=\"timestamp\">%s%s</a>\n",
link,
+ permalink_macro ? (char*)permalink_macro : "",
formatted_date);
}
}
@@ -829,64 +831,32 @@ get_realpath(char** realpath, char* relativeto, char* path)
}
int
-process_link(uint8_t* link_text, uint8_t* link_macro_body, uint8_t* link_id,
- KeyValue* links, size_t links_count, FILE* output)
+process_inline_link(uint8_t* link_text, uint8_t* link_macro_body,
+ uint8_t* link_url, FILE* output)
{
- char* url = (char*)get_value(links, links_count, link_id, NULL);
- char* link_dir = NULL;
- BOOL local = FALSE;
- BOOL dir_is_dot = FALSE;
-
- if (url)
- local = url_is_local(url);
-
- if (local)
- {
- CALLOC(link_dir, char, BUFSIZE)
- get_realpath(&link_dir, basedir, input_dirname ? input_dirname : ".");
- dir_is_dot = !strcmp(link_dir, ".");
- }
-
- fprintf(output, "<a href=\"%s%s%s\">%s%s</a>",
- url && local && !dir_is_dot ? link_dir : "",
- url && local && !dir_is_dot && url ? "/" : "",
- url ? (char*)url : "",
+ fprintf(output, "<a href=\"%s\">%s%s</a>",
+ link_url ? (char*)link_url : "",
link_macro_body ? (char*)link_macro_body : "",
link_text);
- if (local)
- free(link_dir);
-
return 0;
}
int
-process_inline_link(uint8_t* link_text, uint8_t* link_macro_body,
- uint8_t* link_url, FILE* output)
+process_link(uint8_t* link_text, uint8_t* link_macro_body, uint8_t* link_id,
+ KeyValue* links, size_t links_count, FILE* output)
{
- char* link_dir = NULL;
- BOOL local = FALSE;
- BOOL dir_is_dot = FALSE;
-
- if (link_url)
- local = url_is_local((char*)link_url);
-
- if (local)
- {
- CALLOC(link_dir, char, BUFSIZE)
- get_realpath(&link_dir, basedir, input_dirname ? input_dirname : ".");
- dir_is_dot = !strcmp(link_dir, ".");
- }
-
- fprintf(output, "<a href=\"%s%s%s\">%s%s</a>",
- link_url && local && !dir_is_dot ? link_dir : "",
- link_url && local && !dir_is_dot && link_url ? "/" : "",
- link_url ? (char*)link_url : "",
- link_macro_body ? (char*)link_macro_body : "",
- link_text);
+ uint8_t* url = get_value(links, links_count, link_id, NULL);
+ return process_inline_link(link_text, link_macro_body,
+ url, output);
+}
- if (local)
- free(link_dir);
+int
+process_inline_image(uint8_t* image_text, uint8_t* image_url, FILE* output)
+{
+ fprintf(output, "<img src=\"%s\" alt=\"%s\" />",
+ image_url ? (char*)image_url : "",
+ image_text);
return 0;
}
@@ -896,16 +866,7 @@ process_image(uint8_t* image_text, uint8_t* image_id, KeyValue* links,
size_t links_count, FILE* output)
{
uint8_t* url = get_value(links, links_count, image_id, NULL);
- fprintf(output, "<img src=\"%s\" alt=\"%s\" />",
- url ? (char*)url : "", image_text);
- return 0;
-}
-
-int
-process_inline_image(uint8_t* image_text, uint8_t* image_url, FILE* output)
-{
- fprintf(output, "<img src=\"%s\" alt=\"%s\" />", image_url, image_text);
- return 0;
+ return process_inline_image(image_text, url, output);
}
int
@@ -1013,6 +974,8 @@ slweb_parse(uint8_t* buffer, FILE* output,
uint8_t* title = NULL;
uint8_t* title_heading_level = NULL;
uint8_t* date = NULL;
+ uint8_t* permalink_url = NULL;
+ uint8_t* ext_in_permalink = NULL;
uint8_t* pbuffer = NULL;
uint8_t* line = NULL;
uint8_t* pline = NULL;
@@ -1049,6 +1012,8 @@ slweb_parse(uint8_t* buffer, FILE* output,
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);
CALLOC(line, uint8_t, BUFSIZE)
CALLOC(token, uint8_t, BUFSIZE)
@@ -1079,17 +1044,22 @@ slweb_parse(uint8_t* buffer, FILE* output,
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)
- strncat(link, timestamp_output_ext, strlen(timestamp_output_ext));
+ if (ext_in_permalink && *ext_in_permalink != (ucs4_t)'0')
+ strncat(link, timestamp_output_ext, strlen(timestamp_output_ext));
- if (samedir_permalink && !u8_strcmp(samedir_permalink, (uint8_t*)"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, date);
+ process_timestamp(output, real_link, permalink_macro, date);
}
else
- process_timestamp(output, link, date);
+ process_timestamp(output, link, permalink_macro, date);
free(real_link);
free(link);