On Wed, Jul 17, 2024 at 10:03:36AM +0100, Frederico Muñoz wrote:
> 
> Hi,
> 
> I'm using Texinfo for my personal blog, using texi2any to do the heavy
> lifting (check https://interlaye.red/Texiblog.html for the idea behind
> it and a link to the repository).

Interesting!

> ** Automatic creation of "extended" menus.
> 
> I am not using `FORMAT_MENU="sectiontoc"` because it doesn't allow me to
> add a descriptive sentence at the end. I use this in several places:
> 
> 1. The main page has a menu under "Home" in which each section gets a
> small description. I maintain this manually, pointing to files.
> 
> 2. The "Posts" page is an automatically created posts.texi file (using
> M4) that includes  something like:
> 
> ```
> @menu
> *  My latest article.              2024-02-24
> *  Another one about this.         2024-02-10
> @end menu
> 
> @include posts/latest.texi
> @include posts/another.texi
> 
> ```
> 
> ... which adds the date after the title (fundamental for my purpose). I
> get the date from the @date field (a macro) in my individual posts.
> 
> This works, but perhaps it would be possible to combine the automatic
> menu generation (from FORMAT_MENU="sectiontoc") with the "extended"
> format, thus eliminating this step?

The idea of the sectiontoc is to output sectioning commands, like a
localized table of contents, therefore it seems to me that a description
is not much in line with the sectiontoc.  In addition, it seems to me
that a @menu fulfills well your purposse, since it shows a link and a
description.  I do not really understand what you are missing from the
sectiontoc that is not already in the @menu formatting?

> Perhaps by adding an additional
> option with what should be the content of the description field?

We have added a new command @nodedescription in the upcoming release
that contains the description that appears in @menus allowing to have an
automatic generation of menus with descriptions.  For example:

@node Copying Conditions
@nodedescription Your rights.
@unnumbered Texinfo Copying Conditions

Maybe this is what you are looking for?

As a side note, if some nodes appear in multiple menu, the @nodedescription
would not be as flexible as writing menus, as the generated descriptions
would not be different by @menu.

Another possibility would be to replace the default formatting for
sectioning commands and nodes by a different formatting function (in
Perl) that formats this part differently.  There is actually an example
in Texinfo, see tp/init/book.pm, the book_convert_heading_command
function and the called to texinfo_register_command_formatting right
after.

I do not think that it is such a good idea, however, as it requires good
knowledge of Perl and texi2any customization API, and to sync with the
corresponding default formatting function from time to time, which is a
pain.


> == Adding a "Top" navigation entry
> 
> For a web page I find it useful to be able to easily go to the
> homepage. I'm manually changing the HTML to add a "Top" navigation entry
> that points to the index page. I experimented with several options but
> didn't get this effect. Is something like this possible, and if not,
> would it be a useful addition?

It is possible to modify the navigation header with Perl code using the
texi2any customization API.  There are some explanations here:
https://www.gnu.org/software/texinfo/manual/texi2any_api/html_node/Simple-headers-customizations.html
and
https://www.gnu.org/software/texinfo/manual/texi2any_api/html_node/Customizing-HTML-Footers_002c-Headers-and-Navigation-Panels.html

However, to modify existing buttons, another approach seems to be better
to me, call a user-defined function to modify the customization
variables of the converter:
https://www.gnu.org/software/texinfo/manual/texi2any_api/html_node/Init-File-Calling-at-Different-Stages.html
and
https://www.gnu.org/software/texinfo/manual/texi2any_api/html_node/Conversion-Customization-Variables.html

In the attached initialization file, the add_top_button_setup function
does that.  You can load it by adding --init-file=init_file.pm.

I did a patch against your repository to show how it could be used too.

> == Support for image URLs
> 
> I use @image for the images, and this requires a local file. I can work
> around this either by having the file, or doing some pre-processing, but
> it would be easier to support image URLs. I understand that this is
> something that is not simple since it wouldn't work in non HTML modes,
> so I get why it is like it is.

One possibility is to use IMAGE_LINK_PREFIX, like
 -c IMAGE_LINK_PREFIX='https://interlaye.red/texiblog_images/'
But this adds the same prefix to all the images.  I also added that to
the customization file I attach.

To add different prefixes for different images, the best would probably
be to redefine the function formatting images, which is relatively
simple, starting from the default one: tp/Texinfo/Convert/HTML.pm
_convert_image_command.  This is somewhat described here:
https://www.gnu.org/software/texinfo/manual/texi2any_api/html_node/Command-Tree-Element-Conversion-Functions.html

> Neither of these are really needed, and I can keep doing my own changes
> around it, but perhaps one of them is useful for someone else. I also
> completely recognise that using Texinfo for a personal blog is not the
> main use-case of it and as such these enhancements are a bit fringe.

I can't see why it would be such as special use-case, looks good to me.

-- 
Pat
use strict;

texinfo_set_from_init_file('IMAGE_LINK_PREFIX',
                           'https://interlaye.red/texiblog_images/');

# avoid doing twice if there are more than one manual processed
my $button_added;
sub add_top_button_setup {
  my $converter = shift;

  if (!$button_added) {
    foreach my $buttons_spec ('SECTION_BUTTONS', 'CHAPTER_BUTTONS',
                         'TOP_BUTTONS',
                         'CHAPTER_FOOTER_BUTTONS', 'SECTION_FOOTER_BUTTONS',
                         'NODE_FOOTER_BUTTONS') {
      my $buttons_list = $converter->get_conf($buttons_spec);
      push @$buttons_list, ('Top');
      $converter->set_conf($buttons_spec, $buttons_list);
    }
    $button_added = 1;
  }
}

texinfo_register_handler('setup', \&add_top_button_setup);

diff --git a/Makefile b/Makefile
index 29d84a2..7ed0a36 100644
--- a/Makefile
+++ b/Makefile
@@ -42,7 +42,7 @@ src/index.html: src/posts.texi src/config.texi
 	-c MENU_ENTRY_COLON=" " -c CHECK_NORMAL_MENU_STRUCTURE=1 -c PROGRAM_NAME_IN_FOOTER=1 -c SHOW_TITLE=1 -c DATE_IN_HEADER=1 \
         -c NO_CUSTOM_HTML_ATTRIBUTE=1 -c EXTRA_HEAD=$(extra_headers) --html --css-ref=styles/brutex.css \
         -c HIGHLIGHT_SYNTAX="pygments"  -c CONTENTS_OUTPUT_LOCATION="separate_element" \
-	--no-number-sections -o $(outdir) -I static/ --internal-links=out/int-links.txt src/index.texi
+	--no-number-sections --init-file=texiblog.pm -o $(outdir) -I static/ --internal-links=out/int-links.txt src/index.texi
 
 out/%: static/%
 	@mkdir -p $(@D)
@@ -82,5 +82,5 @@ src/posts.texi: src/posts.m4
 
 ## Add a "Top" navigation button. This should be doable using texi2any
 ## (which would be better)
-nav:	src/index.html
-	@awk  -i inplace '{ if (match($$ 0,/\[.*Contents.*\]\[.*Index.*\]/,a)) { gsub(/<\/p>/,"[<a href=\"index.html\">Top</a>] </p>"); print } else { print }}' $(outdir)/*html
+#nav:	src/index.html
+#	@awk  -i inplace '{ if (match($$ 0,/\[.*Contents.*\]\[.*Index.*\]/,a)) { gsub(/<\/p>/,"[<a href=\"index.html\">Top</a>] </p>"); print } else { print }}' $(outdir)/*html
diff --git a/texiblog.pm b/texiblog.pm
new file mode 100644
index 0000000..81e9c15
--- /dev/null
+++ b/texiblog.pm
@@ -0,0 +1,25 @@
+use strict;
+
+texinfo_set_from_init_file('IMAGE_LINK_PREFIX',
+                           'https://interlaye.red/texiblog_images/');
+
+# avoid doing twice if there are more than one manual processed
+my $button_added;
+sub add_top_button_setup {
+  my $converter = shift;
+
+  if (!$button_added) {
+    foreach my $buttons_spec ('SECTION_BUTTONS', 'CHAPTER_BUTTONS',
+                         'TOP_BUTTONS',
+                         'CHAPTER_FOOTER_BUTTONS', 'SECTION_FOOTER_BUTTONS',
+                         'NODE_FOOTER_BUTTONS') {
+      my $buttons_list = $converter->get_conf($buttons_spec);
+      push @$buttons_list, ('Top');
+      $converter->set_conf($buttons_spec, $buttons_list);
+    }
+    $button_added = 1;
+  }
+}
+
+texinfo_register_handler('setup', \&add_top_button_setup);
+

Reply via email to