subroutineread_treerecursiveprivate
recursive subroutine read_tree(p, s, base, directory, location, parent, depth, pages)
Read the directory directory of pages, location below the top.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| p | type(project_t) | inout | target | the project |
| s | type(settings_t) | in | the settings | |
| base | type(markdown_options_t) | in | has the abbreviations of the project | |
| directory | character(len=*) | in | the directory | |
| location | character(len=*) | in | its path below the top, ending in | |
| parent | integer | in | the page above, or 0 | |
| depth | integer | in | how deep it is | |
| pages | type(page_t) | inout | allocatabledimension(:) | the pages |
Calls
Source
Show the code
recursive subroutine read_tree(p, s, base, directory, location, parent, depth, pages)
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) :: directory !! the directory
character(len=*), intent(in) :: location !! its path below the top, ending in `/`, or `''`
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(dir_entry_t), allocatable :: entries(:)
type(string_t), allocatable :: names(:), ordered(:), skip(:)
character(len=:), allocatable :: name, path
logical :: exists
integer :: k, node, stat, index_page
path = directory//'/index.md'
inquire (file=path, exist=exists)
if (.not. exists) then
if (.not. is_input_directory(s, directory)) then
call warn("Skipping creating page for '"//directory//"' because it does not contain 'index.md'")
end if
return
end if
call read_page(p, s, base, path, location//'index.html', parent, depth, pages, ordered, skip)
index_page = size(pages)
if (index_page == 0) return
if (parent > 0 .and. pages(index_page)%parent /= parent) return
node = index_page
call list_directory(directory, entries, stat)
if (stat /= 0) return
allocate (names(0))
do k = 1, size(ordered)
if (ordered(k)%s /= 'index.md') call push(names, ordered(k)%s)
end do
block
type(string_t), allocatable :: listed(:)
allocate (listed(0))
do k = 1, size(entries)
call push(listed, entries(k)%name)
end do
call sort_strings(listed)
do k = 1, size(listed)
if (.not. contains_string(names, listed(k)%s) .and. listed(k)%s /= 'index.md') call push(names, listed(k)%s)
end do
end block
do k = 1, size(names)
name = names(k)%s
if (name(1:1) == '.' .or. name(len(name):len(name)) == '~') cycle
path = directory//'/'//name
if (contains_string(skip, name)) then
call push(pages(node)%copies, location//name)
else if (is_directory(path)) then
call read_tree(p, s, base, path, location//name//'/', node, depth + 1, pages)
else if (ends_with(name, '.md')) then
call read_page(p, s, base, path, location//page_file(name), node, depth, pages, ordered, skip)
else
call push(pages(node)%copies, location//name)
end if
end do
end subroutine read_tree