Here's a way I did it. Probably there is a better way.

*Add a page to each directory (I used the file name "list_title.md") with 
the metadata:*
list_title = "Heading for the navigation links for this directory"
do_not_list = "True"

*In conf.py, define a context variable with the name that was used for the 
page file with the metadata:*
GLOBAL_CONTEXT = {
    ...
    'LIST_TITLE_FILENAME': 'list_title.md',
}

*In base_header.tmpl, add the macros:*
{# Return the title to use for the navigation links for the directory in 
which #}
{# link is found by looking for the metadata "list_title" in 
LIST_TITLE_FILENAME file #}
{% macro html_navigation_links_title(link) %}
    {% set filename = link.split('/')[-2] + ".md" %}
    {% set file_path = link[:-1] + ".md"%}
    {% if filename == LIST_TITLE_FILENAME %}
        {% set full_file_path = os.path.realpath("pages/" + file_path) %}
        {% set f = open(full_file_path, 'r') %}
        {% set file_contents = f.read() %}
        {% set metadata = toml.loads(file_contents.split('+++')[1]) %}
        <h1>{{ metadata['list_title'] }}</h1>
    {% endif %}
{% endmacro %}

{# Return listing for the link if the value of link's do_not_list metadata 
field is not True #}
{% macro list_link(link, text) %}
    {% set filename = link.split('/')[-2] + ".md" %}
    {% set file_path = link[:-1] + ".md"%}
    {% set full_file_path = os.path.realpath("pages/" + file_path) %}
    {% set f = open(full_file_path, 'r') %}
    {% set file_contents = f.read() %}
    {% set metadata = toml.loads(file_contents.split('+++')[1]) %}
    {% if metadata['do_not_list'] != "True" %}
        <li><a href="{{ link }}">{{ text|e }}</a></li>
    {% endif %}
{% endmacro %}

*In list.tmpl, modify the for loop to use the macros:*
        <ul class="postlist">
        {% for text, link, count in items %}
            {{ header.html_navigation_links_title(link) }}
            {{ header.list_link(link, text) }}
            {% if count %}
                ({{ count }})
            {% endif %}
        {% endfor %}
        </ul>

On Saturday, April 29, 2023 at 6:44:30 PM UTC-4 [email protected] wrote:

> I don't think it's implemented but sounds like a nice feature to have.
>
> On Sat, Apr 29, 2023 at 7:40 PM Mitch Berkson <[email protected]> wrote:
>
>> I am using PAGE_INDEX and it creates a nice list with URLs of the pages 
>> in each directory. I would like to specify the title of the list instead of 
>> having it be the title of the site which is what is used in list.tmpl. 
>>
>> It seems like this should be doable in metadata in a .md file in each 
>> directory. Is there a way to do this?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "nikola-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/nikola-discuss/9a8ade93-17a2-4348-8203-2073d8f3e4e9n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/nikola-discuss/9a8ade93-17a2-4348-8203-2073d8f3e4e9n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nikola-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nikola-discuss/af1d1b24-c790-4455-84de-456ca50eadefn%40googlegroups.com.

Reply via email to