subroutinesearch_indexprivate
subroutine search_index(site, text)
The search index, as a script: browsers do not let a page opened from a file read JSON.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| site | type(site_t) | in | the site | |
| text | character(len=:) | out | allocatable | the script |
Calls
- entity_url
- plain_text
- add_entry
- display_name
Source
Show the code
subroutine search_index(site, text)
type(site_t), intent(in) :: site !! the site
character(len=:), allocatable, intent(out) :: text !! the script
type(json_core) :: json
type(json_value), pointer :: root
character(len=:), allocatable :: url, summary, json_text, word
integer :: k, which, j
call json%initialize(no_whitespace=.true.)
call json%create_array(root, '')
do which = 1, NUM_LISTS
do j = 1, size(site%members(which)%ids)
k = site%members(which)%ids(j)
associate (e => site%p%list%box(k)%e)
call entity_url(site%p%list, k, url)
summary = ''
if (allocated(e%summary)) call plain_text(e%summary, 140, summary)
word = trim(LIST_TITLE(which))
if (e%kind == E_SUBROUTINE) word = 'subroutine'
if (e%kind == E_FUNCTION) word = 'function'
if (e%kind == E_INTERFACE) word = 'interface'
if (e%kind == E_TYPE) word = 'type'
if (e%kind == E_MODULE) word = 'module'
if (e%kind == E_SUBMODULE) word = 'submodule'
if (e%kind == E_PROGRAM) word = 'program'
if (e%kind == E_FILE) word = 'file'
call add_entry(display_name(e), url, word, summary)
end associate
end do
end do
do k = 1, size(site%pages)
call plain_text(site%pages(k)%html, 140, summary)
call add_entry(site%pages(k)%title, 'page/'//site%pages(k)%path, 'page', summary)
end do
call json%serialize(root, json_text)
call json%destroy(root)
text = 'window.FDOC_INDEX='//json_text//';'//achar(10)
contains
!> Add an entry.
subroutine add_entry(title, link, kind, description)
character(len=*), intent(in) :: title !! what it is called
character(len=*), intent(in) :: link !! where it is
character(len=*), intent(in) :: kind !! what it is
character(len=*), intent(in) :: description !! a line about it
type(json_value), pointer :: item
call json%create_object(item, '')
call json%add(item, 't', title)
call json%add(item, 'u', link)
call json%add(item, 'k', kind)
call json%add(item, 's', description)
call json%add(root, item)
end subroutine add_entry
end subroutine search_index