fdoc

subroutineread_pageprivate

subroutine read_page(p, s, base, path, target, parent, depth, pages, ordered, skip)

Read and render one page, adding it to pages.

Arguments

NameTypeIntentAttributesDescription
ptype(project_t)inouttarget

the project

stype(settings_t)in

the settings

basetype(markdown_options_t)in

has the abbreviations of the project

pathcharacter(len=*)in

the Markdown file

targetcharacter(len=*)in

the HTML file, relative to page/

parentintegerin

the page above, or 0

depthintegerin

how deep it is

pagestype(page_t)inoutallocatabledimension(:)

the pages

orderedtype(string_t)outallocatabledimension(:)

its ordered_subpage

skiptype(string_t)outallocatabledimension(:)

its copy_subdir

Calls

Source

Show the code
subroutine read_page(p, s, base, path, target, parent, depth, pages, ordered, skip)
    type(project_t), intent(inout), target :: p         !! the project
    type(settings_t), intent(in) :: s                   !! the settings
    type(markdown_options_t), intent(in) :: base        !! has the abbreviations of the project
    character(len=*), intent(in) :: path                !! the Markdown file
    character(len=*), intent(in) :: target              !! the HTML file, relative to `page/`
    integer, intent(in) :: parent                       !! the page above, or 0
    integer, intent(in) :: depth                        !! how deep it is
    type(page_t), allocatable, intent(inout) :: pages(:)    !! the pages
    type(string_t), allocatable, intent(out) :: ordered(:)  !! its `ordered_subpage`
    type(string_t), allocatable, intent(out) :: skip(:)     !! its `copy_subdir`
    type(metadata_t) :: meta
    type(markdown_options_t) :: options
    type(string_t), allocatable :: lines(:)
    character(len=:), allocatable :: text, msg, root, prefix, title, html, author, date
    type(page_t) :: page
    integer :: k, stat

    allocate (ordered(0))
    skip = s%copy_subdir
    do k = 1, size(skip)
        skip(k)%s = skip(k)%s(last_separator(skip(k)%s) + 1:)
    end do
    call read_whole_file(path, text, stat, msg)
    if (stat /= 0) then
        call warn('could not read '//path//': '//msg)
        return
    end if
    lines = split_lines(text)
    call dedent(lines)
    call parse_metadata(join(lines, achar(10)), meta)
    title = ''
    do k = 1, size(meta%items)
        select case (meta%items(k)%key)
        case ('title'); title = join(meta%items(k)%values, ' ')
        case ('author'); author = join(meta%items(k)%values, ' ')
        case ('date'); date = join(meta%items(k)%values, ' ')
        case ('ordered_subpage'); ordered = meta%items(k)%values
        case ('copy_subdir'); skip = meta%items(k)%values
        end select
    end do
    if (len(title) == 0) then
        call warn("Page '"//path//"' has no title metadata")
        return
    end if

    prefix = repeat('../', depth + 1)
    root = prefix(:len(prefix) - 1)
    call base_options(s, root, options)
    if (allocated(base%abbreviations)) options%abbreviations = base%abbreviations
    call render_text(p, options, 0, prefix, join(meta%body, achar(10)), html)

    page%title = title
    page%path = target
    call move_alloc(html, page%html)
    if (allocated(author)) page%author = author
    if (allocated(date)) page%date = date
    page%parent = parent
    page%depth = depth
    allocate (page%copies(0))
    pages = [pages, page]
end subroutine read_page

Graphs

Calls

Called by