fdoc

subroutinenames_pageprivate

subroutine names_page(site, html)

Render the index of all names: everything in the lists, from A to Z, with what each is and where.

Arguments

NameTypeIntentAttributesDescription
sitetype(site_t)in

the site

htmlcharacter(len=:)outallocatable

the page

Calls

Called by

Source

Show the code
subroutine names_page(site, html)
    type(site_t), intent(in) :: site                    !! the site
    character(len=:), allocatable, intent(out) :: html  !! the page
    type(buffer_t) :: b
    type(string_t), allocatable :: keys(:)
    integer, allocatable :: ids(:), order(:)
    character(len=:), allocatable :: url, letter, word
    character :: initial, previous
    integer :: k, which, n

    n = sum([(size(site%members(which)%ids), which=1, NUM_LISTS)])
    allocate (ids(n), keys(n))
    n = 0
    do which = 1, NUM_LISTS
        do k = 1, size(site%members(which)%ids)
            n = n + 1
            ids(n) = site%members(which)%ids(k)
            keys(n)%s = lowercase(display_name(site%p%list%box(ids(n))%e))
        end do
    end do
    call sorted_order(keys, order)

    call page_head(site, 'Index', HERE_INDEX, '../', .false., b)
    call add(b, '<aside class="side">'//achar(10))
    call site_side(site, 0, '../', b)
    call add(b, '</aside>'//achar(10)//'<main><div class="inner">'//achar(10)//'<h1>Index</h1>'//achar(10))
    call add(b, '<nav class="letters">')
    previous = ' '
    do k = 1, n
        initial = index_letter(keys(order(k))%s)
        if (initial == previous) cycle
        call add(b, '<a href="#letter-'//initial//'">'//upper_letter(initial)//'</a>')
        previous = initial
    end do
    call add(b, '</nav>'//achar(10))
    previous = ' '
    do k = 1, n
        initial = index_letter(keys(order(k))%s)
        if (initial /= previous) then
            if (previous /= ' ') call add(b, '</ul>'//achar(10))
            call add(b, '<h2 id="letter-'//initial//'">'//upper_letter(initial)//'</h2>'//achar(10)//'<ul class="names">')
            previous = initial
        end if
        associate (id => ids(order(k)), e => site%p%list%box(ids(order(k)))%e)
            call entity_url(site%p%list, id, url)
            call add(b, '<li><a href="../')
            call html_escape(url, b, .true.)
            call add(b, '">')
            call side_icon(e, b)
            call html_escape(display_name(e), b, .false.)
            call add(b, '</a>')
            call icon_of(e, letter, word)
            call add(b, ' <span class="where">'//word)
            if (e%parent > 0) then
                if (site%p%list%box(e%parent)%e%kind /= E_NONE) then
                    call add(b, ' in ')
                    call link_to(site, e%parent, display_name(site%p%list%box(e%parent)%e), b)
                end if
            end if
            call add(b, '</span></li>')
        end associate
    end do
    if (n > 0) call add(b, '</ul>'//achar(10))
    call page_foot(site, b)
    call take(b, html)

contains

    !> The group of a name in the index: its first letter, or `_` for anything else.
    pure character function index_letter(key)
        character(len=*), intent(in) :: key     !! the name, in lowercase

        index_letter = '_'
        if (len(key) == 0) return
        if (key(1:1) >= 'a' .and. key(1:1) <= 'z') index_letter = key(1:1)
    end function index_letter

    !> The heading of a group: its letter in capitals, or `#`.
    pure character function upper_letter(initial)
        character, intent(in) :: initial    !! the group

        upper_letter = '#'
        if (initial /= '_') upper_letter = achar(iachar(initial) - 32)
    end function upper_letter

end subroutine names_page