subroutinewrite_site
subroutine write_site(p, s, front, pages_in, count, stat, errmsg)
Write the whole site.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| p | type(project_t) | inout | target | the project |
| s | type(settings_t) | in | target | the settings |
| front | character(len=*) | in | the project file's text as HTML | |
| pages_in | type(page_t) | in | targetdimension(:) | the static pages |
| count | integer | out | how many pages were written | |
| stat | integer | out | nonzero on failure | |
| errmsg | character(len=:) | out | allocatable | what is wrong |
Calls
- collect_lists
- make_footer
- locate_sources
- measure_files
- push_int
- has_page
- build_graphs
- make_directory
- page_directories
- write_entity_pages
- list_page
- index_page
- static_page
- search_page
- progress_start
- progress_tick
- write_whole_file
- progress_finish
- asset_fdoc_css
- take
- asset_fdoc_js
- sidebar_script
- search_index
- copy_page_files
- copy_file
- logo_name
- warn
- remove_directory
- copy_path
Source
Show the code
subroutine write_site(p, s, front, pages_in, count, stat, errmsg)
type(project_t), intent(inout), target :: p !! the project
type(settings_t), intent(in), target :: s !! the settings
character(len=*), intent(in) :: front !! the project file's text as HTML
type(page_t), intent(in), target :: pages_in(:) !! the static pages
integer, intent(out) :: count !! how many pages were written
integer, intent(out) :: stat !! nonzero on failure
character(len=:), allocatable, intent(out) :: errmsg !! what is wrong
type(site_t) :: site
type(string_t), allocatable :: pages(:), paths(:)
integer, allocatable :: ids(:)
character(len=:), allocatable :: url, directory
type(buffer_t) :: b
integer :: k, n, extra
site%p => p
site%s => s
site%pages => pages_in
call collect_lists(site)
call make_footer(s, site%footer)
call locate_sources(site)
call measure_files(site)
allocate (ids(0))
do k = 1, p%list%n
if (has_page(site, k)) call push_int(ids, k)
end do
n = size(ids)
call build_graphs(p, s, ids, [LIST_FILES, LIST_MODULES, LIST_PROCEDURES, LIST_TYPES], site%graphs, stat, errmsg)
if (stat /= 0) return
allocate (site%graphs_of(p%list%n))
do k = 1, size(site%graphs%graphs)
if (site%graphs%graphs(k)%owner > 0) then
call push_int(site%graphs_of(site%graphs%graphs(k)%owner)%ids, k)
end if
end do
extra = size(pages_in) + 1
allocate (pages(n + NUM_LISTS + 1 + extra), paths(n + NUM_LISTS + 1 + extra))
count = 0
directory = s%output_dir
call make_directory(directory, stat)
do k = 1, size(SITE_DIRECTORIES)
if (stat /= 0) exit
call make_directory(directory//'/'//trim(SITE_DIRECTORIES(k)), stat)
end do
if (stat /= 0) then
errmsg = 'could not create '//directory
return
end if
call page_directories(directory, pages_in)
call write_entity_pages(site, ids, directory, count, stat, errmsg)
if (stat /= 0) return
do k = 1, NUM_LISTS
paths(n + k)%s = 'lists/'//trim(LIST_FILE(k))//'.html'
if (size(site%members(k)%ids) > 0) call list_page(site, k, pages(n + k)%s)
end do
paths(n + NUM_LISTS + 1)%s = 'index.html'
call index_page(site, front, pages(n + NUM_LISTS + 1)%s)
do k = 1, size(pages_in)
paths(n + NUM_LISTS + 1 + k)%s = 'page/'//pages_in(k)%path
call static_page(site, k, pages(n + NUM_LISTS + 1 + k)%s)
end do
paths(size(paths))%s = 'search.html'
if (s%search) call search_page(site, pages(size(paths))%s)
call progress_start('Writing files', size(pages))
do k = 1, size(pages)
call progress_tick()
if (.not. allocated(pages(k)%s)) cycle
count = count + 1
call write_whole_file(directory//'/'//paths(k)%s, pages(k)%s, stat, errmsg)
if (stat /= 0) return
end do
call progress_finish()
call asset_fdoc_css(b)
call take(b, url)
call write_whole_file(directory//'/css/fdoc.css', url, stat, errmsg)
if (stat /= 0) return
call asset_fdoc_js(b)
call take(b, url)
call write_whole_file(directory//'/js/fdoc.js', url, stat, errmsg)
if (stat /= 0) return
call sidebar_script(site, url)
call write_whole_file(directory//'/js/sidebar.js', url, stat, errmsg)
if (stat /= 0) return
if (s%search) then
call search_index(site, url)
call write_whole_file(directory//'/search/index.js', url, stat, errmsg)
if (stat /= 0) return
end if
call copy_page_files(s, directory, pages_in)
if (allocated(s%css)) call copy_file(s%css, directory//'/css/user.css', k)
if (allocated(s%favicon)) call copy_file(s%favicon, directory//'/favicon.png', k)
call logo_name(s, url)
if (len(url) > 0) then
call copy_file(s%logo, directory//'/'//url, k)
else if (allocated(s%logo)) then
call warn('the logo '//s%logo//' was not found, so the main page has none')
end if
if (allocated(s%media_dir)) then
if (is_directory(s%media_dir)) then
call remove_directory(directory//'/media')
call copy_path(s%media_dir, directory//'/media', k)
end if
end if
end subroutine write_site